web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Inge M. Bruvik Profile Picture
    1,111 Moderator on at

    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?

  • Swati Dev Profile Picture
    5 on at

    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 

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

    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

    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,111 Moderator on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,151

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,443 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,092 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans