New Reader 9.2 API

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)


(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".

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


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


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);


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.

7 Responses to New Reader 9.2 API

  1. E. Loralon says:

    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.

  2. E. Loralon:I am not aware of anything you can do that would allow you to use JavaScript to extract the contents of a word document.I don’t think you can get there from here.sorry,John

  3. E. Loralon says:

    Thank you very much John for your reply,So will it be possible using JavaScript to have a print button that will print both the form and the attached document (word document) at the same time?Since I cannot display the content of the attached document within the form, if I am able to print both the form and the attached document will also be helpful in my current project.Loralon

  4. Loralon:As far as I know, there is no way to print your word file attachment. In fact, I don’t think you can even launch a word file attachment.John

  5. E. Loralon says:

    Thanks John,I have been able to attach a word document to my PDF and open it using a custom button adapted from another livecycle forum. But I am stuck on how to create a custom button to print both the form and the attachment (word document).Loralon

  6. Loralon:Looks as if by now you’ve surpassed me in ability to work with attachments. Sorry I don’t have more to add.John

  7. Tai says:

    [a bit late I know, but my 2c for future readings]

    Attachments are attachments – not embeds.

    Acrobat does not take any responsibility for rendering whatever is attached, nor interfacing with the file’s native program for processing (edit, print, any other operation). Embedded content, however, is a different matter – that’s things like videos, images, which are meant to be rendered by any PDF reader.

    Maybe you could try to use an Acrobat call to launch an independant executable (I have heard this can be done, never tried it myself) with the attached data as argment, which could translate and print your DOC, or interface with Word, then you might be able to achieve it.

    But natively within Acrobat? I think that’s beyond the program’s jurisdiction…