按照给定的示例pdfClown
,既可以突出显示特定文本,也可以在相应单词周围绘制一个矩形。
之后有没有可能使这个反应角度可以编辑Adobe Acrobat
?
我目前的工作流程(按计划):
- 导入文档
- 搜索突出显示的文档
- 确定突出显示的颜色
- 围绕矩形的外边界绘制一个矩形
- 根据确定的颜色,将标注添加到另一个包含字母的矩形
Acrobat Reader
据我所知,我不能(例如)用 . 拖动以前突出显示的单词周围的矩形。我使用 pdfClown 网页中提供的示例在每个字符周围绘制了一个反应角。
有什么我忘记考虑的吗?
File inFile = null;
String inFilePath = "/path/to/inputFile/input_highlight.pdf";
String outDirPath = "/tmp";
try {
inFile = new File(inFilePath);
} catch (Exception e) {
throw new RuntimeException(inFilePath + " file access error.", e);
}
Document document = inFile.getDocument();
Pages pages = document.getPages();
PageStamper stamper = new PageStamper();
for (Page page : pages) {
stamper.setPage(page);
PageAnnotations annotations = page.getAnnotations();
for (Annotation annotation : annotations) {
if (annotation.getColor() == null) {
continue;
}
Rectangle2D textStringBox = annotation.getBox();
PrimitiveComposer composer = stamper.getBackground();
composer.setStrokeColor(DeviceRGBColor.Black);
textStringBox.setRect(annotation.getBox().getX(), annotation.getBox().getY(), annotation.getBox().getWidth(), annotation.getBox().getHeight());
composer.drawRectangle(textStringBox);
composer.stroke();
composer.beginLocalState();
composer.setStrokeColor(DeviceRGBColor.Black);
composer.end();
stamper.flush();
System.out.println("Text: " + annotation.getText());
System.out.println("Color: " + annotation.getColor());
System.out.println("Coordinates: " + annotation.getBox().toString());
annotation.setColor(DeviceRGBColor.White);
}
}