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

Acrobat Javascript

New Here ,
Apr 26, 2023 Apr 26, 2023

importDataObject (to attach a pdf file) is not working in Acrobat DC. Also not throwing any errors. I got strucked in that. Someone help me. I need a javascript code to attach a pdf file inside a main pdf file.

Note: importDataObject is woking fine in "Adobe Acrobat X Standard", but not working in "Acrobat DC Pro". Is this a bug in Adobe Javascript?

My Code is - -  this.importDataObject("Checklist", Checklist_Path);

Checklist_Path is a variable having the pdf file path with forward slashes.

Help appriciated. Thanks.

TOPICS
JavaScript
3.2K
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 ,
Apr 26, 2023 Apr 26, 2023

Where is the code located?

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
New Here ,
Apr 26, 2023 Apr 26, 2023

The code is located in server "C:\Program Files\Adobe\Acrobat DC\Acrobat\Javascripts"

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 ,
Apr 26, 2023 Apr 26, 2023

That's not enough. You have to run it from a trusted function. See:

https://acrobatusers.com/tutorials/trust-and-privilege-in-acrobat-scripts

https://acrobatusers.com/tutorials/using_trusted_functions

And if you check the JS Console you should see an error message regarding it.

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
New Here ,
Apr 26, 2023 Apr 26, 2023

Here is my entire code:

var attachPreparerChecklist = app.trustedFunction( function()
{
app.beginPriv();
var preparerChecklist_Path = global.checkListBase_Path + "2022 Preparer Checklist.pdf";
(global.lastDoc).importDataObject("Preparer Checklist", preparerChecklist_Path);
app.alert("\nPreparer Checklist is Attached Successfully", 1, 0, "Preparer Checklist Attachment");
app.endPriv();
});

It is showing the successful alert. But not attaching the checklist.
(global.lastDoc) is nothing but "this".

I tried attaching the checklist pdf manually once and then that plugin is working. After closing and opening the acrobat dc pro then it is not woking. Sooooo weird. I am totally confused.

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
New Here ,
Apr 26, 2023 Apr 26, 2023

No error is showing in the Console. That is the problem. Is there any setting that I have to do with Adobe Acobat DC Pro version to attach the checklist 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 ,
Apr 26, 2023 Apr 26, 2023

In the future please post the actual code you're using, not something similar. The devil is in the details...

 

First of all, you should check the return value of imprtDataObject. It returns true if successful, or throws an exception on failure. So there has to be an error in the JS Console, unless you caught it and didn't handle it properly.

Also, instead of using a global variable, I would pass a reference to the Document object to the function as a parameter. Same for the path to the file you want to attach. Do that and see if it helps solve the issue.

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
New Here ,
Apr 26, 2023 Apr 26, 2023

It is showing true.

Thuyavan_0-1682517521188.pngexpand image

Now I changed the code to,
var attachPreparerChecklist = app.trustedFunction( function()
{
app.beginPriv();
var rtn = (global.lastDoc).importDataObject("Preparer Checklist", "/wlt-data-1/Adobe/AdobeAutomationDontDelete/04_ChecklistBase/2022 Preparer Checklist.pdf");
app.alert(rtn); // here it is showing true
app.alert("\nPreparer Checklist is Attached Successfully", 1, 0, "Preparer Checklist Attachment");
app.endPriv();
});

But still not working.

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
New Here ,
Apr 26, 2023 Apr 26, 2023

This is the exact path of the checklist "/wlt-data-1/Adobe/AdobeAutomationDontDelete/04_ChecklistBase/2022 Preparer Checklist.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 ,
Apr 26, 2023 Apr 26, 2023

You didn't implement the first change I recommended, ie. passing a reference to the Doc object as a parameter, instead of using a global variable.

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
New Here ,
Apr 27, 2023 Apr 27, 2023

Please provide me a sample code. Thanks.

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
LEGEND ,
Apr 27, 2023 Apr 27, 2023
LATEST

This is intolerably rude. See https://community.adobe.com/t5/acrobat-discussions/attach-pdf-in-to-a-pdf-using-javascript-sample-co...

 

Please do NOT ask for sample code, minutes after you have been asked not to ask for sample code, imagining we don't read the other posts. So rude!

Please do NOT start new discussions, without linking to the old one.

Please do NOT register new users to make it look like a new discussion.

Or, please NEVER allow multiple members of the same team to start the same discussion separately.

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