To embed the created XML with wPDF you can use this code.
The example assumes the XML code has been already saved to the database in the blob field OrdersINVOICEXML.
The Invoice has been created with WPTools and is exported using the WPPDFExport1 component.
procedure TForm1.btnCreatePDF(Sender: TObject);
var mem : TMemoryStream;
lst : TStringList;
s : string;
begin
mem := TMemoryStream.Create;
try
WPPDFExport1.Info.Producer := 'wPDF - https://www.wpcubed.com';
if FileExists(PDFName.Text) then
begin
if MessageDlg('PDF Datei existiert. Überschreiben?',mtConfirmation, [mbYes, mbNo],0)=ID_NO then
begin
PDFName.SelectAll;
PDFName.SetFocus;
exit;
end;
end;
WPPDFExport1.FileName := PDFName.Text;
WPPDFExport1.AutoLaunch := false;
WPPDFExport1.CompressStreamMethod := wpCompressFlate;
WPPDFExport1.Source.ReformatAll(true);
WPPDFExport1.Source.ReformatAll(true);
WPPDFExport1.FontMode := wpEmbedCIDFonts;
OrdersINVOICEXML.SaveToStream(mem);
mem.Position := 0;
if mem.Size>0 then
begin
WPPDFExport1.PDFAMode := wpdfaLevel3B;
lst := TStringList.Create;
s := Format( pdfa_xfactur_info, [pdfa_xfactur_filename,'EXTENDED'] );
WPPDFExport1.AddXMPExtra( pdfa_xfactur_schema, s );
lst.Free;
end;
WPPDFExport1.BeginDoc;
try
if mem.Size>0 then
WPPDFExport1.AddFileAttachment(
pdfa_xfactur_filename,
pdfa_xfactur_description, mem, 'text/xml', now, [wpDontCompressData])
else
ShowMessage('Keine XML Daten für X-Factur vorhanden, erzeuge reguläres PDF');
WPPDFExport1.Print;
finally
WPPDFExport1.EndDoc;
end;
PDFName.SelectAll;
PDFName.SetFocus;
finally
mem.Free;
end;
end;