Skip to main content
September 20, 2016
Answered

Attaching a .pdf file(s) into a form

  • September 20, 2016
  • 2 replies
  • 2919 views

Hi

I'm trying to improve a petty cash reimbursement process by introducing a form. The form includes an expenses list box that allows users to select Taxi, Meals, Telephone etc. These items require a receipt of purchase. Employees complete the form, scan their receipt and send these to their manager for approval.

I wanted to know is it possible to set up a Browse button to select and attach .pdf file(s) (scanned copy of a receipt) so when the manager receives the form via email they can open the form, then open/view the attached receipt.

Thanks for your help

Michael

This topic has been closed for replies.
Correct answer George_Johnson

Yes, you can use JavaScript to prompt the user to add file attachments. Here's a link to a sample document that should help get you started: http://acroscript.net/pdf/demos/importFileJS_v1.pdf

You'll have to download the PDF and open it in Acrobat to see the code in the document-level JavaScript to understand how it works.

2 replies

George_JohnsonCorrect answer
Inspiring
September 20, 2016

Yes, you can use JavaScript to prompt the user to add file attachments. Here's a link to a sample document that should help get you started: http://acroscript.net/pdf/demos/importFileJS_v1.pdf

You'll have to download the PDF and open it in Acrobat to see the code in the document-level JavaScript to understand how it works.

genv2046
Participant
October 10, 2016

Hi,

I'd downloaded your PDF, copied the JavaScript to my form (I'm using Acrobat Pro DC) but it didn't work on my form.

Please help.

NKOWA555
Inspiring
October 10, 2016

Besides the script for the button's mouse up event, did you also add the Document JavaScript (import_file)?:

See JavaScript comments below:

// ADD THE FOLLOWING CODE FOR IMPORT BUTTON MOUSE UP JavaScript EVENT:

if (app.viewerVersion < 11) {

  import_pre_11();

} else {

  import_11();

}

// END CODE FOR IMPORT BUTTON MOUSE UP JavaScript EVENT:

// ADD THE FOLLOWING CODE TO Document JavaScripts:

// Acrobat menu>Advanced>Document Processing>Document JavaScripts

// Add Name = import_file

// Add - CODE START

// Initialize attachment number

attachment_num = 1;

// Initial location of file attachment icon

// The x value is incremented below

var oFAP = {x_init: -72, x: -72, y: -72};  // Below lower-left corner of the page

function import_pre_11() {

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

  app.alert({

  cMsg: "You must user Reader version 11 or later to attach files to this form.",

  cTitle: "Attach File Error",

  nIcon: 3,

  nType: 0

  });

  return;

  }

  // Prompt user to import a file

  app.alert({

  cMsg: "Click the OK/Open button after selecting the file from your system that you want to attach.",

  cTitle: "Attach File",

  nIcon: 3,

  nType: 0

  });

  try {

  var rc = this.importDataObject("Attachment" + attachment_num);

  if (rc) {

  attachment_num += 1;

  app.alert({

  cMsg: "Attachment successful.\r\rOpen the Attachments panel to access the attached file(s).",

  cTitle: "Attachment Successful",

  nIcon: 3,

  nType: 0

  });

  } else {

  app.alert({

  cMsg: "Attachment cancelled.",

  cTitle: "Attachment Cancelled",

  nIcon: 3,

  nType: 0

  });

  }

  } catch (e) {

  app.alert({

  cMsg: "Could not attach file.",

  cTitle: "Could not attach file",

  nIcon: 3,

  nType: 0

  });

  }

}

function import_11() {

  try {

  var annot = addAnnot({

  page: event.target.page,

  type: "FileAttachment",

  author: "Form user",

  name: "File Attachment",

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

  contents: "File attachment on: " + util.printd("yyyy/mm/dd HH:MM:ss", new Date()),

  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

  });

  }

}

// Document JavaScripts CODE END

NKOWA555
Inspiring
September 20, 2016

I would recommend using static LiveCycle PDF forms from a version of Adobe Acrobat that includes LiveCycle. The LiveCycle XFA forms have an image field that can perform the requirements you need. Once the end-user clicks on the image field in Adobe Reader, the form brings up a OS file browse dialog prompt to import the image (JPG, PDF, PNG, GIF) into the XFA form's image field place holder. The image's file bytes are encoded as a base64 string and stored in the XDP data of the XFA form. The XDP data can be emailed just like FDF is with Acrobat PDF forms.

Note: When creating the XFA forms, you should save as "Static PDF" instead of "Dynamic PDF"; unless you need the features from dynamic PDF forms. Static XFA forms have limited compatibility with some software; such as iTextSharp for parsing and merging, but Dynamic XFA forms are only proprietary to Adobe Software.