Add Password to Existing File

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v6)  /  Add Password to Existing File

DynamicPDF CoreSuite for .NET (v6) Forum

 Oct 02 2013 10:54 AM
Is there a way to add a password to an existing PDF without creating a new file.

Using the MergeDocument, I can open an existing file, add security to the file, but then I have to write it out to a different file (i.e. I can't update the existing input file)

Thanks!
 Oct 02 2013 2:55 PM
Posted by a ceTe Software moderator
Hello,

The MergeDocument class does not modify the source PDF, when you call the Draw method to save the PDF it will create a new PDF document. If you are loading the source PDF from file path you won’t be able to call the Draw method to that path again as the MergerDocument class holds the file handle to the source PDF. If you want to overwrite the  source PDF, you would need to load the source PDF  into a byte array and create the MergeDocument object using the PDF byte array.

            byte[] pdfbytes = File.ReadAllBytes(@"source.pdf");
            PdfDocument pdf = new PdfDocument(pdfbytes);
            MergeDocument document = new MergeDocument(pdf);
            document.Draw(@"source.pdf");

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 6:20 PM.