【发布时间】:2020-01-10 10:07:15
【问题描述】:
我在 pdf 文件中添加隐藏文本以使其可搜索。对于某些文档,左下角似乎是默认值 (0,0),而对于其他文档,它是左上角。我的理解是,可以因为页面旋转。
在下面的代码中,我正在获取/打印页面旋转,但对于我拥有的不同测试 pdf 文件,它显示为 0。为什么有些文档会将 (0,0) 翻译到左下角而其他文档会翻译到左上角的任何想法。
File file = new File(inputDocumentName);
PDDocument document = PDDocument.load(file);
//Retrieving the pages of the document
PDPage page = document.getPage(0);
int rotation = page.getRotation();
System.out.println("Rotation: " + rotation);
contentStream.moveTo(0, 0);
//Begin the Content stream
contentStream.beginText();
//Setting the font to the Content stream
contentStream.setFont(PDType1Font.COURIER, 20);
contentStream.newLineAtOffset(0, 0);
//Adding text in the form of string
contentStream.showText(text);
//Ending the content stream
contentStream.endText();
//Closing the content stream
contentStream.close();
//Saving the document
document.save(new File(outputDocumentName));
//Closing the document
document.close();
关于如何在 pdf 文档中找到代表哪个角 (0,0) 的任何想法。谢谢。
【问题讨论】:
-
您是否检查过裁剪框和媒体框(如果页面)?