Skip to main content
Participating Frequently
December 23, 2016
Question

How do I, via javascript code, insert multiple corresponding PDFs from one folder to multiple corresponding PDFs in another folder?

  • December 23, 2016
  • 3 replies
  • 1065 views

I could really use some help from some kind soul out there. I have been racking my brain trying to learn this and scouring the forums/internet and have come up empty handed. I have been trying to figure this out for the last 3 months on my own with no success. Could someone please help me?

I have two folders: folder "A" and folder "B".

On any given day they will both have multiple PDFs in them. The number of PDFs will vary from day to day and week to week, but the number of PDFs in both folders will always match on the same day.

i.e. Monday folder "A" could have 15 PDFs and thus folder "B" would have 15 PDFs. Tuesday it could be 3 PDFs in each folder. Friday it could be 1,000 PDFs in each folder. Regardless of the day, there will always be the same number of PDFs in each folder.

I am currently running/using Adobe Pro 8 (not my decision, out of my control/authority) and due to the limited functionality I have to find an alternative/creative way to achieve an end result via a script. At least I hope that it can be done.

When I run the script, I need the PDFs in folder "B" to be inserted into the end of the PDFs in folder "A", but it has to be a 1:1 ratio. Meaning the first PDF in the list in folder "B" needs to be insert into the first PDF in the list in folder "A". Then the second PDF in folder "B" into the second PDF in folder "A", the third into the third, the fourth into the fourth, etc etc. Until the last PDF has been insert from folder "B" into the last PDF in folder "A".

I then also need to save each merged/inserted result separately in a different location but still use the same naming scheme as the PDFs in folder "A".

My initial, very basic thought was something such as this:

-Count the number of PDFs in Folder "A"

-Count the number of PDFs in Folder "B"

     -Compare to ensure they each have the same number of PDFs (which they always should)

-Insert B.1 to the end of A.1

-Save newly merged/created PDF to new location

     -Save newly merged/created PDF using same name as A.1 file

-Insert B.2 to the end of A.2

-Save newly merged/created PDF to new location

     -Save newly merged/created PDF using same name as A.2 file

-Insert B.n to the end of A.n

-Save newly merged/created PDF to new location

     -Save newly merged/created PDF using the same name as A.n file

I hope that all makes sense.

Is there anyone that can assist me, please? Thank you for your assistance, time, and effort.

This topic has been closed for replies.

3 replies

Legend
December 23, 2016

If they are, without exception, numbered, you could in theory do this in one piece of code. You would keep trying to open NAMEnumber until it failed, trapping the failure with a try...except. Then you are done.

In current Acrobat this will probably fail around 100 files because of "security enhancements" but it might just work in Acrobat 8 for up to a few hundred.

I notice in your original message that you've been scouring the forums/internet. One thing Acrobat programmers find is that they usually need to do something new and won't find anything to copy. So the critical resource for all programmers with Acrobat is the Acrobat SDK. Which is to say, the documentation.

Participating Frequently
December 23, 2016

Hey, thank you very much for the pointers and info regarding the Acrobat SDK. I will have to take a look at it and will probably need to start learning more of the ins and outs.

Here's me, keeping my fingers crossed to hopefully find something and/or learn how to do it via the Acrobat SDK.

try67
Community Expert
Community Expert
December 23, 2016

I think it can be done using scripts, actually, but it would have to be a multi-step process that uses Actions to scan the folders and a script to perform the actual merge.

Participating Frequently
December 23, 2016

@Test Screen Name & try67

The scanning of the folders to compare the number of PDF files is really not that crucial. It was just an idea of mine. They will always have the same number of files, so that is a given.

Do you think there is a way to take the the files and merge them as I indicated in my op? How would I go about doing that without having to manually go one by one? Any ideas?

Thanks for your help!

try67
Community Expert
Community Expert
December 23, 2016

If the file names are not always the same then they will have to be

scanned, either way.

On Fri, Dec 23, 2016 at 6:42 PM, SpydeyNinja <forums_noreply@adobe.com>

Legend
December 23, 2016

JavaScript is deliberately very limited. In particular it cannot scan folders, so the project is a non-starter. This could be done in visual basic using the Acrobat SDK.