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

Export of a file annotation located in PDF page

New Here ,
Jul 02, 2024 Jul 02, 2024

I want to export a file attachment located in a page with a javascript.

I tried like that:

var annotObj = this.getAnnots(this.pageNum)[0];
var attachObj = annotObj.attachment;

console.println(attachObj.name);

this.exportDataObject({cName: attachObj.name});

And I expected the typical security popup, which does not appear.

What am I doing wrong here?

TOPICS
Acrobat SDK and JavaScript , Windows
283
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 ,
Jul 02, 2024 Jul 02, 2024

Even though the attached file appears in the Attachments panel it is not a Data Object and therefore can't be exported using the exportDataObject command. You can see that this.dataObjects returns null.

I think the only way to do what you're after is to read the contents of the attachment's contentStream property and then write them out to a new file, and export 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
Community Expert ,
Jul 02, 2024 Jul 02, 2024
LATEST

Try67 is correct. There's no JS functionality for directly saving the file attachment on a file attachment annotation. The contents of the file are however exposed and can be used to create a new PDF that can be saved. There are a couple of ways to do this. Here's some code using an undocumented function to shortcut this process. 

 

var attachObj = this.getAnnots(this.pageNum)[0].attachment;

// This line creates a new PDF in the tmp folder, with a temporary name, 

var oAttDoc = Collab.streamToDocument(attachObj.contentStream);

// Save to attachment name in same file folder as the current PDF 

oAttDoc.saveAs(this.path.replace(/[^\/]+$/,attachObj.name));

oAttDoc.closeDoc();

 

 

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