我有一个 PostScript 示例,用于说明如何创建表单。如果我将 PostScript 转换为 PDF,我可以很容易地枚举 FormXObject,但如何访问内容?例如
/SForm <<
/FormType 1 % all forms are FormType 1
/Matrix [ 1 0 0 1 0 0] % no scaling or translating
/BBox [ 0 -10 100 100 ] % hack - should really calculate the width of the string
% and the height of the font allowing for descenders etc
/PaintProc {
pop
0 0 moveto % assume that the translate has set the current point
(XObject String) show
0 24 moveto
(Line Two) show
} bind
>> def
翻译为
7 0 obj
<</Type/XObject/Subtype/Form/FormType 1/BBox[0 -10 100 100]/Resources 6 0 R/Matrix[1 0 0 1 0 0]/Length 98>>
stream
/GS1 gs
BT
/F1 1 Tf
11 0 0 11 0 0 Tm
0 g
0 Tc
0 Tw
(XObject String)Tj
0 2.1818 TD
(Line Two)Tj
ET
endstream
endobj
如何获取stream
和endstream
之间的信息。我原以为这将是一个相对简单的操作,但我没有设法检索内容。如果我使用类似下面的内容(在我的 Groovy 代码中),那么我会获取 << >> (字典)之间的信息,但不会获取执行实际标记的实际 PDF 运算符(来自 PostScript PaintProc)。
Iterable<COSName> names = pdDoc.getPage(pageNum).getResources().getXObjectNames();
for (COSName name:names){
def xObject = pdResources.getXObject(name)
if (xObject instanceof PDFormXObject) {
println xObject.getContentStream().dump()
}
}
实际上,获取BT
和ET
运算符之间的内容很适合我的目的。主要重点是找到 FormXObject 及其内容的“定义”,而不是真正探索 FormXObject 在页面内容中的何处使用。
显然我忽略了一些东西,但是什么呢? 提前致谢。
最佳答案
xObject.getContents()
返回一个 InputStream
,您可以从中读取流内容。
关于java - PDFormX对象处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59248154/