开发者

Getting Info (title, subject, author, producer...) from PDF using javascript

Im trying to learn how to use javascript inside pdf files, and how to grab information from the /Info object like author and title. I've found two ways to use js inside a pdf, and I've put together 2 samples, the first works, the second doesn't. They both execute javascript, but the second code can't access the /Info data. I can't figure out why.

Sample 1 (This code shows an alert with the contents of /Title, works fine):

%PDF-1.3
1 0 obj
<</Type/Catalog/Pages 5 0 R/OpenAction 3 0 R>>
endobj
2 0 obj
<<
/Producer (test)
/Subject (test)
/Title (test)
>>
endobj
3 0 obj
<</Type/Action/S/JavaScript/JS 4 0 R>>
endobj
4 0 obj
<</Length 17>>
stream
app.alert(title);
endstream
endobj
5 0 obj
<<
>>
endobj
xref
trailer
<<
/Root 1 0 R
/Info 2 0 R
>>
startxref
%%EOF

Sample 2 (this one doesn't show any alert, but if i replace title with a string, it does show the alert);

%PDF-1.3
1 0 obj
<</Type/Catalog/Pages 5 0 R/AcroForm 3 0 R>>
endobj
2 0 obj
<<
/Producer (test)
/Subject (test开发者_Python百科)
/Title (test)
>>
endobj
3 0 obj
<</XFA [4 0 R]>>
endobj
4 0 obj
<</Length 767>>
stream
<?xml version="1.0" encoding="UTF-8" ?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
<config xmlns="http://www.xfa.org/schema/xci/1.0/"><present>
<pdf><interactive>1</interactive><version>1.6</version>
</pdf><xdp><packets>*</packets></xdp><destination>pdf</destination></present></config>
<template xmlns="http://www.xfa.org/schema/xfa-template/2.5/">
    <subform layout="tb" locale="en_US" name="form">
        <subform>
            <field>
                <event activity="initialize" name="eventName">
                        <script contentType="application/x-javascript">
                        app.alert(title)
                        </script>
                </event>
            </field>
        </subform>
    </subform>
</template>
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data></xfa:data></xfa:datasets>
</xdp:xdp>
endstream
endobj
5 0 obj
<<
>>
endobj
xref
trailer
<<
/Root 1 0 R
/Info 2 0 R
>>
startxref
%%EOF

(Both pdf sources are not really valid pdfs but the js gets executed, i removed a lot of stuff to make them easier to read)

Does someone knows why app.alert(title) doesn't work on the second sample?


app.alert(event.target.title);


This is really a comment, but I use answer for formatting and readability reasons.

http://corkami.googlecode.com/svn-history/r503/wiki/PDFTricks.wiki

If you have

/Info <</Author(Hello) /Title( World) /Producer( !)>>

then you can do

app.alert(info.author + info.title + info.producer);

In your case I would guess you need to get the document you are in first. I doubt you can do what you want since you seem to be embedding an xml file inside the pdf. I would not expect it to work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜