How to read header of a file using javascript?


I have a acrobat file which has been created by using the conversion of various files. I mean to say,for ex, the word file is converted to pdf and attached into it.

Now, I need to distinguish those files by reading header of each attachments. Is it possible in Javascript?

shivarajkumar poojar

2 Answers

That could be very tricky. You need to be able to identify the header based on some criteria. For example, does it always appear in the same place? If so, you can use the quads of the words to locate it. Or if it always follows or is preceded by certain text then you can look for that. Or even looking at the size of the words is possible (again, using quads). These are not trivial tasks, though, and require quite a bit of scripting knowledge...

Gilad D (try67)   

When Acrobat attaches a file to a PDF, that file is given a MIME type. The file type is usually determined from this property. Look at the poperties of the "dataObjects" array. Run this code from the console window


if there is more than one file, then set the index appropiately.

If you really need to access the file data, the use this fucntion

var stmData = this.getDataObjectContents(this.dataObjects[0].name);

This function returns a stream object. Hexadecimal encoded data. You can read it byte by byte or convert it to text with one of the "util" functions.

Thom Parker
The source for PDF Scripting Info

The Acrobat JavaScript Reference, Use it Early and Often

The most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)
Having trouble, Why Doesn't my Script Work

Thom Parker   

Please specify a reason: