How to Generate PDFs from XML files in c# using “https://github.com/itplr-kosit/xrechnung-visualization”?

I want to create PDF files using https://github.com/itplr-kosit/xrechnung-visualization.
Based on the documentation I have to create an intermediate file first which should be valid to “https://github.com/itplr-kosit/xrechnung-visualization/blob/master/src/xsd/xrechnung-semantic-model.xsd” than I should use “https://github.com/itplr-kosit/xrechnung-visualization/blob/master/src/xsl/xrechnung-html.xsl” or “https://github.com/itplr-kosit/xrechnung-visualization/blob/master/src/xsl/xr-pdf.xsl” to create HTML file or PDF file.
I am using Saxon-He to do this and I could generate the HTML file.

I am using Saxon-He to convert XML to XR like this:

public static void XmlToInterWithSaxon(byte[] xmlData, byte[] xslUblData, byte[] xslHtmlData, byte[] xslPdfData, string xmlPath, string xsdPath)
{
try
{
Processor processor = new Processor();
XsltCompiler xsltCompiler = processor.NewXsltCompiler();
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.DtdProcessing = DtdProcessing.Parse;
var interResultt = “”;
using (MemoryStream msXslt = new MemoryStream(xslUblData))
{
using (XmlReader reader = XmlReader.Create(msXslt, readerSettings))
{
xsltCompiler.BaseUri = new Uri(“C:Pathtoxsl”);
XsltExecutable xsltExecutable = xsltCompiler.Compile(reader);
var xsltTransformer = xsltExecutable.Load30();
using (MemoryStream inputStream = new MemoryStream(xmlData))
{
using (MemoryStream outputStream = new MemoryStream())
{
xsltTransformer.Transform(inputStream, processor.NewSerializer(outputStream));
interResultt = System.Text.Encoding.UTF8.GetString(outputStream.ToArray());

                    string directoryPath = Path.GetDirectoryName(xmlPath);
                    string newFileName = Path.GetFileNameWithoutExtension(xmlPath);
                    string destinationFilePath = Path.Combine(directoryPath, newFileName + "-inter" + ".xml");
                    File.WriteAllText(destinationFilePath, interResultt);
                    var isInterValid = ValidateXml(destinationFilePath, xsdPath);

                    byte[] interData = Encoding.UTF8.GetBytes(interResultt);
                    if (isInterValid)
                    {
                        InterToPDFWithSaxon(interData, xslPdfData, xmlPath);
                    }
                    else
                    {
                        throw new Exception("Error validating XML with XSD");
                    }
                }
            }
        }
    }
}
catch (Exception ex)
{
    Console.WriteLine("Error transforming XML to HTML: " + ex.Message);
}

}

than I am using the same function to convert XR to PDF like this:
public static void InterToPDFWithSaxon(byte[] xmlData, byte[] xslPdfData, string xmlPath)
{
try
{
Processor processor = new Processor();
XsltCompiler xsltCompiler = processor.NewXsltCompiler();
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.DtdProcessing = DtdProcessing.Parse;
var pdfResult = “”;
var pdfFilePath = “”;
using (MemoryStream msXslt = new MemoryStream(xslPdfData))
{
using (XmlReader reader = XmlReader.Create(msXslt, readerSettings))
{
xsltCompiler.BaseUri = new Uri(“C:Pathtoxsl”);
XsltExecutable xsltExecutable = xsltCompiler.Compile(reader);
var xsltTransformer = xsltExecutable.Load30();
using (MemoryStream inputStream = new MemoryStream(xmlData))
{
using (MemoryStream outputStream = new MemoryStream())
{
xsltTransformer.Transform(inputStream, processor.NewSerializer(outputStream));
pdfResult = System.Text.Encoding.UTF8.GetString(outputStream.ToArray());

                    pdfFilePath = Path.ChangeExtension(xmlPath, ".pdf");
                    File.WriteAllText(pdfFilePath, pdfResult);
                }
            }
        }
    }
}
catch (Exception ex)
{
    Console.WriteLine("Error transforming XML to PDF and saving to file: " + ex.Message);
}

}

It generates a pdf file but when try to open it says: “There was an error opening this document, The file is damaged and could not be repaired”
Is there anything else that I should use?

New contributor

mensur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật