Skip to content

Instantly share code, notes, and snippets.

@ekaraman89
Last active February 20, 2020 07:54
Show Gist options
  • Save ekaraman89/2352adc7eeb14ec1dfc2297ac206bc6d to your computer and use it in GitHub Desktop.
Save ekaraman89/2352adc7eeb14ec1dfc2297ac206bc6d to your computer and use it in GitHub Desktop.
// 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