PDF Security
Moderator: Alex
-
- Posts: 30
- Joined: Fri Aug 07, 2009 9:48 pm
PDF Security
I am trying to set the security settings on a document. But the .EncryptionSystem property object and all of it's properties on a PDFDocument are readonly. How does one set the actual properties. Ifs there another method that has to be used to set the properties?
-
- Posts: 2
- Joined: Sun Jan 25, 2015 1:18 am
Re: PDF Security
kwaltman,
you can use constructors to create new objects with desired properties. Here is an example:
If you want to change security properties of an existing PDF document, do it in the same way. The following code should work:
you can use constructors to create new objects with desired properties. Here is an example:
Code: Select all
EncryptionSystem encSystem = new EncryptionSystem(
EncryptionAlgorithm.RC4, 40, "userpwd", "ownerpwd", UserAccessPermissions.ExtractTextAndGraphics);
using (PdfDocument document = new PdfDocument(PdfFormat.Pdf_16, encSystem))
{
document.Pages.Add(PaperSizeKind.A4);
document.Save(filename);
}
encSystem.Dispose();
Code: Select all
EncryptionSystem encSystem = new EncryptionSystem(
EncryptionAlgorithm.RC4, 40, "userpwd", "ownerpwd", UserAccessPermissions.ExtractTextAndGraphics);
using (PdfDocument documentOriginal = new PdfDocument(inFilename))
using (PdfDocument documentChanged = new PdfDocument(PdfFormat.Pdf_16, encSystem))
{
documentChanged.Pages.AddRange(documentOriginal.Pages.ToArray());
documentChanged.Save(outFilename);
}
encSystem.Dispose();