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

Adding a File to a PDF using Javascript

New Here ,
Aug 25, 2022 Aug 25, 2022

Good day everyone

 

I was wondering if there's a way to know via javascript, if at least one file is attached to said PDF?

Im prsently using this code to let someone attch a file:

var myDoc = event.target;
var sFile = "myFile"
myDoc.importDataObject(sFile);

app.execMenuItem("ShowHideFileAttachment");

 

But after that, how can i keep track of this? I could use right now a variable to tell me its been added... but what if a user deletes the attachement?? can i track that? if so, i could update said variable maybe??

 

Any ideas??? thx so much for the help again 🙂

 

Patrick

 

TOPICS
How to , JavaScript , PDF forms
1.4K
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 ,
Aug 25, 2022 Aug 25, 2022

Yes, here's a link to the JS reference entry

 

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#dataobjects

 

 

 

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

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 ,
Aug 30, 2022 Aug 30, 2022

Sounds good, i will take a look at the reference link just to help me understand better what is going on.

Thx for the input. Would you be able to capture via javascript, if the person did press the remove attachment button???

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 ,
Sep 09, 2022 Sep 09, 2022
LATEST

No, There are no JavaScript events associated with actions taken at the application level. 

 

 

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

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 ,
Aug 25, 2022 Aug 25, 2022

Hi,

Unless I'm mistaken, this only works if the attachment has been imported manually... not with the importDataObject method!

@+

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 ,
Aug 25, 2022 Aug 25, 2022
quote

Hi,

Unless I'm mistaken, this only works if the attachment has been imported manually... not with the importDataObject method!

@+


By bebarth

 

the importDataObject method does add to the standard data objects. It's the FileAttachment annot that doesn't add to the dataObjects (as try67 pointed out).  

 

 

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

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 ,
Aug 25, 2022 Aug 25, 2022

You can check the length of the dataObjects array, but this only works for actual Attachments. If they used the Attach File commenting tool, that won't appear there. To detect that you would need to scan the entire annotations array of the file, checking if any of them are of the "FileAttachment" type.

 

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