ZUGFeRD Example

Stimulsoft Reports.JS discussion
Flo
Posts: 23
Joined: Fri Jul 16, 2021 7:18 am

ZUGFeRD Example

Post by Flo »

Hello, is there a working example of adding ZUGFeRD XML to PDF export in Stimulsoft Reports.JS? I only found examples for C#.

I tried it with something like this:

Code: Select all

    var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
                            var zugferdXml = reportdata.ei.value;
                            var buff = new TextEncoder().encode(zugferdXml);

                            settings.zugferdCompliance = Stimulsoft.Report.Export.StiPdfZUGFeRDComplianceMode.V2_1;
                            settings.zugferdConformance = "EN 16931";
                            settings.embeddedFiles = [
                                new Stimulsoft.Report.Export.StiPdfEmbeddedFileData("test.xml", "test", buff)
                            ];
But thats not working.
I want to add it to the function Adobe PDF, see Screenshot:

Image
Max Shamanov
Posts: 975
Joined: Tue Sep 07, 2021 10:11 am

Re: ZUGFeRD Example

Post by Max Shamanov »

Hello.

We need more time to prepare an answer for you.
We will let you know when we get any results.

Thank you
Flo
Posts: 23
Joined: Fri Jul 16, 2021 7:18 am

Re: ZUGFeRD Example

Post by Flo »

Hello,

Thank you very much, that would be quite urgent because there was a legal change in Germany and therefore all customers need this update, otherwise the system would no longer be useable.

Thanks in advance.
Max Shamanov
Posts: 975
Joined: Tue Sep 07, 2021 10:11 am

Re: ZUGFeRD Example

Post by Max Shamanov »

Hello,

Please try to use the following code:

Code: Select all

var pdfExportSettings = new Stimulsoft.Report.Export.StiPdfExportSettings();;
            pdfExportSettings.ZUGFeRDComplianceMode = Stimulsoft.Report.Export.StiPdfZUGFeRDComplianceMode.V2_1;
            pdfExportSettings.ZUGFeRDConformanceLevel = "EN 16931";
            pdfExportSettings.ZUGFeRDInvoiceData = your_file_zugferd - invoice.xml;

            // Export to PDF
            report.exportDocumentAsync(function (pdfData) {
                // Save data to file
                Stimulsoft.System.StiObject.saveAs(pdfData, "your_file.pdf", "application/pdf");
            }, Stimulsoft.Report.StiExportFormat.Pdf, null, pdfExportSettings);
Thank you.
Flo
Posts: 23
Joined: Fri Jul 16, 2021 7:18 am

Re: ZUGFeRD Example

Post by Flo »

Hello, that looks a little better, at least he's trying to merge something now.

When I read out my PDF after merging, it looks like this:

Image

But my XML file is correct but not getting merged.
I used this code:

Code: Select all

                   var pdfExportSettings = new Stimulsoft.Report.Export.StiPdfExportSettings();;
                            pdfExportSettings.ZUGFeRDComplianceMode = Stimulsoft.Report.Export.StiPdfZUGFeRDComplianceMode.V2_1;
                            pdfExportSettings.ZUGFeRDConformanceLevel = "EN 16931";
                            pdfExportSettings.ZUGFeRDInvoiceData = "./e_invoice_zugferd.xml";

                            // Export to PDF
                            report.exportDocumentAsync(function (pdfData) {
                                // Save data to file
                                Stimulsoft.System.StiObject.saveAs(pdfData, "your_file.pdf", "application/pdf");
                            }, Stimulsoft.Report.StiExportFormat.Pdf, null, pdfExportSettings);
                            
Stimulsoft Version 2024.2.6
Max Shamanov
Posts: 975
Joined: Tue Sep 07, 2021 10:11 am

Re: ZUGFeRD Example

Post by Max Shamanov »

Hello,

Could you please send us a sample project that reproduces the issue?

Thank you.
Flo
Posts: 23
Joined: Fri Jul 16, 2021 7:18 am

Re: ZUGFeRD Example

Post by Flo »

Hello,

Attached you will find a test project where the error can be reproduced.
I currently use “Quba” to read the merged PDF file.

Image

Image

Thanks in advance.
Attachments
stimulsoft.zip
Test project zugferd
(35.2 MiB) Downloaded 1240 times
Max Shamanov
Posts: 975
Joined: Tue Sep 07, 2021 10:11 am

Re: ZUGFeRD Example

Post by Max Shamanov »

Hello,

We require more time to investigate the issue thoroughly.

Thank you.
Max Shamanov
Posts: 975
Joined: Tue Sep 07, 2021 10:11 am

Re: ZUGFeRD Example

Post by Max Shamanov »

Hello,

Unfortunate we couldn't reproduce the issue with your sample.
We download the pdf file and open it in Addobe Acrobat and everything is fine.
Please check the attached image.

Thank you.
Attachments
Acrobat_O0pfXzc8Ws.png
Acrobat_O0pfXzc8Ws.png (48.8 KiB) Viewed 4453 times
Flo
Posts: 23
Joined: Fri Jul 16, 2021 7:18 am

Re: ZUGFeRD Example

Post by Flo »

Hello,

No, that can't be the case and it's not possible that that was my original Code.
Are you sure you used my PDF file because I use a completely different XML name in the code.

Code: Select all

   <script type="text/javascript">
        var options = new Stimulsoft.Viewer.StiViewerOptions();
        options.toolbar.showSendEmailButton = true;
        options.toolbar.displayMode = Stimulsoft.Viewer.StiToolbarDisplayMode.Separated;
        options.appearance.fullScreenMode = true;
        options.appearance.scrollbarsMode = true;
        options.height = "600px"; // Height for non-fullscreen mode

        var viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);

        function loadJsonFile(filePath) {
            return fetch(filePath)
                .then(response => {
                    if (!response.ok) {
                        throw new Error('err net');
                    }
                    return response.json();
                })
                .catch(error => {
                    console.error('error fetch: ', error);
                });
        }

        const jsonFilePath = 'reports/SimpleList.json';
        const xmlFilePath = 'reports/SimpleList.xml';

        var report = new Stimulsoft.Report.StiReport();
        var n = Stimulsoft.System.Guid.newGuid().toString().substr(0, 8);
        report.loadFile("reports/SimpleList.mrt" + "?n=" + n);
        report.culture = "de-DE";
        var dataSet = new Stimulsoft.System.Data.DataSet("data");

        viewer.renderHtml("viewerContent");

        loadJsonFile(jsonFilePath).then(reportdata => {
            dataSet.readJson(reportdata);
            report.regData(dataSet.dataSetName, "", dataSet);
        });

        var saveMenu = viewer.jsObject.controls.menus.saveMenu;
        var customSaveItem = viewer.jsObject.VerticalMenuItem(saveMenu, "myItemName", "test download zugferd", "emptyImage", "customItemKey");
        saveMenu.innerContent.appendChild(customSaveItem);

        customSaveItem.action = function () {
            saveMenu.changeVisibleState(false);

            var pdfExportSettings = new Stimulsoft.Report.Export.StiPdfExportSettings();
            pdfExportSettings.ZUGFeRDComplianceMode = Stimulsoft.Report.Export.StiPdfZUGFeRDComplianceMode.V2_1;
            pdfExportSettings.ZUGFeRDConformanceLevel = "EN 16931";
            pdfExportSettings.pdfACompliance = true;
            pdfExportSettings.pdfComplianceMode = Stimulsoft.Report.Export.StiPdfComplianceMode.A3;
            pdfExportSettings.ZUGFeRDInvoiceData = xmlFilePath;

            //Export to PDF
            report.exportDocumentAsync(function (pdfData) {
                //Save data to file
                Stimulsoft.System.StiObject.saveAs(pdfData, "your_file.pdf", "application/pdf");
            }, Stimulsoft.Report.StiExportFormat.Pdf, null, pdfExportSettings);
        }

        // Assigning a report to the Viewer:
        viewer.report = report;

    </script>
As you can see, I am attaching the file with "SimpleList.xml" so it must also be present in Acrobat Reader.
You can also have the PDF checked online at the following link: https://belegmeister.de/zugferd-e-rechn ... -anzeigen/

If the function works without any problems for you, then please send me your example of what you used to merge as a project file like I sent you or try to run my project that I sent you, you will see that it doesn't work.

Thanks in advance.


EDIT:

I see what you mean, but the file which gets merged, is not working, see screenshot:

Image

EDIT 2:

I think I know where the problem is, pdfExportSettings.ZUGFeRDInvoiceData only gets a path from me to the XML file, which is then written in by Stimulsoft but not the data of this path.

Image

Edit 3:

I found the problem, it actually has to be a string and not a path as shown in the example above:
If I load it like this:

Code: Select all

      function loadXmlFile(filePath) {
            return fetch(filePath)
                .then(response => {
                    if (!response.ok) {
                        throw new Error('err net');
                    }
                    return response.text();
                })
                .catch(error => {
                    console.error('error fetch: ', error);
                });
        }
        
                customSaveItem.action = function () {
            saveMenu.changeVisibleState(false);

            var pdfExportSettings = new Stimulsoft.Report.Export.StiPdfExportSettings();
            pdfExportSettings.ZUGFeRDComplianceMode = Stimulsoft.Report.Export.StiPdfZUGFeRDComplianceMode.V2_1;
            pdfExportSettings.ZUGFeRDConformanceLevel = "EN 16931";
            pdfExportSettings.pdfACompliance = true;
            pdfExportSettings.pdfComplianceMode = Stimulsoft.Report.Export.StiPdfComplianceMode.A3;

            loadXmlFile(xmlFilePath).then(xmldata => {
                pdfExportSettings.ZUGFeRDInvoiceData = xmldata;

                report.exportDocumentAsync(function (pdfData) {
                    Stimulsoft.System.StiObject.saveAs(pdfData, "your_file.pdf", "application/pdf");
                }, Stimulsoft.Report.StiExportFormat.Pdf, null, pdfExportSettings);
            });
        }
It is working with the data in it!
Post Reply