จัดการคำอธิบายประกอบใน PDF โดยใช้ Java

การจัดการคำอธิบายประกอบในเอกสาร PDFใช้ Aspose.PDF สำหรับ Java เพื่อแก้ไขไฟล์ PDF แบบโปรแกรม

วิธีจัดการคำอธิบายประกอบโดยใช้ไลบรารี Java

ในการเพิ่มคำอธิบายประกอบข้อความ เราจะใช้ Aspose.PDF for Java API ซึ่งเป็น 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 ในอินสแตนซ์ของคลาสเอกสาร 1.สร้างคำอธิบายประกอบที่คุณต้องการเพิ่มใน PDF 1.เพิ่มคำอธิบายประกอบลงในคอลเลกชันคำอธิบายประกอบของวัตถุหน้า 1.บันทึกไฟล์ PDF

คำอธิบายประกอบข้อความ PDF - Java

Example: Java

String inputFile = DATA_DIR.resolve("sample.pdf").toString();
String outputFile = DATA_DIR.resolve("java-add-annotation.pdf").toString();
Document pdfDocument = new Document(inputFile);
DefaultAppearance appearance = new DefaultAppearance();
appearance.setFontSize(12);
appearance.setFontName("Arial");
Page page = pdfDocument.getPages().get_Item(1);
FreeTextAnnotation freeTextAnnotation =
        new FreeTextAnnotation(
                page,
                new Rectangle(299.988, 703.664, 508.708, 720.769),
                appearance);
freeTextAnnotation.setContents("This is a free text annotation.");
freeTextAnnotation.setName("FreeText1");
freeTextAnnotation.setSubject("Revision 01");
freeTextAnnotation.setTitle("Free Text Annotation");
freeTextAnnotation.setPopup(new PopupAnnotation(page,
        new Rectangle(299.988, 713.664, 308.708, 720.769)));
freeTextAnnotation.getPopup().setOpen(true);

page.getAnnotations().add(freeTextAnnotation);
pdfDocument.save(outputFile);
pdfDocument.close();