AddFacturXAssociatedFileFromString
文件屬性
描述
把電子發票 XML 寫成 PDF/A-3 關聯檔案,並為 Factur-X、ZUGFeRD 與 XRechnung 設定檔產生必要的 XMP 電子發票中繼資料
語法
Delphi
Function TPDFlib.AddFacturXAssociatedFileFromString(Const XMLBytes: AnsiString; Const ConformanceLevel, FileName, Description, Relationship, Version, CountryCode: WideString): Integer;
參數
| XMLBytes | 要內嵌的原始 UTF-8 XML 位元組 |
|---|---|
| ConformanceLevel | 發票設定檔層級,例如 MINIMUM、BASIC WL、BASIC、EN16931、EXTENDED、XRECHNUNG、EXTENDED-CTC-FR 或 EXTENDED-B2B-FR |
| FileName | 內嵌 XML 檔名,通常為 factur-x.xml、xrechnung.xml、zugferd-invoice.xml 或 ZUGFeRD-invoice.xml;空值預設為 factur-x.xml |
| Description | 寫入檔案規格的選配 /Desc 文字 |
| Relationship | /AFRelationship 值;空值預設為 Alternative |
| Version | 發票設定檔版本;空值預設為 1.0 |
| CountryCode | 選配的國家設定檔代碼,例如空字串、DE 或 FR |
傳回值
| 0 | 文件不在 PDF/A-3 模式、XML 與設定檔組合無效,或發票 XML 已經加入過 |
|---|---|
| Non-zero | 新建檔案規格的物件控制代碼 |
備註
寫出附件之前,方法會驗證檔名、符合性層級、版本、國家設定檔與 /AFRelationship
COMFORT 只接受搭配 ZUGFeRD-invoice.xml 與版本 1.0;zugferd-invoice.xml 選用 ZUGFeRD 2.0 設定檔,xrechnung.xml 則選用 XRECHNUNG 設定檔
此方法會寫入 DocumentFileName、DocumentType、Version 與 ConformanceLevel XMP 欄位,並確認 XML guideline ID 與所選設定檔相符。呼叫端仍須在儲存前建立一般可見的發票頁面內容
範例
// Add EN 16931 invoice XML to a PDF/A-3b document
var
FileID: Integer;
begin
PDF.SetPDFAMode(5);
PDF.NewDocument;
FileID := PDF.AddFacturXAssociatedFileFromString(
InvoiceXML,
'EN16931',
'factur-x.xml',
'Factur-X invoice XML',
'Alternative',
'1.0',
'');
if FileID = 0 then Exit;
PDF.SaveToFile('factur-x.pdf');
end;
另見
AddPDFA3AssociatedFileFromString, DetectFacturXInvoice, ValidateFacturXInvoice, ExtractFacturXXMLToString