PDFormX对象处理

PDFormXObject Processing

我有一个说明如何创建表单的 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

如何获取streamendstream之间的信息。我原以为这会是一个相对简单的操作,但我还没有设法检索到内容。如果我使用类似下面的内容(在我的 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()
    }
 }

实际上,获取 BTET 运算符之间的内容符合我的目的。主要重点是找到 FormXObject 的 "definition" 及其内容,而不是真正探索 FormXObject 在页面内容中的使用位置。

显然我忽略了什么,但是什么呢? 提前致谢。

xObject.getContents() returns 你 InputStream 你可以从中读取流内容。