Best design to create a document

Community Beginner ,
Aug 08, 2018

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.

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

1. Return also PDDoc

3. Save using PDDoc Returned in 1.

TOPICS
Acrobat SDK and JavaScript

Views

195

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Best design to create a document

Community Beginner ,
Aug 08, 2018

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.

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

1. Return also PDDoc

3. Save using PDDoc Returned in 1.

TOPICS
Acrobat SDK and JavaScript

Views

196

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 08, 2018 0
Adobe Community Professional ,
Aug 08, 2018

Copy link to clipboard

Copied

With PDDocCreatePage you can add new empty pages.

You don't need PDDocAquirePage after PDDocCreatePage.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2018 0
Most Valuable Participant ,
Aug 08, 2018

Copy link to clipboard

Copied

1. Return also PDDoc

3. Save using PDDoc Returned in 1.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2018 0
Community Beginner ,
Aug 08, 2018

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2018 0
Adobe Community Professional ,
Aug 08, 2018

Copy link to clipboard

Copied

You need the PDPageSetPDEContent only once after adding all elements.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2018 0
Community Beginner ,
Aug 08, 2018

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 !

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2018 0
Adobe Employee ,
Aug 08, 2018

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 )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2018 0
Most Valuable Participant ,
Aug 08, 2018

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2018 0