首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PDFClown可编辑矩形

PDFClown可编辑矩形
EN

Stack Overflow用户
提问于 2016-01-29 15:31:34
回答 1查看 468关注 0票数 0

按照给定的示例,pdfClown既可以突出显示特定的文本,也可以围绕各自的单词绘制矩形。

是否有可能在Adobe Acrobat之后使此反应角可编辑?

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

  1. 导入文件
  2. 搜寻高度的文件
  3. 确定高亮度的颜色
  4. 在矩形的外部边界周围画一个矩形
  5. 根据确定的颜色,向另一个包含字母的矩形添加标注

我不能(例如)在我所能看到的范围内,用Acrobat Reader在以前高亮显示的单词周围拖动矩形。我使用pdfClown的网页中提供的例子来绘制每个字符的反作用力。

有什么我忘了考虑的吗?

代码语言:javascript
复制
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);

    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-10 08:45:48

看上去你的主要问题是

我不能(例如)用Acrobat在以前高亮显示的单词周围拖动矩形

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

如果您想要一个矩形,您可以拖动,因此,您必须使用矩形注释。矩形注释可以创建如下所示:

代码语言:javascript
复制
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)"
     ));

(https://svn.code.sf.net/p/clown/code/trunk/java/pdfclown.samples.cli/src/org/pdfclown/samples/cli/AnnotationSample.java)

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

代码语言:javascript
复制
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));

(https://svn.code.sf.net/p/clown/code/trunk/java/pdfclown.samples.cli/src/org/pdfclown/samples/cli/AnnotationSample.java)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35088168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档