Управляйте аннотациями в PDF с помощью Java

Современная библиотека Java для управления аннотациями PDF с помощью наших API.

Как управлять аннотациями с помощью библиотеки Java

Чтобы добавить текстовую аннотацию, мы будем использовать API Aspose.PDF for Java, который является многофункциональным, мощным и простым в использовании API преобразования для платформы Java. Вы можете загрузить его последнюю версию непосредственно из Maven и установить ее в свой проект на базе Maven, добавив следующие конфигурации в pom.xml.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Создание аннотаций в документе PDF с помощью Java


Вам понадобится Aspose.PDF for Java, чтобы попробовать код в своей среде.

  1. Загрузите PDF в экземпляр класса Document.
  2. Создайте аннотацию, которую хотите добавить в PDF.
  3. Добавьте аннотацию в коллекцию Annotations объекта Page.
  4. Сохраните PDF-файл.

Текстовая аннотация PDF — Java

Example: Java


    Document document = new Document(_dataDir + "sample.pdf");
    Page page = document.getPages().get_Item(1);
    Rectangle rect = new Rectangle(200, 750, 400, 790);
    TextAnnotation textAnnotation = new TextAnnotation(page, rect);

    textAnnotation.setTitle("Aspose User");
    textAnnotation.setSubject("Sample Subject");
    textAnnotation.setState (AnnotationState.Accepted);
    textAnnotation.setContents("Sample contents for the annotation");
    textAnnotation.setOpen(true);
    textAnnotation.setIcon(TextIcon.Circle);

    Border border = new Border(textAnnotation);
    border.setWidth(5);
    border.setDash(new Dash(1, 1));
    textAnnotation.setBorder(border);
    textAnnotation.setRect(rect);

    page.getAnnotations().add(textAnnotation);
    document.save(_dataDir + "sample_textannot.pdf");