Hi,
how can i convert html template to pdf file in c# windows application
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
using (StreamReader sr= new StreamReader(Server.MapPath("~/EmailTemplate.htm")))
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Add(pdfTable);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=HTMLExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
Loading


Kimberlee Lowe30 reputationPosted May 20, 2015, 12:34 AM EDT
shi lianghong48 reputationPosted Feb 2, 2015, 10:05 PM EST
http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-Customize-HTML-to-PDF-Conversion-by-Yourself.html
SelectPdf14 reputationPosted Feb 20, 2015, 4:16 AM EST
I can recommend a free html to pdf converter: http://selectpdf.com/community-edition/
Baraa Momani6 reputationPosted Apr 7, 2015, 4:07 AM EDT
First of all I think you will need to use an sdk to handle saving PDFs as they are not natively supported in .NET. About the PDF itself, the solution for this depends on whether you want the PDF to have full text and font information, or just a snapshot of the web page. By "snapshot" I mean converting the page to images that gets stored in the PDF, where the text is lost and not searchable. In my code, I used leadtools sdk for loading the html files and save them to PDF files that only contain snapshot of the rendered html page.
If you want full text, one way to do it is using a printer driver where your application uses a web browser control to invoke printing, then capture the print job using a printer driver such as leadtools virtual printer that supports capturing print jobs and saving them as PDFs that has all the objects from the original web page
Amit ShrivastavaRank #5,080 · 312 reputationPosted May 25, 2015, 4:13 AM EDT
Shalini Dixit6 reputationPosted Jun 29, 2015, 3:27 AM EDT
Ali Jago Seif23 reputationPosted Oct 24, 2017, 8:19 AM EDT
Why you don’t try this code with easyPDF library (http://www.pdfonline.com/html-to-pdf-c%23/)?
Pratik ShirseRank #3,199 · 449 reputationPosted Oct 24, 2017, 9:18 PM EDT
rajendra singhRank #1,521 · 1K reputationPosted Nov 3, 2017, 3:58 AM EDT
SERGE FLOYD12 reputationPosted Jul 19, 2018, 7:15 AM EDT
I would recommend to check https://zetpdf.com/ library
Tony Chen27 reputationPosted Oct 27, 2018, 12:27 AM EDT
Atir TahirRank #3,495 · 415 reputationPosted Nov 28, 2019, 12:57 AM EST