AddEmbeddedFile
文件屬性
描述
把檔案以內嵌檔案串流的形式嵌進 PDF,但本身不在任何目錄清單登錄該檔案,也不畫可點擊的註解。函式傳回 EmbeddedFileID 控制代碼,可傳給 AddFileAttachment(在頁面上附加迴紋針圖示)或 AddLinkToEmbeddedFile(建立可點擊、開啟檔案的熱點)。想一次完成內嵌並列為文件層級附件,請改用 EmbedFile。
語法
Delphi
Function TPDFlib.AddEmbeddedFile(Const FileName, MIMEType: WideString): Integer;
ActiveX
Function PDFlib::AddEmbeddedFile(FileName As String, MIMEType As String) As Long
DLL
int DLAddEmbeddedFile(int InstanceID, const wchar_t * FileName, const wchar_t * MIMEType);
參數
| FileName | 磁碟上來源檔案的完整路徑與檔名。其位元組會原封不動複製進 PDF 內嵌檔案串流。 |
|---|---|
| MIMEType | 檔案的 MIME 類型,例如 image/jpeg 或 application/xml。MIME 類型未知時可為空字串。 |
傳回值
| 0 | 無法開啟檔案,或沒有作用中的文件。 |
|---|---|
| Non-zero | EmbeddedFileID 控制代碼,供 AddFileAttachment、AddLinkToEmbeddedFile 或 SetEmbeddedFileStrProperty 使用。 |
備註
PDF 版本行為:內嵌檔案串流與檔案規格字典需要 PDF 1.3。目前文件版本較低且儲存版本未鎖定時,AddEmbeddedFile 會自動把文件提升到 PDF 1.3。把檔案登錄為文件層級附件的呼叫可能需要更高版本:AddFileAttachment 與 EmbedFile 使用 PDF 1.4 的 /Names /EmbeddedFiles 名稱樹,AddLinkToEmbeddedFile 則使用 PDF 1.4 的註解不透明度/外觀透明效果。
只以 AddEmbeddedFile 內嵌的檔案雖然是 PDF 的一部分,但在登錄到文件附件清單或被頁面註解引用之前,閱讀器介面看不到它。將同一個 EmbeddedFileID 搭配 AddFileAttachment 與 AddLinkToEmbeddedFile 重複使用,就能透過文件層級與頁面層級兩種介面公開同一個內嵌檔案,不必複製內嵌位元組
PDF/A compatibility:
- PDF/A-1、PDF/A-2(SetPDFAMode 模式 1–4)— 禁止內嵌檔案;呼叫會被拒絕。
- PDF/A-3(SetPDFAMode 模式 5、6 與 7)— 允許任何 MIME 類型的內嵌檔案。儲存前請透過 SetEmbeddedFileAFRelationship 設定檔案關聯。
範例
// Expose the same embedded file through the document attachment list and a page annotation
var
FileID: Integer;
begin
PDF.NewDocument;
PDF.AddStandardFont('Helvetica');
FileID := PDF.AddEmbeddedFile('C:\reports\sales.csv', 'text/csv');
if FileID = 0 then Exit;
PDF.AddFileAttachment('Source data', FileID);
PDF.AddPage;
PDF.PrintText(50, 750, 'See attached source data');
PDF.AddLinkToEmbeddedFile(50, 720, 16, 16, FileID, 'Source data', 'Open source CSV', 4, 0);
PDF.SaveToFile('with-attachment.pdf');
end;另見
AddFileAttachment, AddLinkToEmbeddedFile, EmbedFile, SetEmbeddedFileAFRelationship, SetEmbeddedFileStrProperty, EmbeddedFileCount