• 技术文章 >java >java基础

    Java如何在PDF添加注释

    小妮浅浅小妮浅浅2021-07-13 09:48:37原创2174

    流程

    1、使用Document类加载PDF文档。

    2、创建TextAnnotation对象,添加文本注释。

    3、设定标题、主题等注释属性。

    4、使用Border类设置注释的Border。

    使用Document.getPages().get_Item(int).getAnnotations().add(Annotation)方法向文档添加注释。

    5、用Document.save保存更新的PDF。

    实例

    // Open the source PDF document
    Document pdfDocument = new Document("input.pdf");
     
    // Create annotation
    TextAnnotation textAnnotation = new TextAnnotation(pdfDocument.getPages().get_Item(1), new com.aspose.pdf.Rectangle(200, 400, 400, 600));
     
    // Set annotation title
    textAnnotation.setTitle("Sample Annotation Title");
     
    // Set annotation subject
    textAnnotation.setSubject("Sample Subject");
    textAnnotation.setState(AnnotationState.Accepted);
     
    // Specify the annotation contents
    textAnnotation.setContents("Sample contents for the annotation");
    textAnnotation.setOpen(true);
    textAnnotation.setIcon(TextIcon.Key);
    Border border = new Border(textAnnotation);
    border.setWidth(5);
    border.setDash(new Dash(1, 1));
    textAnnotation.setBorder(border);
    textAnnotation.setRect(new com.aspose.pdf.Rectangle(200, 400, 400, 600));
     
    // Add annotation in the annotations collection of the page
    pdfDocument.getPages().get_Item(1).getAnnotations().add(textAnnotation);
     
    // Save the output file
    pdfDocument.save("output.pdf");

    以上就是Java在PDF添加注释的方法,希望对大家有所帮助。更多Java学习指路:Java基础

    本教程操作环境:windows7系统、java10版,DELL G3电脑。

    专题推荐:java pdf
    品易云
    上一篇:java中如何实现可重入的自旋锁 下一篇:Java在PDF中删除注释

    相关文章推荐

    • python中怎么将pdf内容显示出来?• pdf如何用python读取?• 进阶PDF,就用Python(pdfminer.six和pdfplumber模块)• Python如何读取pdf中的图片• 详解利用python提取pdf文本数字• 看不懂pdf中的英文?就用Python• 如何用Python合并多个pdf 的文件夹• 如何将Python字符串生成PDF?• 如何使用Python生成PDF?• 如何实现使用python将pdf文档加密?• python中pdfkit库如何使用?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网