翻譯|使用教程|編輯:李顯亮|2020-11-25 10:21:20.693|閱讀 287 次
概述:PDF格式允許將文件作為附件嵌入PDF文件中。為了自動執行PDF附件操作,本文提供了一些使用Java在PDF文件中添加和刪??除附件的簡單方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
PDF是數字文檔世界中的主要文件格式之一。PDF格式允許將文件作為附件嵌入PDF文件中。這些附件類似于您添加到電子郵件中的附件。為了自動執行PDF附件操作,本文提供了一些使用Java在PDF文件中添加和刪除附件的簡單方法。
目前,Java版Aspose.PDF升級到v20.11版,感興趣的朋友可點擊下方按鈕下載最新版。(安裝包僅提供部分功能,并設置限制,如需試用完整功能請)
首先,讓我們檢查一下如何檢索PDF文件中的附件信息。該信息包含附件的名稱,描述,MIME類型和其他參數,例如校驗和,修改日期等。以下是在PDF文件中獲取有關附件信息的步驟。
下面的代碼示例演示如何使用Java獲取PDF附件的信息。
// Open document Document pdfDocument = new Document("input.pdf"); // Get particular embedded file FileSpecification fileSpecification = pdfDocument.getEmbeddedFiles().get_Item(1); // Get the file properties System.out.println("Name:-" + fileSpecification.getName()); System.out.println("Description:- " + fileSpecification.getDescription()); System.out.println("Mime Type:-" + fileSpecification.getMIMEType()); // Check if parameter object contains the parameters if (fileSpecification.getParams() != null) { System.out.println("CheckSum:- " + fileSpecification.getParams().getCheckSum()); System.out.println("Creation Date:- " + fileSpecification.getParams().getCreationDate()); System.out.println("Modification Date:- " + fileSpecification.getParams().getModDate()); System.out.println("Size:- " + fileSpecification.getParams().getSize()); }
以下是將附件添加到PDF文檔的步驟。
以下代碼示例顯示了如何使用Java將附件添加到PDF。
// Open a document Document pdfDocument = new Document("input.pdf"); // Set up a new file to be added as attachment FileSpecification fileSpecification = new FileSpecification("sample.txt", "Sample text file"); // Add an attachment to document's attachment collection pdfDocument.getEmbeddedFiles().add(fileSpecification); // Save the updated document pdfDocument.save("output.pdf");
可以使用名稱刪除特定附件,也可以一次刪除所有附件。以下是從PDF文檔中刪除附件的步驟。
以下代碼示例顯示了如何使用Java刪除PDF附件。
// Open a document Document pdfDocument = new Document("input.pdf"); // Delete all attachments pdfDocument.getEmbeddedFiles().delete(); // Save the updated file pdfDocument.save("output.pdf");
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn