翻譯|使用教程|編輯:李顯亮|2021-03-29 10:10:37.843|閱讀 415 次
概述:由于PDF文件不可編輯,因此批注可讓您提供其他信息。在本文中,您將學(xué)習(xí)如何以編程方式使用PDF文件中的注釋。特別是,您將學(xué)習(xí)如何使用Java在PDF文件中添加或刪除注釋。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
相關(guān)鏈接:
PDF文件中的注釋用于詳細(xì)說(shuō)明內(nèi)容。批注可以是注釋,彈出窗口或圖形對(duì)象,例如箭頭,線條等。由于PDF文件不可編輯,因此批注可讓您提供其他信息。在本文中,您將學(xué)習(xí)如何以編程方式使用PDF文件中的注釋。特別是,您將學(xué)習(xí)如何使用Java在PDF文件中添加或刪除注釋。
Aspose.PDF for Java是功能豐富的API,可讓您使用Java生成,編輯和轉(zhuǎn)換PDF文件。此外,該API允許您無(wú)縫處理各種PDF注釋。感興趣的朋友可點(diǎn)擊下方按鈕下載最新版。
點(diǎn)擊下載最新版Aspose.PDF for Java
Java的Aspose.PDF支持許多注釋,包括但不限于文本,線條,圓形,正方形,突出顯示等。要使用每種注釋類型,Java的Aspose.PDF提供了一個(gè)單獨(dú)的類。例如,LineAnnotation 類用于添加行,而 HighlightAnnotation 類用于添加突出顯示注釋。
為了演示,我們將文本注釋添加到PDF文件中。以下是與API引用一起使用Java向PDF添加文本注釋的步驟。
以下代碼示例顯示了如何使用Java將文本注釋添加到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的Aspose.PDF支持許多注釋,包括但不限于文本,線條,圓形,正方形,突出顯示等。要使用每種注釋類型,Java的Aspose.PDF提供了一個(gè)單獨(dú)的類。例如,LineAnnotation 類用于添加行,而 HighlightAnnotation 類用于添加突出顯示注釋。
為了從PDF頁(yè)面中刪除注釋,Aspose.PDF for Java提供了以下選項(xiàng):
以下是使用Java從PDF文件中刪除注釋的步驟。
以下代碼示例顯示了如何使用Java從PDF頁(yè)面中刪除特定注釋。
// Open the source PDF document Document pdfDocument = new Document("input.pdf"); // Delete particular annotation pdfDocument.getPages().get_Item(1).getAnnotations().delete(1); // Save the update document pdfDocument.save("output.pdf");
以下是使用Java刪除PDF頁(yè)面上所有注釋的步驟。
以下代碼示例顯示了如何使用Java刪除PDF頁(yè)面上的所有注釋。
// Open source PDF document Document pdfDocument = new Document("input.pdf"); // Delete all annotation pdfDocument.getPages().get_Item(1).getAnnotations().delete(); // Save the update document pdfDocument.save("output.pdf");
如果你想試用Aspose的全部完整功能,可聯(lián)系在線客服獲取30天臨時(shí)授權(quán)體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn