PDF小丑可编辑矩形

PDFClown Editable Rectangle

按照给定的示例pdfClown 既可以突出显示特定文本,也可以在相应的单词周围绘制一个矩形。

是否可以使用 Adobe Acrobat 使此 reactangle 之后可编辑?

我当前的工作流程(按计划):

  1. Import a document
  2. Search document for Highlightings
  3. Determine the Hightlighting's color
  4. Draw a rectangle around the outer boundaries of the rectangle
  5. add a callout to a another rectangle containing a letter, depending on the determined color

据我所知,我不能(例如)在以前用 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);

    }

}

看来你的主要问题是

I can not (e.g.) drag the rectangle around the formerly highlighted word with Acrobat Reader

原因是您在页面内容中绘制矩形(您使用的 PageStamper 记录为 将内容插入现有页面的工具 )。页面内容是固定的,特别是就 Acrobat Reader 而言; Acrobat Reader 只允许您移动注释。

如果你想要一个可以拖动的矩形,那么你必须使用矩形注释。可以这样创建矩形注释:

new org.pdfclown.documents.interaction.annotations.Rectangle(
  page,
  new Rectangle(50, 370, 100, 30),
  "Text of the Rectangle annotation"
  ).withColor(DeviceRGBColor.get(Color.RED))
   .withBorder(new Border(1, new LineDash(new double[]{5})))
   .withAuthor("Stefano")
   .withSubject("Rectangle")
   .withPopup(new Popup(
     page,
     new Rectangle2D.Double(200, 325, 200, 75),
     "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
     ));

(AnnotationSample.java)

您还提到要添加标注;可以像这样创建标注注释:

new StaticNote(
  page,
  new Rectangle(250, 90, 150, 70),
  "Text of the Callout note annotation"
  ).withLine(
     new StaticNote.CalloutLine(
       page,
       new Point(250,125),
       new Point(150,125),
       new Point(100,100)
       )
     )
   .withLineEndStyle(LineEndStyleEnum.OpenArrow)
   .withBorder(new Border(1))
   .withColor(DeviceRGBColor.get(Color.YELLOW));

(AnnotationSample.java)