简体   繁体   English

PDF小丑可编辑矩形

[英]PDFClown Editable Rectangle

Following the given examples pdfClown can both highlight a specific text and draw a rectangle around the respective words. 在给出的示例之后, pdfClown既可以突出显示特定文本, pdfClown可以在各个单词周围绘制一个矩形。

Is there a possibility to make this reactangle editable afterwards with the Adobe Acrobat ? 是否可以在以后使用Adobe Acrobat使此Reactangle可编辑?

My current workflow (as planned): 我当前的工作流程(按计划):

  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 根据确定的颜色,将标注添加到另一个包含字母的矩形中

I can not (eg) drag the rectangle around the formerly highlighted word with Acrobat Reader , as far as I can see. 据我所知,我无法(例如)使用Acrobat Reader在先前突出显示的单词周围拖动矩形。 I used the provided example from pdfClown's webpage to draw a reactangle around every character. 我使用pdfClown网页上提供的示例在每个字符周围绘制了一个反角。

Is there something that I forgot to consider? 有什么我忘记考虑的事情吗?

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);

    }

}

As it seems your main issue is that 看来您的主要问题是

I can not (eg) drag the rectangle around the formerly highlighted word with Acrobat Reader 我无法(例如)使用Acrobat Reader在先前突出显示的单词周围拖动矩形

The reason is that you draw your rectangle in the page content (the PageStamper you use is documented as Tool for content insertion into existing pages ). 原因是您在页面内容中绘制了矩形(您使用的PageStamper被记录为将内容插入到现有页面中的工具 )。 The page content is fixed, in particular as far as Acrobat Reader is concerned; 页面内容是固定的,特别是就Acrobat Reader而言; Acrobat Reader only allows you to move annotations. Acrobat Reader仅允许您移动注释。

If you want to have a rectangle you can drag around, therefore, you have to use a rectangle annotation. 如果要使用矩形,可以拖动它,因此,必须使用矩形注释。 Rectangle annotations can be created like this: 矩形注释可以这样创建:

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 ) AnnotationSample.java

You also mention that you want to add a callout ; 您还提到要添加标注 a callout annotation can be created like this: 标注注释可以这样创建:

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 ) AnnotationSample.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM