Using Javascript to Extract, Flatten, & Save As

New Here ,
Jul 31, 2019

Copy link to clipboard

Copied

Hi everyone,

I have a PDF form that I've created for my team to help make creating contracts easier. Essentially what it does is it has a bunch of form fields on page 1 that fill in all the appropriate information on all the other pages. I've then created buttons that print just the pages we need, which vary for different people. This system works great for printing, but I'm trying to come up with a better solution for saving.

Here's what I want:

On a button press, a certain set of pages should be extracted from the PDF, flattened, and then a Save As prompt should appear.

But I haven't been able to figure out how to apply scripts to the extracted pages, instead of the original.

For example, if I use this code:

this.extractPages(1,3);

this.flattenPages();

app.execMenuItem("SaveAs");

then the pages are extracted correctly, but the original PDF is then flattened and saved, not the new extracted PDF.

This is what I've been doing as a workaround:

this.deletePages({nStart: 4, nEnd: 7});

this.deletePages({nStart: 0, nEnd: 1});

this.flattenPages();

app.execMenuItem("SaveAs");

Essentially, instead of extracting, I'm just deleting the unneeded pages, then flattening and saving the original PDF. This works, and we've been using it this way for about 2 years, but the problem is that it's really only effective if you need to make one contract. If you need to make say, five, all with the same information but a different name, you have to start over from the original PDF and re-enter all of the information. That's why I want the pages to be extracted, leaving the original PDF with form fields intact, and then flattening the new PDF.

Now before anyone says it, I know, I know, this.flattenPages() only works on Acrobat Pro. This is not a problem for us because this PDF is only used internally by my team, and we all have Acrobat Pro DC running on our machines.

Is it possible to apply script to the extracted pages?

Thank you very much for your help!!

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

1.6K

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

Using Javascript to Extract, Flatten, & Save As

New Here ,
Jul 31, 2019

Copy link to clipboard

Copied

Hi everyone,

I have a PDF form that I've created for my team to help make creating contracts easier. Essentially what it does is it has a bunch of form fields on page 1 that fill in all the appropriate information on all the other pages. I've then created buttons that print just the pages we need, which vary for different people. This system works great for printing, but I'm trying to come up with a better solution for saving.

Here's what I want:

On a button press, a certain set of pages should be extracted from the PDF, flattened, and then a Save As prompt should appear.

But I haven't been able to figure out how to apply scripts to the extracted pages, instead of the original.

For example, if I use this code:

this.extractPages(1,3);

this.flattenPages();

app.execMenuItem("SaveAs");

then the pages are extracted correctly, but the original PDF is then flattened and saved, not the new extracted PDF.

This is what I've been doing as a workaround:

this.deletePages({nStart: 4, nEnd: 7});

this.deletePages({nStart: 0, nEnd: 1});

this.flattenPages();

app.execMenuItem("SaveAs");

Essentially, instead of extracting, I'm just deleting the unneeded pages, then flattening and saving the original PDF. This works, and we've been using it this way for about 2 years, but the problem is that it's really only effective if you need to make one contract. If you need to make say, five, all with the same information but a different name, you have to start over from the original PDF and re-enter all of the information. That's why I want the pages to be extracted, leaving the original PDF with form fields intact, and then flattening the new PDF.

Now before anyone says it, I know, I know, this.flattenPages() only works on Acrobat Pro. This is not a problem for us because this PDF is only used internally by my team, and we all have Acrobat Pro DC running on our machines.

Is it possible to apply script to the extracted pages?

Thank you very much for your help!!

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

1.6K

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
Jul 31, 2019 0
Most Valuable Participant ,
Jul 31, 2019

Copy link to clipboard

Copied

If you read the documentation of extractPages you'll see that it returns a Doc object when you specify a file path. However, to be able to do that you have to run it from a privileged context, such as a folder-level script.

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...
Jul 31, 2019 0
New Here ,
Jul 31, 2019

Copy link to clipboard

Copied

Understood, thanks. I have been unable to read the documentation despite several attempts to find it over several months. The link on Adobe's website returns a 404 Not Found error. Is there a place it is currently located?

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...
Jul 31, 2019 0
try67 LATEST
Most Valuable Participant ,
Jul 31, 2019

Copy link to clipboard

Copied

Download the Acrobat SDK from here: Adobe - Acrobat Developer Center | Adobe Developer Connection

The Acrobat JS API Reference document is located in it.

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...
Jul 31, 2019 1