Skip to content

Instantly share code, notes, and snippets.

@ekaraman89
Last active Feb 20, 2020
Embed
What would you like to do?
// Install-Package iTextSharp -Version 5.5.10
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
private void printHtmlToPdf(string html)
{
StringReader sr = new StringReader(html);
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Siparis.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment