Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my MVC.net (C#) application, I am creating creating reports at client side using JQplot. The report generate is placed inside a placeholder on the page ('div' element).
My requirement says that I need to create a PDF having all the data of my page, for-example the page (HTML) may have report description in text and the report. All this HTML need to go in PDF file.

In brief : Entire HTML has to be written in PDF file.

How this can be done?
Posted

1 solution

myHTMLTable.Border = 1;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=ReportName.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

//lblReportName.Visible = true;
hw.WriteLine("Header Text"); // add header to pdf file


pnlPerson.RenderControl(hw); ///pnlPerson is panel inside that your HTML table will come
StringReader sr = new StringReader(sw.ToString());

Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 5f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

For this you have to use 3rd party tool iTextSharp>
May this will help
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900