I am trying to export retrieved data from SQL into PDF using ASP.NET (C#). Remarks:
How can I convert an HTML table to PDF using ASP.NET?
Can anyone help me? Thanks.
You can try to use itextsharp (link)
Example:
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using iTextSharp.text.html;
// step 1 -- get html content
string htmlContent = ... // you html code (for example table from your page)
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.GetInstance(document, new FileStream("c:\\Chap0101.pdf", FileMode.Create));
// step 3: we open the document
document.Open();
// step 4: we add a paragraph to the document
//document.Add(new Paragraph(htmlContent.ToString()));
System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(new StringReader(htmlContent));
HtmlParser.Parse(document, _xmlr);
// step 5: we close the document
document.Close();