我已经看到很多方法可以更改新空白文档的页面大小,但我无法通过pdfReader访问PDF文件
帮助?
答案 0 :(得分:2)
警告:我对CF很了解,但对iText有很多了解。
亨利的答案会起作用,但可能会更有效率。
你想要一个PdfStamper
。更改页面大小不是更高级别直接支持的内容,因此您必须使用低级别的pdf对象调用。像这样:
final static float POINTS_PER_INCH = 72f;
final static float INCHES_TO_ADD = 3f;
PdfReader reader = new PdfReader(pdfPath); // throws
PdfStamer stamper = new PdfStamper(reader, outputStream); // throws
for (int curPageNum = 1; curPageNum <= reader.getNumberOfPages(); ++curPageNum) {
PdfDictionary pageDict = reader.getPageN(curPageNum);
// pdf rects are stored as [llx, lly, urx, ury].
// X increases to the right, Y increases upward.
// Note that the origin doesn't have to be 0,0.
PdfArray mediaBox = pageDict.getAsArray(PdfName.MEDIABOX);
float curBottom = mediaBox.getAsNumber(1).floatValue();
curBottom -= INCHES_TO_ADD * POINTS_PER_INCH;
mediaBox.set(1, new PdfNumber(curBottom));
}
stamper.close(); // throws
除了媒体框之外,您可能还需要修改CROPBOX,使用相同的“获取矩形,调整底部”技术。请注意,您的PDF中可能存在其他几个可能需要或不需要修改的页面框...“艺术框”,“修剪框”,“出血框”。我可能也忘记了一两个。
这几乎肯定会导致底部Y坐标[s]的负值。如果您的PDF由不太好的软件处理,这可能是一个问题。这将是他们软件中的错误,而不是这个过程。但是,如果你需要解决这样的问题,Henry的代码就可以解决问题,生成左下角为0,0的页面。虽然使用iText编写的软件可能不那么精明,但Adobe不会瞄准,iText本身也不会这么精明。
答案 1 :(得分:1)
不确定它是否有效,但这是我发现的
您可以使用正确的空白PDF 页面大小作为起点然后 在右侧覆盖PDF段 使用DDX定位为水印。您 可能需要在之后压平PDF 每个水印都已添加。
http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:62109
没有测试过代码,但也许是这样的?
<cfpdf name="resizedPdf" action="addwatermark" source="blank.pdf" copyfrom="image.pdf">
<cfpdf name="resizedPdfWithFooter" action="addfooter" source="resizedPdf" text="xyz">
请参阅<cfpdf>
doc:http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7995.html