I need to convert a bunch of HTML files (about 30) to PDF files. It would be great if I could create TOC and page links, but for now I will just be happy to convert individual files :)
I already tried a couple of solutions, the most successful was EO.PDF, but it put an unpleasant watermark on every page, and it could not process the files for several megabytes, and some of them - 10 megabytes +.
I read a lot of good things about wkhtmltopdf and I found a wrapper for it, WkHTMLToSharp. I cannot find any documentation, so I have combined the next bit of code that throws an exception. I would appreciate any help resolving this.
I noticed a line that throws an exception. An exception (very UNhelpful) is:
"The type initializer for 'WkHtmlToXSharp.WkHtmlToPdfConverter' threw an exception."
- THE CODE -
/// <summary> /// Creates a PDF file from the HTML file passed in /// </summary> /// <param name="cFile">Full path to HTML file to generate PDF from</param> /// <param name="pdfFile">Full path of PDF output file</param> public static void WritePDF(string cFile, string pdfFile) { // Generates "The type initializer for // 'WkHtmlToXSharp.WkHtmlToPdfConverter' threw an exception.": WkHtmlToPdfConverter w = new WkHtmlToPdfConverter(); byte[] strHTML = w.Convert(cFile); File.WriteAllBytes(pdfFile, strHTML); w.Dispose(); }
After solving the problem with the missing DLL, I found that a bit of code actually converts an HTML string, not a file. I can work with this, but MUCH prefers to work with HTML files.
In addition, none of the images are displayed in the PDF file. This is all JPG (I know there is a problem with GIFS).
source share