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

Export of a file annotation located in PDF page

New Here ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

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

Views

42

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
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

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.

Votes

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
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

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

Votes

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