使用PDF的JavaScript获取信息(标题,主题,作者,制作人...) [英] Getting Info (title, subject, author, producer...) from PDF using javascript

查看:495
本文介绍了使用PDF的JavaScript获取信息(标题,主题,作者,制作人...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去学习如何使用JavaScript里面的PDF文件,以及如何抓住从如作者和标题/信息对象的信息。我发现用js PDF文件中的两个方法,我已经把2个样本中,首部作品,第二个没有。他们都执行JavaScript的,但第二个code不能访问/信息数据。我想不通为什么。

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.

样品1(这code显示与/标题内容的警报,工作正常):

%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(职称)不会在第二个样品的工作?

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

推荐答案

这是一个真正的评论,但我使用的答案格式和可读性的原因。

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

HTTP://corkami.google$c$ c.com/svn-history/r503/wiki/PDFTricks.wiki

如果您有

/信息&LT;&LT; /作者(你好)/标题(世界)/制作人&GT(!);&GT;

那么你可以做

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

在你的情况我猜你需要让你在第一个文件。我怀疑你可以做你想做的,因为你似乎被嵌入PDF中的XML文件。我不希望它的工作

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

这篇关于使用PDF的JavaScript获取信息(标题,主题,作者,制作人...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆