We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PdfDocument.Merge

Hi

I would like to merge a few pdfs files. No I have a problem with the password. How can I set the password?

Regrads,
jpp

8 Replies

DK Dhivya K Syncfusion Team September 25, 2006 01:45 PM UTC

Hi,

Thank you for your interest in Essential PDF.

You can set the password for the PDF document after merging the documents as follows.

//Merge PDFDocument
PDFDocument pdfdoc= PDFDocument.Merge(source );

//set the password.
pdfdoc.Security.OwnerPassword = "Syncfusion";
pdfdoc.Security.UserPassword = "111";

Here is a sample for your reference.
merge.zip

Please take a look into it and let me know if you have any queries.

Regards,
Dhivya.


JP Jean-Pierre Pokora September 26, 2006 10:52 AM UTC

Hi

The problem is: when the pdf files have a security protection and I would like to merge them. I get an exception from PdfDocument.Merge that the pdf files are protected.
I'' m missing something like this:
PdfDocument.Merge(Stream[] pdfs, string ownerPassword). And after that I can set the security properties again.

Regards,
Jean-Pierre Pokora


DK Dhivya K Syncfusion Team September 26, 2006 12:05 PM UTC

Hi Jean,

We do have option for merging password protected document and set the password again.

I can be done as follows:

//Open a PDF document
PDFDocument pdfdoc1= PDFDocument.Load(source1);

//Open the password protected PDF document
PDFDocument pdfdoc2 = PDFDocument.Load(source2,"111");

//Add the pages of password protected document to the 1st document
for (int pages=0;pages< pdfdoc2.Pages.Count;pages++)
{
pdfdoc1.Pages.Add(pdfdoc2.Pages[pages]);

}

//Save the document
pdfdoc2.Save(destination);

Here is a sample for your reference.
merge.zip

Please take a look into it and let me know if you have any queries.

Regards,
Dhivya.


JP Jean-Pierre Pokora September 29, 2006 09:00 AM UTC

Hi

There is something very strange. When step thru the code it works fine and sometime I get an index exception or the password is not correct, but it is always the same source pdfs and the same passwords. The list of pdfs stream is ok and the pdfs are ok as well. When I remove the password form my pdfs and I use the function PDFDcoument.Merge() everything works fine.


PDFDocument doc = new PDFDocument();
PDFDocument doc2;
foreach(Stream s in list) {
s.Position = 0;
doc2 = PDFDocument.Load(s, ownerPassword);
for(int pages = 0; pages < doc2.Pages.Count; pages++) {
doc.Pages.Add(doc2.Pages[pages]);
}
}

Regards,
jpp


DK Dhivya K Syncfusion Team October 2, 2006 01:42 PM UTC

Hi Jpp,

Sorry for the delay in getting back to you.I will send you an update reagarding this by tomorrow.

Thanks,
Dhivya.


DK Dhivya K Syncfusion Team October 3, 2006 04:54 AM UTC

Hi Jpp,

I tried testing this issue.I am afraid.I am unable to reproduce the issue.

Here is a sample for your reference.
merge.zip

In the sample attached,I am having two sample PDF streams with same password. I am unable to reproduce the issue.

Please take a look into it and let me know if I am missing something in my sample.

Thanks,
Dhivya.


JA Jason Adriance May 17, 2007 05:26 PM UTC

I am having perhaps more of a problem of ability... I am given a pdf that I Don't know the password to, I need to append / merge the pdfs together then assign it a new password... Is this done with a similar task?

>Hi Jean,

We do have option for merging password protected document and set the password again.

I can be done as follows:

//Open a PDF document
PDFDocument pdfdoc1= PDFDocument.Load(source1);

//Open the password protected PDF document
PDFDocument pdfdoc2 = PDFDocument.Load(source2,"111");

//Add the pages of password protected document to the 1st document
for (int pages=0;pages< pdfdoc2.Pages.Count;pages++)
{
pdfdoc1.Pages.Add(pdfdoc2.Pages[pages]);

}

//Save the document
pdfdoc2.Save(destination);

Here is a sample for your reference.
merge.zip

Please take a look into it and let me know if you have any queries.

Regards,
Dhivya.


SK Sarath Kumar G Syncfusion Team May 18, 2007 12:20 AM UTC

Hi Jason,

Thank you for your interest in Syncfusion products.

- It is not possible to load a PDF document without knowing the exact password. Password in PDF document is used to encrypt/decrypt file object datas. Therefore it is necessary to have the password used to encrypt to be given to load the pdf document inorder to decrypt the file.

- Syncfusion's Essential PDF do not have options to crack the password and decrypt the password protected file without decrypting a file it is not possible to merge the files.

Please let me know if you need any further details.

Regards,
Sarath

Loader.
Live Chat Icon For mobile
Up arrow icon