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 LowePosted May 20, 2015, 4:34 AM
Atir TahirPosted Nov 28, 2019, 5:57 AM
Tony ChenPosted Oct 27, 2018, 4:27 AM
SERGE FLOYDPosted Jul 19, 2018, 11:15 AM
I would recommend to check https://zetpdf.com/ library
rajendra singhPosted Nov 3, 2017, 7:58 AM
Pratik ShirsePosted Oct 25, 2017, 1:18 AM
Ali Jago SeifPosted Oct 24, 2017, 12:19 PM
Why you don’t try this code with easyPDF library (http://www.pdfonline.com/html-to-pdf-c%23/)?
Shalini DixitPosted Jun 29, 2015, 7:27 AM
Amit ShrivastavaPosted May 25, 2015, 8:13 AM
Baraa MomaniPosted Apr 7, 2015, 8:07 AM
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
SelectPdfPosted Feb 20, 2015, 9:16 AM
I can recommend a free html to pdf converter: http://selectpdf.com/community-edition/
shi lianghongPosted Feb 3, 2015, 3:05 AM
http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-Customize-HTML-to-PDF-Conversion-by-Yourself.html