How To Convert Html Page To Pdf With Css Using Itextsharp?
This is my code : Response.ContentType = 'application/pdf'; Response.AddHeader('content-disposition', 'attachment;filename=TestPage.pdf'); Response.Cache.SetCacheability(HttpCache
Solution 1:
I don't know if this is the answer, but I found that iTextSharp is picky about having valid html. My tests had a table that was opened twice and never closed and that took about an hour for me to notice. The exception was very similar to the one you have there.
Solution 2:
use can you A4 size width & height for html deigning .
Solution 3:
use this set od code to create pdf from html.
String htmlText = "<div>Your HTML text here</div>";
Documentdocument = newDocument();
PdfWriter.GetInstance(document, newFileStream(Request.PhysicalApplicationPath + "\\outfile.pdf", FileMode.Create));
document.Open();
iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
hw.Parse(newStringReader(htmlText));
document.Close();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "inline;filename=outfile.pdf");
Response.ContentType = "application/pdf";
Response.WriteFile(Request.PhysicalApplicationPath + "\\outfile.pdf");
Response.Flush();
Response.Clear();
Post a Comment for "How To Convert Html Page To Pdf With Css Using Itextsharp?"