Generating Pdf From Latex Files
To generate a PDF from a HTML file with C# in Windows Forms, we are going to use Pechkin, the.NET Wrapper for wkhtmltopdf DLL, library that uses Webkit engine to convert HTML pages to PDF. Pechkin is available as a NuGet package, in most cases you should use SynchronizedPechkin as it protects multithreaded code from crashing the lib. You can use pdfsharp library for generating pdf file from c# applications check this one. Create PDF file from C# is explain the simple step by step methods to generate pdf file from c#. There are PDF generators that use HTML as templates or Word-documents (eg: www.docati.com). I prefer those, since they provide a nice.
I am using the following library to generate a PDF document (https://www.nuget.org/packages/HtmlRenderer.PdfSharp).
I am having some odd issues while trying to use the library. The HTML string is being appropriately passed, yet I am receiving the following error.
However, the the html variable looks as follows:
I saved the HTML in a separate file and opened it in a browser and it displayed just.
Additionally, I tried wrapping the HTML in <html><body></body></html>
. The odd thing is, I received no error, but got a blank PDF.
In case it helps, the HTML is generated by the following:
and passed into a View
by a Controller method
Any advice would be appreciated.
Mr ListerGenerating Pdf From Html C#
1 Answer
You have to call doc.AddPage() before you can use a document. It returns a reference to the page which you can use for setting dimensions or getting the XGraphics/renderContext.
Can't instantly find it, but there is a very similar question either here on SF or on the PdfSharp / HtmlRenderer forum/help pages.