Copy and save pdf file without using ClonePage() method

Discussions about PDF management.
Post Reply
hardikv
Posts: 43
Joined: Thu Jan 27, 2011 11:46 am

Copy and save pdf file without using ClonePage() method

Post by hardikv » Fri Apr 20, 2012 9:44 am

Hi All,

is there any method or function availabe to copy and save pdf file from one GDPicturePDF object to another GDPicturePDF object without using ClonePage() method?

my main goal is one pdf file is password protect and i want to remove password and save pdf file with same name and path(overwrite).because sometimes one pdf file containse 5000 or more pages then we will have to loop through each page and save to another pdf using clonePage() method. it will decrease performance as well taking some more time for loop pages.

like below code.

Code: Select all

            GdPicturePDF objPDF = new GdPicturePDF();
            objPDF.SetLicenseNumber("XXX");
            objPDF.NewPDF();

            GdPicturePDF objPDFNew = new GdPicturePDF();
            objPDFNew.SetLicenseNumber("XXX");

            if (objPDFNew.LoadFromFile("C:\\5000Pages.pdf", true) == GdPictureStatus.OK)
            {
	           objPDF=objPDFNew;
            }

hardikv
Posts: 43
Joined: Thu Jan 27, 2011 11:46 am

Re: Copy and save pdf file without using ClonePage() method

Post by hardikv » Fri Apr 20, 2012 10:51 am

Hi All,

I found a simple method to copy and save pdf file without using clonepage() method

Code: Select all

GdPicturePDF objPDFNew = new GdPicturePDF();
            objPDFNew.SetLicenseNumber("XXX");

            if (objPDFNew.LoadFromFile("C:\\5000Pages.pdf", true) == GdPictureStatus.OK)
            {
             objPDFNew.SaveToFile("C:\\5000Pages.pdf", PdfEncryption.PdfEncryptionNone, "", "", true, false, false, false, false, false, false, true)
            }

if there is any better solution than let me know
thanks

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Copy and save pdf file without using ClonePage() method

Post by Loïc » Mon Apr 23, 2012 4:07 pm

Hello,

The solution is good. Anyway keep in mind that you are loading the complete file content into the memory. Therefore, if you open a 2 GB PDF, you will need to be able to allocate 2GB of memory...

A better approach to handle large PDF document is:

- Load the PDF from keeping initial source available (without second parameter to True).
- Saves the brand new PDF to a temporary location.
- Close the input source.
- Delete the input file.
- Move the new PDF to the previous input location.

Let me know if you need further information.

Kind regards,

Loïc

hardikv
Posts: 43
Joined: Thu Jan 27, 2011 11:46 am

Re: Copy and save pdf file without using ClonePage() method

Post by hardikv » Tue Apr 24, 2012 6:55 am

Hi Loic,

Thank you very much.
your solution is better than my solution. it will decrease the memory allocation.

ejbrandino
Posts: 38
Joined: Thu Sep 22, 2016 4:56 am

Re: Copy and save pdf file without using ClonePage() method

Post by ejbrandino » Wed Oct 05, 2016 11:36 pm

Hi Loic,

"A better approach to handle large PDF document is:

- Load the PDF from keeping initial source available (without second parameter to True).
- Saves the brand new PDF to a temporary location.
- Close the input source.
- Delete the input file.
- Move the new PDF to the previous input location."

How do you achieve this one? If it's not too much to ask, can you give me code snippets in achieving these? thank you very much.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest