Import data from one PDF to another

Adobe Community Professional ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

Hi.

Can Acrobat Reader import data from one PDF to another using JavaScript?

I have a set of document containing some fields with the same name and I'd like a button to do this.

TOPICS
PDF forms

Views

3.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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Mar 19, 2018 Mar 19, 2018

I need to make up some more data tutorials and sample scripts.

The idea is pretty simple. Just loop over all the fields in on PDF, if the same field name exists in a different PDF, then copy the data. The sticky point comes in with how the person selects the source. Assuming the current PDF is the target. I think the best approach is to use a popup menu. 

So this script would be on a button, on the document that is importing the data from another document (i.e. the target file).

var aFiles = app.

...

Likes

Translate

Translate
Adobe Community Professional ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

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
community guidelines
Participant ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

Hi,

I received this response in my email... but this was not my question/discussion...?

Regards,

Jeff P.

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
community guidelines
Adobe Community Professional ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

Maybe you clicked on the Follow button of the PDF Forms page, which means you will get a notification for any reply under 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
community guidelines
Adobe Community Professional ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

I think there are several ways to do this. You could easily write a script to copy data field for field from one PDF to another. From a trusted function you could also save and retrieve data to/from the global object.

I'd be happy to help you out JR

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines
Adobe Community Professional ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

Thank you.

try67: I don't want to import from a data file, I want to import from another PDF form already filled. As I can do with Acrobat via the Form pane when "Importing data": I can import data from a PDF file.

Thom Parker: I will ask my customer but I'm not sure about the trusted function, this form should work on about one hundred Windows tablets. But the user must manually select the PDF to import from, since he is the only one to know its name and its location.

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
community guidelines
Adobe Community Professional ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

My suggestion was to export from one file (to a string which can be copied), and then import it in the other file. There's no need to actually create a text file, although it's possible. As Thom mentioned, though, it's possible to also do it more directly using the global object. I'm not even sure it will require using a trusted function, but it will require installing a script on the local machine.

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
community guidelines
Adobe Community Professional ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

It is possible to transfer data in a "not trusted way" through any of the Generic Top level JS objects, such as the color object. However, the problem is getting to the source or target documents, depending on where the script is placed. Privilege overcomes lots of obstacles. Without it the documents need to know about one another. Here are a couple of options. 

Place save and load buttons on all PDFs that will transfer data. Pushing the Save button saves data to a non-privileged location and pushing the load button loads data from the non-privileged location. This method works without trust or folder levels scripts. But requires all the documents to have the scripts. It'll also works in Reader.

Another, non-privileged solution is to disclose all documents, then a document level script can copy data directly from an open document without an intermediate storage location. The script could even open a disclosed document since app.openDoc will return a doc object from a non-privileged script if the doc is disclosed.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines
Adobe Community Professional ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

These forms are made for wood buyers/sellers that works in lands or in mountains. I cannot ask them to save and load data nor something complicated.

Another, non-privileged solution is to disclose all documents, then a document level script can copy data directly from an open document without an intermediate storage location. The script could even open a disclosed document since app.openDoc will return a doc object from a non-privileged script if the doc is disclosed.

Importing from an open document is a good solution since they need to fill several forms at the same time, and asking them to keep forms opened is something manageable.

I know how to disclose, can you elaborate the following or pointing me to any tuto?

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
community guidelines
Adobe Community Professional ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

I need to make up some more data tutorials and sample scripts.

The idea is pretty simple. Just loop over all the fields in on PDF, if the same field name exists in a different PDF, then copy the data. The sticky point comes in with how the person selects the source. Assuming the current PDF is the target. I think the best approach is to use a popup menu. 

So this script would be on a button, on the document that is importing the data from another document (i.e. the target file).

var aFiles = app.activeDocs.filter(function(a){return this.path!=a.path;}).map(function(a){return a.documentFileName;});

if(aFiles.length)

{

   var cFileName = app.popUpMenu.apply(app,aFiles);

   ...< code for getting doc object and copying fields>...

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines
Adobe Community Professional ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

Waow!

I would never have been able to write this piece of code. I will deepen but it should do it.

Thank you very much (once again).

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
community guidelines
Adobe Community Professional ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

You're welcome!

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines
New Here ,
Jun 03, 2022 Jun 03, 2022

Copy link to clipboard

Copied

LATEST

Good day 

 

Thank you for this string. I am running Adobe on Mac the string does not do anything when I click on the button. Is there a modification required for this string for mac users?

 

Your assistance would be greatly appreciated. 

 

 

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
community guidelines