How to maintain appearance when converting HTML to PDF

I use iTextSharp to convert HTML to PDF, overall it works pretty well, but it doesn't seem to be like most formatting.

Bold, Italic, and Underline work, but none of the font sizes, styles, or other information is respected, so the export does not look very similar to the HTML that was used to create the format.

Does anybody know how

  • fix iTextSharp export method (below is an example of my code)
  • Or find out about another product that exists that provides this functionality and won't break the bank?

This is my code:

//Do the PDF thing
Document document = new Document(PageSize.A4);
using (Stream output = new FileStream(Server.MapPath(relDownloadDoc), FileMode.Create, FileAccess.Write, FileShare.None))
using (Stream htmlStream = new FileStream(Server.MapPath(relProcessingDoc), FileMode.Open, FileAccess.Read, FileShare.Read))
using (XmlTextReader reader = new XmlTextReader(htmlStream))
{
    reader.WhitespaceHandling = WhitespaceHandling.None;
    PdfWriter.GetInstance(document, output);
    document.Open();
    Console.ReadLine();
    HtmlParser.Parse(document, reader);
    document.Close();
}
+3
source share
4 answers

WKHTMLTOPDF.

webkit . .

+3

HTML + CSS PDF PHP? Prince XML, , .Net.

, . Google Tech Talk . , Google Google. Acid2.

HTML PDF $3800 , . , , - , , , . .

+1

pd4ml . , .

html-/, pd4ml: http://pd4ml.com/html.htm

0

ActivePDF 375 . , .

http://www.activepdf.com/products/serverproducts/webgrabber/index.cfm

EDIT : Nevermind, it depends on another product that costs $ 1,400. I thought it would be cheaper than some other offers. A few more minutes of research came to the following options:

Up to $ 500:

http://www.websupergoo.com/abcpdf-1.htm (you'll need a professional edition to get as much formatting as possible).

0
source

Source: https://habr.com/ru/post/1706144/


All Articles