Highlighted

open a FileAttachment type annot via JavaScript

Participant ,
Oct 01, 2020

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

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

143

Likes

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

open a FileAttachment type annot via JavaScript

Participant ,
Oct 01, 2020

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

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

144

Likes

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
Oct 01, 2020 0
Adobe Community Professional ,
Oct 01, 2020

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.

Likes

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
Reply
Loading...
Oct 01, 2020 0
Participant ,
Oct 01, 2020

Copy link to clipboard

Copied

Thanks for your answer,

so it is not possible?

@+

Likes

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
Reply
Loading...
Oct 01, 2020 0
Adobe Community Professional ,
Oct 01, 2020

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

Likes

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
Reply
Loading...
Oct 01, 2020 0
Participant ,
Oct 01, 2020

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!

@+

Likes

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
Reply
Loading...
Oct 01, 2020 0
Adobe Community Professional ,
Oct 01, 2020

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

 

Likes

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
Reply
Loading...
Oct 01, 2020 0
Participant ,
Oct 08, 2020

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

 

@+

Likes

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
Reply
Loading...
Oct 08, 2020 0
Most Valuable Participant ,
Oct 09, 2020

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

Likes

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
Reply
Loading...
Oct 09, 2020 0
Participant ,
Oct 09, 2020

Copy link to clipboard

Copied

Thanks

Likes

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
Reply
Loading...
Oct 09, 2020 0
Participant ,
Oct 09, 2020

Copy link to clipboard

Copied

I doubted a bit...

Likes

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
Reply
Loading...
Oct 09, 2020 0
Adobe Community Professional ,
Oct 09, 2020

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.  

Likes

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
Reply
Loading...
Oct 09, 2020 0