简体   繁体   中英

How to convert HTML into PDF using iTextSharp in winform?

I want to convert HTML into PDF in windows form. I have come across many fabulous articles online such as these:

But they do not quite address my problem.

Is it possible that I can just pass a string of HTML and convert it into PDF in Winform?

For example :

string html = "<table><tr><td>Arbaaz</td><tr></table>"

Can I just pass this string to some iText method to create PDF?

Got the answer I was looking for here ..

Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\MySamplePDF.pdf", FileMode.Create));
document.Open();
iTextSharp.text.html.simpleparser.HTMLWorker hw = 
             new iTextSharp.text.html.simpleparser.HTMLWorker(document);
hw.Parse(new StringReader(htmlText));
document.Close();

https://stackoverflow.com/a/18378661/2064292

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