附件 (Attachment)
在Foxit PDF SDK中,attachments指的是文档附件而不是文件附件注释。它允许将整个文件封装在文档中,就像电子邮件附件一样。Foxit PDF SDK提供应用程序APIs来访问附件,例如加载附件,获取附件,插入/删除附件,以及访问附件的属性。
Example:
如何从PDF文档中导出嵌入的附件文件,并将其另存为单个文件
import com.foxit.sdk.PDFException; import com.foxit.sdk.common.Library; import com.foxit.sdk.pdf.Attachments; import com.foxit.sdk.pdf.FileSpec; import com.foxit.sdk.pdf.PDFDoc; import com.foxit.sdk.pdf.objects.PDFNameTree; ... PDFNameTree empty_nametree = new PDFNameTree(); { // Get information of attachments. Attachments attachments = new Attachments(doc, empty_nametree); int count = attachments.getCount(); for (int i = 0; i < count; i++) { String key = attachments.getKey(i); FileSpec file_spec = attachments.getEmbeddedFile(key); if (!file_spec.isEmpty()) { String name = file_spec.getFileName(); if (file_spec.isEmbedded()) { String export_file_path = output_path + name; file_spec.exportToFile(export_file_path); } } } }
如何删除PDF文档中所有的附件文件
import com.foxit.sdk.PDFException; import com.foxit.sdk.common.Library; import com.foxit.sdk.pdf.Attachments; import com.foxit.sdk.pdf.PDFDoc; import com.foxit.sdk.pdf.objects.PDFNameTree; ... // Assuming PDFDoc doc has been loaded. PDFNameTree empty_nametree = new PDFNameTree(); { // Get information of attachments. Attachments attachments = new Attachments(doc, empty_nametree); attachments.removeAllEmbeddedFiles(); } ...