New Reader 9.2 API

| 1 Comment

Last week Adobe released Reader 9.2.  Included with this release is a new API for loading file attachment data: util.readFileIntoStream().  The reason this method has been added is because certified PDFs cannot add file attachments.  This method allows the form author to embed attachments in their XML form data stream rather than as PDF file attachments.

util.readFileIntoStream(cDIPath, bEncodeBase64)

cDIPath

(optional) A device-independent path to an arbitrary file on the user's hard drive. This path may be absolute or relative to the current document.  If not specified, the user is presented with the File Open dialog to locate the file.

If the cDIPath parameter is specified, this method can be executed only in a privileged context, during a batch or console event, or when the document is certified with a certificate trusted to execute "embedded high privileged javascript".

bEncodeBase64
(optional) If true, base 64-encode the file content. Defaults to false.

Returns

The File content as a ReadStream object that is optionally base 64-encoded.  If the user cancels the dialog, the method returns "undefined".

Example

The following sample shows how to use the API to load attachments.  The button script to load an attachment looks like:

var vStream = util.readFileIntoStream({bEncodeBase64:true});
if (typeof(vStream) !== "undefined") {
    var vNewAttach = _attach.addInstance();
    vNewAttach.contents.rawValue = util.stringFromStream(vStream);
}

Futures

It would be nice if the method provided the name of the loaded file.  It would also be nice if there was a corresponding util.writeStreamToFile() method.  I don't know whether these enhancements are planned or not.

1 Comment

Hi John,

Will it be possible to display the content of the attached file (word document) inside the form in its native format/look? Or at least have a preview of the attached file? I just sent another comment on "Base64 Encode a PDF attachment" blog post regarding the possibility to print and display the attached document with the form.

I believe if we can have the file displayed then we will be able to print it, which will be very good for my current project.

Thank you very much for your valuable posts.

Leave a comment

About this Entry

This page contains a single entry by John Brinkman published on October 19, 2009 11:34 AM.

Populating List Boxes was the previous entry in this blog.

Populate a listbox from a web service is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.