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

Using Javascript to export a page level file attachment

New Here ,
Feb 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

Hello and thank you in advance for any light you can shine on this subject for me.

I'm creating a form in acrobat pro 10 that I want the users to be able to attach files to.

I don't know if the user will be filling out the form using Acrobat Pro or Reader so I'm using a logic statement in the document level Javascript to determine whether to use the "ImportDataObject" (Pro) or "AddAnot" (Reader) method.

The problem that I'm running into is that while I can export document level attachments using the "this.exportDataObject" function by referencing the name passed to the "ImportDataOjbect" function... I don't know how to export a page level file attachment added using the "AddAnot" function.

Really appreciate any help. I've written code in Visual Basic but Java Script is brand new to me, as is programming for Acrobat forms.

Document Level Java Script Added Below for Reference...

var oFAP = {x_init: -72, x: -72, y: -72}

function Attach(FileName) {

if (app.viewerType === "Reader")

    try {

        var annot = addAnnot({

            page: event.target.page,

            type: "FileAttachment",

            author: FileName,

            name: FileName,

            point: [oFAP.x, oFAP.y],

            contents: FileName,

            attachIcon: "Paperclip"

        });

        annot.cAttachmentPath; // Prompt user to select a file to attach

        oFAP.x += 18;  // Increment the x location for the icon

    } catch (e) {

        app.alert({

            cMsg: "Could not attach file.\r\rPlease report this error.",

            cTitle: "File attachment error",

            nIcon: 3,

            nType: 0

        });

    }

else

{this.importDataObject(FileName)}

}

TOPICS
Acrobat SDK and JavaScript

Views

748

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 ,
Feb 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

AFAIK, it can't be done using JS.

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 ,
Feb 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

Actually you can do this, just not directly.

1. The Attachment annotation has an "attachment" property which is an "annotAttachment" object. Look it up in the JS reference.

2. This object has a contentStream property.  Use this property to create a regular attachment using the "doc.setDatObjectContents()" function.

3. From there you treat it as a regular file attachment.

4. Viola

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
New Here ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

Having a hard time trying to put this into practice. Any chance you could provide an example? Thank you so much!

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 ,
Mar 01, 2018 Mar 01, 2018

Copy link to clipboard

Copied

What do you have so far? 

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
Community Beginner ,
Sep 29, 2018 Sep 29, 2018

Copy link to clipboard

Copied

Is there any way we can do this...I tried but I am getting the below message.

TypeError: Invalid argument type.

Doc.setDataObjectContents:31:AcroForm:Button1:Annot1:MouseUp:Action1

===> Parameter cName.

The code I tried.. Any kind of help is appreciated...

var annot = this.addAnnot({


   page: 0,


   type: "FileAttachment",


   point: [400,500],


   author: "A. C. Robat",


   contents: "Call Smith to get help on this paragraph.",


   /*cAttachmentPath: "/d/a.pdf" ,*/


});


var attachObj = annot.attachment;

cName = attachObj.name;

console.println("Name: " + attachObj.name);


console.println("Type: " + attachObj.MIMEType);


console.println("Size: "+ attachObj.size);


console.println("==============Content=================");


var stm = attachObj.contentStream;


stringStream = util.stringFromStream(stm, "utf-8");

fileStream = util.streamFromString(stringStream, "utf-8");

this.setDataObjectContents(cName, fileStream);

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 ,
Sep 29, 2018 Sep 29, 2018

Copy link to clipboard

Copied

LATEST

No, you can't do it. The attachment property is defined as Read-Only.

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