原創(chuàng)|使用教程|編輯:張瑩心|2021-10-22 11:41:06.057|閱讀 615 次
概述:PDF 注釋是添加到 PDF 文檔的附加對象。有時您可能需要從 PDF 文件中提取這些附加數(shù)據(jù),以便在不打開文檔的情況下了解注釋詳細信息。在本文中,我們將介紹如何使用Spire.PDF for Java在 Java 中從 PDF 中獲取注釋。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Spire.PDF for Java 是一款專門對 PDF 文檔進行操作的 Java 類庫。該類庫的主要功能在于幫助開發(fā)人員在 Java 應(yīng)用程序(J2SE和J2EE)中生成 PDF 文檔和操作現(xiàn)有 PDF 文檔,并且運行環(huán)境無需安裝 Adobe Acrobat。
PDF 注釋是添加到 PDF 文檔的附加對象。有時您可能需要從 PDF 文件中提取這些附加數(shù)據(jù),以便在不打開文檔的情況下了解注釋詳細信息。在本文中,我們將介紹如何使用Spire.PDF for Java在 Java 中從 PDF 中獲取注釋。
可點擊此處下載最新版測試。
從 PDF 文件中獲取注釋
Spire.PDF for Java 提供了PdfPageBase.getAnnotationsWidget()方法來獲取文檔指定頁面的注釋集合。
以下是從PDF文件的第一頁獲取所有注釋的步驟:
import com.spire.pdf.*; import com.spire.pdf.annotations.*; import java.io.FileWriter; public class Test { public static void main(String[] args) throws Exception { //Create an object of PdfDocument class. PdfDocument pdf = new PdfDocument(); //Load the sample PDF document pdf.loadFromFile("Annotations.pdf"); //Get the annotation collection of the first page of the document. PdfAnnotationCollection annotations = pdf.getPages().get(0).getAnnotationsWidget(); //Create a StringBuilder object StringBuilder content = new StringBuilder(); //Traverse all the annotations for (int i = 0; i < annotations.getCount(); i++) { //If it is the pop-up annotations, continue if (annotations.get(i) instanceof PdfPopupAnnotationWidget) continue; //Get the annotations’ author content.append("Annotation Author: " + annotations.get(i).getAuthor()+"\n"); //Get the annotations’ text content.append("Annotation Text: " + annotations.get(i).getText()+"\n"); //Get the annotations’ modified date String modifiedDate = annotations.get(i).getModifiedDate().toString(); content.append("Annotation ModifiedDate: " + modifiedDate+"\n"); //Get the annotations’ name content.append("Annotation Name: " + annotations.get(i).getName()+"\n"); //Get the annotations’ location content.append ("Annotation Location: " + annotations.get(i).getLocation()+"\n"); } //Write to a .txt file FileWriter fw = new FileWriter("GetAnnotations.txt"); fw.write(content.toString()); fw.flush(); fw.close(); } }
整合所有格式API處理套包Spire.office for Java正在慧都網(wǎng)火熱銷售中!立馬1分鐘了解全部咨詢!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn