Skip to main content
michelm76805089
Participating Frequently
August 8, 2018
Answered

Best design to create a document

  • August 8, 2018
  • 4 replies
  • 1062 views

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.

This topic has been closed for replies.
Correct answer Test Screen Name

1. Return also PDDoc

3. Save using PDDoc Returned in 1.

4 replies

Legend
August 8, 2018

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.

lrosenth
Adobe Employee
Adobe Employee
August 8, 2018

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 )

Test Screen NameCorrect answer
Legend
August 8, 2018

1. Return also PDDoc

3. Save using PDDoc Returned in 1.

michelm76805089
Participating Frequently
August 8, 2018

- 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

Bernd Alheit
Community Expert
Community Expert
August 8, 2018

You need the PDPageSetPDEContent only once after adding all elements.

Bernd Alheit
Community Expert
Community Expert
August 8, 2018

With PDDocCreatePage you can add new empty pages.

You don't need PDDocAquirePage after PDDocCreatePage.