简体   繁体   中英

XSL + XML -> PDF for C#

I know several people asked questions like this, but no answer helped to solve my problem.

Well, I have xsl and xml and want to generate pdf with a processor like Apache.FOP. I am not able to use any JAVA programms like that. Just able to use C# libraries / exe.

I tried to use nFop :

  • Version 1.x uses Java.io and..
  • Version 2.0 doesn't have the ability to set XsltSettings

My current Software uses XSL + XML -> HTML (using standard Stystm.Xml.Xsl on C#) and wktmltopdf to generate PDF from created HTML . But tables got split when they are too long for the page, and on the next page you don't have any column headers (this is very important for my problem).

I think there are no Free FO-Processor for pure C

Have a look at FoNET .

public static bool XMLToPDF(string pXmlFile, string pXslFile, string pFoFile, string pPdfFile)
{
    string lBaseDir = System.IO.Path.GetDirectoryName(pXslFile);
    XslCompiledTransform lXslt = new XslCompiledTransform();
    lXslt.Load(pXslFile);
    lXslt.Transform(pXmlFile, pFoFile);
    FileStream lFileInputStreamFo = new FileStream(pFoFile, FileMode.Open);
    FileStream lFileOutputStreamPDF = new FileStream(pPdfFile, FileMode.Create);
    FonetDriver lDriver = FonetDriver.Make();
    lDriver.BaseDirectory = new DirectoryInfo(lBaseDir);
    lDriver.CloseOnExit = true;
    lDriver.Render(lFileInputStreamFo, lFileOutputStreamPDF);
    lFileInputStreamFo.Close();
    lFileOutputStreamPDF.Close();
    return System.IO.File.Exists(pPdfFile);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM