Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JavaScript code to add merge (combine) another document after the last page

Contributor ,
Nov 07, 2022 Nov 07, 2022

Hello there,

I have an Expense Report, (it's one page), I would love to add a JavaScript code to a button to attach (add) the receipts after the Expense Report

So once I click on a button I can browse the files I want and select one or all of them.

 

I used these codes, but unfortunately, did not work

 

var a = this.templates;
for (i = 0; i < a.length; i++)
    a[i].spawn(this.numPages, false, false);

 

 

 

var a = this.getTemplate("PageA");
a.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});

 

 

SaherNaji_0-1667893964106.pngexpand image

 

 

I tried to follow the links in this page, but they are not working

https://community.adobe.com/t5/acrobat-sdk-discussions/javascript-code-to-combine-pdf-files/td-p/981...

 

Maybe I should to add a document level JavaScript codes? I hope it's an easy thing to do

Thanks in advance

TOPICS
Create PDFs , JavaScript , PDF forms , Print and prepress
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Again, the only way to insert pages in Reader is through a Template. If you use any other methods, it will not work there. If you disable the button to insert pages via the Template object the end-users won't be able to insert any more pages.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Spawning a template is not the same thing than adding a page.

About Document Level Scripts you should start here: https://www.pdfscripting.com/public/Document-Level-Scripts.cfm


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2022 Nov 08, 2022

Maybe I have to be a memeber in pdfscripting to review more details

Do you think there is an easy way to do this?

actually I can attach the receipts as attachments, is there a way to convert these attachments to pages ander the main pdf?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Are the receipts PDF files or image files? If so, you can use a Template page with a single image field, spawn a copy of it and then prompt the user to select the receipt file as the icon of that field. They will need to do it one page at a time, though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2022 Nov 08, 2022

I know it's a good idea,

But let's make it the last option,

I'm trying to find a solution here

 

https://acrobatusers.com/tutorials/inserting-pages-pdf-acrobat-javascript1/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

That is the only way to do it if the file is going to be used in Reader.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2022 Nov 08, 2022

@try67 Yes, this file is going to be used only in Reader

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Then the tutorial above does not apply for it (it's mentioned there, too, somewhere in the middle).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2022 Nov 08, 2022

So do you think select the receipt file as the icon is the only way?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

If you want them to be visible on the page, yes. Alternatively, they can be attached to the file using the Attach File commenting tool, but then they won't be visible. You'll have to double-click the attachment icon to open them as separate files.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2022 Nov 08, 2022

This option is better than selecting the receipt file as icon, thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2022 Nov 08, 2022

"Inserting a page into a PDF is a major document modification, so it is not an operation that can be done in Adobe Reader, and it requires a Privileged Context. At its simplest, a Privileged Context means this operation cannot be done from a Document Level script, i.e., documents can’t insert pages into themselves. This has to be done from an Application Level script."

Is that mean the user of Adobe Reader can not insert pages, assuming I wrote the correct code?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2022 Nov 08, 2022

but please, I want to make sure that there is no way at all to let the final users insert pages by click on [Attach Recept] button (They will only use Adobe Reader (the last version)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Again, the only way to insert pages in Reader is through a Template. If you use any other methods, it will not work there. If you disable the button to insert pages via the Template object the end-users won't be able to insert any more pages.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2022 Nov 08, 2022
LATEST

Thank to saving my time

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