Posted by a ceTe Software moderator
Hello,
There are two types of passwords that one can set in a PDF:
1. User Password – If this is set you will need to provide the password when viewing the PDF.
2. Owner Password – If this is set you will need to provide the password for editing and/or merging the PDF.
It is possible that your PDF only has an owner password was and not a user password. Hence you are able to open and view the PDF but not able to modify or merge it without the owner password.
If the PDF is encrypted with an owner password then you will need to load the PDF using the PdfDocument class constructor which takes file path/byte array and owner password as arguments. Then append or merge it with MergeDocument object. Below is the code sample for it.
Please note that it is not possible to merge the password protected PDFs without specifying the correct owner password.
PdfDocument pdfDoc = new PdfDocument(@"Secured PDF file path", "correct owner password");
MergeDocument document = new MergeDocument( );
document.Append(pdfDoc);
document.Draw(@"C:\temp\MyOutput.pdf");
Also below is the code sample to check whether the PDF is protected with owner or user password.
EncryptionInfo info = PdfDocument.GetEncryptionInfo("PDF file path or byte array");
bool hasOwnerPasword = info.HasOwnerPassword;
bool hasUserPassword = info.HasUserPassword;
Thanks,
ceTe Software Support Team