Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Zugferd invoices in BC

(0) ShareShare
ReportReport
Posted on by 5

Hello Folks

I need to add a functionality to my Project that integrates/embeds XML file into the pdf Document.

This is basically should be e-invoice in Zugferd Format. So what i have read so far is that Zugferd invoice

is a PDF/A format document that contains PDF invoice and xml version of the invoice.

I could not find a way to implement this type of Code in Al - Business Central. . Has anyone done something of similar kind?

Regards

Swati

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Zugferd invoices in BC

    I do not have any specific experience with any of those pdf .net libraries.

    But i see there are a lot if them available, so the trick is to find one that covers what you need.

    But it looks to me that you are on the right track.

  • Swati Dev Profile Picture
    5 on at
    RE: Zugferd invoices in BC

    Thanks for you reply.

    Do you have any idea which .Net Library is available for this functionality.

    I found the below code in internet . It is using iText Library which we will have to buy i guess as its not already included in .Net libraries.

    Is this the right direction i am looking my solution in ?

    using iText.Forms;

    using iText.Kernel.Pdf;

    using iText.Pdfa;

    using iText.Layout.Element;

    using System;

    using System.Collections.Generic;

    using System.IO;

    using System.IO.Compression;

    using System.Linq;

    using System.Text;

    namespace PdfXml

    {

       class Program

       {

           static void Main(string[] args)

           {

               string pdfIn = "\\xfar\\pdfin.pdf";

               string pdfOut = "\\xfar\\pdfoutU.pdf";

               string cdaIn = "\\xfar\\cda.xml";

               StreamReader Reader = new StreamReader(cdaIn);

                   var content = new StringBuilder();

                   string line;

                   while (Reader.EndOfStream == false)

                   {

                       line = Reader.ReadLine();

                       content.AppendLine(line);

                   }

                   byte[] bytes = Encoding.ASCII.GetBytes(content.ToString());            

                   PdfDocument pdfDoc = new PdfDocument(new PdfReader(pdfIn), new PdfWriter(pdfOut));            

                   PdfStream stream = new PdfStream();;

                   PdfNameTree nameTree1 = pdfDoc.GetCatalog().GetNameTree(new PdfName("XFAResource"));

                   stream.SetCompressionLevel(9);

                   stream.SetData(bytes, true);

                   nameTree1.AddEntry("dataset", stream);

                   nameTree1.BuildTree();

                   nameTree1.SetModified();

                   Console.WriteLine("ok");

                   }                

                 pdfDoc.Close();

           }

       }

    }

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Zugferd invoices in BC

    Ok, then I understand.

    Are you in BC on prem or in BC online.

    In BC On prem you could use a .net library to do this, if you are in BC Online you would have to run it through an Azure function.

  • Swati Dev Profile Picture
    5 on at
    RE: Zugferd invoices in BC

    zugferd_5F00_2p1_5F00_XRECHNUNG_5F00_Elektron.pdf

    Hello Inge

    Thanks a lot for taking out your time to answer this question. But it is opposite of what i am looking for. I don't need to insert/attach pdf into xml rather vice versa

    If you might have seen in pdf/a type documents . On opening them with Acrobat reader , you find an attachment with the pdf file . In my case i need to add xml file as an attachment to the pdf file.

    I have attached an example. If you open it in Acrobat reader you will find an xml attached to it.

    So the requirement is generate PDF/A format document through  Business Central Code 

  • Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Zugferd invoices in BC

    You can use the xmldocument datatype to create your xml file.

    And in one of the tags in your xml document you can fill in the base64 encoded data for a pdf representation of the same invoice.

    Is it something like that you are looking for?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans