VintaSoft PDF .NET Plug-in Discussions

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

Board index < VintaSoft Imaging < VintaSoft PDF .NET Plug-in Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

PDF Security



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?


Re: PDF Security

Post by vladimirG »

kwaltman,
you can use constructors to create new objects with desired properties. Here is an example:
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:
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();



Page 1 from 1: 1