AddEmbeddedFile
文档属性
描述
将一个文件作为 embedded file stream 嵌入 PDF,但该调用本身不会把文件注册到任何 Catalog 列表中,也不会绘制可点击注释。函数返回一个 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 embedded file stream 中 |
|---|---|
| MIMEType | 文件的 MIME 类型,例如 image/jpeg 或 application/xml。MIME 类型未知时可以传入空字符串 |
返回值
| 0 | 无法打开文件,或当前没有活动文档 |
|---|---|
| Non-zero | 一个 EmbeddedFileID 句柄,供 AddFileAttachment、AddLinkToEmbeddedFile 或 SetEmbeddedFileStrProperty 使用 |
备注
PDF 版本行为:embedded file stream 和 file specification dictionary 需要 PDF 1.3。如果当前文档版本更低且保存版本未锁定,AddEmbeddedFile 会自动把文档提升到 PDF 1.3。把文件注册为文档级附件的调用可能需要更高版本:AddFileAttachment 和 EmbedFile 使用 PDF 1.4 的 /Names /EmbeddedFiles name tree,AddLinkToEmbeddedFile 使用 PDF 1.4 注释不透明度/外观透明度
只用 AddEmbeddedFile 嵌入的文件是 PDF 的一部分,但在注册到文档附件列表或被页面注释引用前,阅读器界面中不可见。将同一个 EmbeddedFileID 同时传给 AddFileAttachment 和 AddLinkToEmbeddedFile,可以通过文档级和页面级界面暴露同一个嵌入文件,而不会重复嵌入文件字节
PDF/A 兼容性
- 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