1

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?

4
  • i didb't get your point... whether you want create pdf with html tags like <h1>Hi</h1> or just you want print only 'Hi' even you has pass with tags Commented Oct 10, 2014 at 11:28
  • I dont want to print <h1><b>Hi<b></h1> I want to print Hi in bold as it would appear on a webpage. Commented Oct 10, 2014 at 11:39
  • It is easy to format in html. Commented Oct 10, 2014 at 11:40
  • What you are looking for is called XMLWorker, you'll find more information at nuget.org/packages/itextsharp.xmlworker and sourceforge.net/projects/itextsharp/files/xmlworker Commented Oct 10, 2014 at 11:52

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.