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!
Add Password to Existing File
Re: Add Password to Existing File
Support · Oct 2, 2013Hello,
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.