Copy link to clipboard
Copied
Hi all,
I am creating a PDF document from scratch with the Adobe SDK Library. My first version of the code is working but I would like to improve the speed of the algorithm.
Here is the initial workflow :
1 - Create a new empty document via
* PDDocCreate
* PDDocCreatePage
* PDDocSave
2 - For each text element to add
* PDDocOpen
* PDDocAquirePage
* PDPageAcquirePDEContent
* PDEContentAddElem
* PDPageSetPDEContent
* PDDocSave
As I said, this process works fine but it's not efficient because each time we open and save the same file. So my second thought was to do :
1 - Create a new empty document via
* PDDocCreate
* PDDocCreatePage
* PDDocSave
* return pdDoc
2 - For each text element to add, using the already known pdDoc
* PDDocOpen
* PDDocAquirePage
* PDPageAcquirePDEContent
* PDEContentAddElem
* PDPageSetPDEContent
* PDDocSave
In this way it seems to be two times faster. It is great but I would like to know if it is possible to avoid the PDDocSave and doing it only one time at the end. Here is the Idea :
1 - Create a new empty document via
* PDDocCreate
* PDDocCreatePage
* PDDocAquirePage
* PDPageAcquirePDEContent
* PDDocSave
* return pdeContent
2 - For each text element to add, using the already known pdeContent
* PDDocOpen
* PDDocAquirePage
* PDPageAcquirePDEContent
* PDEContentAddElem
* PDPageSetPDEContent
* PDDocSave
3 - Save the Document
* ???
The Question are :
- How can I deal with the multiple page ? Is PDEContentAddPage the answer ?
- I think I could use PDPageSetPDEContent to send the pdeContent to a pdPage but what is the pdDoc for PDDocSave ? How could I set it with pdPage ?
Thank you in advance for your help.
1. Return also PDDoc
3. Save using PDDoc Returned in 1.
Copy link to clipboard
Copied
With PDDocCreatePage you can add new empty pages.
You don't need PDDocAquirePage after PDDocCreatePage.
Copy link to clipboard
Copied
1. Return also PDDoc
3. Save using PDDoc Returned in 1.
Copy link to clipboard
Copied
- Since, I add each Text in the pdeContent I will not have any pdPage in 2 ?
- Probably a related question, how can the pdDoc return in 1 know what I have Added in the pdeContent ?
According to both answers, Is it correct to do :
1 - Create a new empty document via
* PDDocCreate
* PDDocCreatePage
* PDDocAquirePage
* PDPageAcquirePDEContent
* PDDocSave
* return pdeContent pdPage and pdDoc
2 - For each text element to add, using the already known pdeContent
* PDEContentAddElem
* PDPageSetPDEContent
3 - Save the Document
* PDDocSave using pdDoc
Copy link to clipboard
Copied
You need the PDPageSetPDEContent only once after adding all elements.
Copy link to clipboard
Copied
Thank you very much Bernd Alheit​ and Test Screen Name​ it seems to work.
It took me roughly roughly 28 sec to insert 400 elements with the first process, 14 sec with the second and about 0.5 sec now !
Copy link to clipboard
Copied
In general, it works more like:
PDDoc newDoc = PDDocCreate
For each page
PDPage newPage = PDDocCreatePage( newDoc )
PDEContent cont = PDPageAcquirePDEContent( newPage )
For each element
PDEContentAddElem( cont )
PDEPageSetPDEContent( newPage, cont )
PDDocSave( newDoc )
Copy link to clipboard
Copied
The PDDoc is not a frozen copy of a file, or a name of a file on disk, it holds all the contents as you change them. These changes are in memory or temporary files. When you save, all changes are saved.