HTML to PDF in c#

I'm having a bit of trouble with the whole XHTML to FO(or xsl).

Can you please tell me how to transform the XHTML to FO?

Or maybe a different approapch to the whole HTML to PDF?

243k 27 27 gold badges 300 300 silver badges 436 436 bronze badges asked Oct 13, 2010 at 12:03 Catalin Florea Catalin Florea 508 8 8 silver badges 16 16 bronze badges I'd definitely buy a product that does this for you. Not an easy task. Commented Oct 13, 2010 at 12:14

5 Answers 5

I have write easiest way to write html to pdf code using NRerco Pdf library which available free, Install nuget package

PM > Install-Package NReco.PdfGenerator

 Create HtmltoPdf() < if (System.IO.File.Exists("HTMLFile.html")) < System.IO.File.Delete("HTMLFile.html"); >System.IO.File.WriteAllText("HTMLFile.html", html); var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter(); if (System.IO.File.Exists("export.pdf")) < System.IO.File.Delete("export.pdf"); >htmlToPdf.GeneratePdfFromFile("HTMLFile.html", null, "export.pdf"); > 
answered Jun 10, 2017 at 12:44 Sanjay Dwivedi Sanjay Dwivedi 739 7 7 silver badges 11 11 bronze badges

Well you could use a HTML to PDF converter via shell, I am sorry I can not rememeber the name of the one I have used in the past, if you have a Google around, you should be able to find a good one.

answered Oct 13, 2010 at 12:09 41k 12 12 gold badges 56 56 silver badges 77 77 bronze badges Yes, it is a program. You use the shell command to run it from your C# Commented Oct 13, 2010 at 12:56

Searched a lot for my personal stack app project SO2PDF and finally settled with wkhtmltopdf which so far is the best free tool to convert HTML to PDF. Yes I used it with c# ;-)

1 1 1 silver badge answered Oct 13, 2010 at 12:14 23k 8 8 gold badges 65 65 silver badges 107 107 bronze badges

Here is the different approach. We are going to convert HTML/XML to PDF directly with 3d party tool (it has multiple preference and settings of conversion and doesn't require any external libraries).

1) Download free HTML to PDF SDK from her (it is easy PDF SDK)

2) Use the following code or run Action Center to customize the conversion

using BCL.easyPDF.Printer; namespace TestPrinter < class Program < static void Main(string[] args) < if(args.Length != 2) return; string inputFileName = args[0]; string outputFileName = args[1]; Printer printer = new Printer(); try < IEPrintJob printjob = printer.IEPrintJob; printjob.PrintOut(inputFileName, outputFileName); >catch(PrinterException ex) < System.Console.WriteLine(ex.Message); >finally < printer.Dispose(); >> > >