0

我正在尝试学习如何在 pdf 文件中使用 javascript,以及如何从 /Info 对象中获取信息,例如作者和标题。我找到了两种在 pdf 中使用 js 的方法,并且我将 2 个示例放在一起,第一个有效,第二个无效。它们都执行 javascript,但第二个代码无法访问 /Info 数据。我不知道为什么。

示例 1(此代码显示带有 /Title 内容的警报,工作正常):

%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

示例 2(这个不显示任何警报,但如果我用字符串替换标题,它会显示警报);

%PDF-1.3
1 0 obj
<</Type/Catalog/Pages 5 0 R/AcroForm 3 0 R>>
endobj
2 0 obj
<<
/Producer (test)
/Subject (test)
/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

(这两个 pdf 源都不是真正有效的 pdf,但 js 被执行,我删除了很多东西以使它们更易于阅读)

有人知道为什么 app.alert(title) 不适用于第二个示例吗?

4

2 回答 2

1

app.alert(event.target.title);

于 2011-08-12T22:47:32.620 回答
0

这确实是一条评论,但出于格式和可读性的原因,我使用 answer 。

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

如果你有

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

那么你可以做

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

在您的情况下,我猜您需要先获取您所在的文件。我怀疑你能做你想做的,因为你似乎在 pdf 中嵌入了一个 xml 文件。我不希望它起作用

于 2011-06-16T05:40:58.317 回答