WPCubed Product Support

Embed XML for "elektronische Rechnung" (ZugFerD)

wpsupport

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;
#6 ♥ 0
3.9k Views 13 links 3 users 1 ♥ read 3 min
wpsupport

A new version with invoice embedding is currently beeing developed.

The mode wpdfaLevel3B should be set for ZUGFeRD.

#4 ♥ 1

@wpsupport:
Yes. You need to activate PDFA mode

Is this PDF/A-3? If I put the file into a validator it says it's PDF/A-1B. But I may use the validator wrong.

@wpsupport:
https://www.wpcubed.com/manuals/wpdf/method_addfileattachment.htm

https://www.wpcubed.com/manuals/wpdf/method_addxmpextra.htm

There is some discussion in the Delphi-PRAXIS board that the example may be outdated: Delphi-PRAXiS - Einzelnen Beitrag anzeigen - Wie sieht die Zukunft mit XRechnung, ZUGFerD, Peppol und Co. aus ? (delphipraxis.net)
wPDFMan.pdf that comes with wPDF 5 differs a bit.

#3 ♥ 0

Is it possible to embed a (German) "elektronische Rechnung" in the "ZugFerD"-Format (XML) into the PDF with WPPDF? (PDF/A-3)

#1 ♥ 0