Copy link to clipboard
Copied
How could I open a FileAttachment type annot via JavaScript?
I read all the annot proprieties but I don't understand which one I have to use for opening such as a double-click on the icon!!!
Thanks
Copy link to clipboard
Copied
You can use the doc.openDataObject method, but only for attachments that are PDFs. An exception will be thrown if you attempt to use it to lauch other file types, which is a good thing for security reasons.
Copy link to clipboard
Copied
Thanks for your answer,
so it is not possible?
@+
Copy link to clipboard
Copied
Sorry, my previous response was not entirely correct. You can attempt to launch a file attachment using the doc.exportDataObject JavaScript method and include the nLaunch parameter, but there are certain restrictions as documented here: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_Acro...
Copy link to clipboard
Copied
I know this method, but a FileAttachment type annot is not looked upon as an object, so this method can't be used!
@+
Copy link to clipboard
Copied
The file attachment annotations cannot be accessed from the regular data object methods. This is because the file in the annot is not in the name tree, where all the regular attachments live. The embedded file stream is in the actual annotation.
So, the file attachment annot has a property named "attachment", which is the actual file attachment. The content of this file is available through the undocumented "contentStream" property of the attachment property.
Streams in Acrobat JavaScript have a "read" function for reading the raw file bytes as hex digits. Use the util function to convert to text. Like this, for a selected file attachment annot:
var strFileText = util.stringFromStream(selectedAnnots[0].attachment.contentStream);
Copy link to clipboard
Copied
Hi,
Thank you for your answer.
Sorry for this late reply, but I just got the notification...
Since this is an undocumented property, do you have any idea what the attachment.contentStream feedback represents.
Can some information be usable in JavaScript?
Below is the feedback of a test.
%PDF-1.6
%
7 0 obj
<</Linearized 1/L 4797/O 9/E 725/N 1/T 4512/H [ 422 118]>>
endobj
10 0 obj
<</DecodeParms<</Columns 3/Predictor 12>>/Filter/FlateDecode/ID[<8BD9D490C05043E8BFEEFA3F4DFBEAEF><1D69BE13C95A45A3886378EFA78CEE33>]/Index[7 5]/Info 6 0 R/Length 30/Prev 4513/Root 8 0 R/Size 12/Type/XRef/W[1 2 0]>>stream
hbbd`b`ab`ab'h`
true
@+
Copy link to clipboard
Copied
That content stream contains the whole of a normal PDF. I don't think there is any JavaScript method to say "open this string as a PDF file", and security restrictions stop the obvious solution "Write this string to a file, then open this as a PDF file."
Copy link to clipboard
Copied
Thanks
Copy link to clipboard
Copied
I doubted a bit...
Copy link to clipboard
Copied
Actually there is a way to do this. Use the content stream to create a regular attachment, then open it.
Copy link to clipboard
Copied
Do you have an example for this. I am trying to save annotation file attachments and am having a lot of trouble finding information.
Copy link to clipboard
Copied
The user can simple double click on the file attachment annotation to open or save it. This is the simplest solution since saving a file attachment with code also requires the user's help, except under special circumstances.