PDF Security

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
kwaltman
Posts: 30
Joined: Fri Aug 07, 2009 9:48 pm

PDF Security

Post by kwaltman »

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?
vladimirG
Posts: 2
Joined: Sun Jan 25, 2015 1:18 am

Re: PDF Security

Post by vladimirG »

kwaltman,
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();

If you want to change security properties of an existing PDF document, do it in the same way. The following code should work:

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();

Post Reply