Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Generate pdf from following html string

HTML
<font face="" verdana="" size="" 2=""><span style=""> Accounting</span></font>
Posted
Updated 9-Nov-14 17:27pm
v2
Comments
[no name] 10-Nov-14 1:00am    
What do you mean to achieve here my friend. Please brief us.:)
Timir Patel 10-Nov-14 22:29pm    
I want to generate pdf from html string[like above specified statement] using iTextSharp.dll. But there is one problem that iTextsharp not inherit style specified with this tag. It inherit style of table, but not other tags. So I want to solve this issue.

1 solution

I have used PDFDuo-NET.dll (version 2.3) in my project which is very useful. First, you need to convert content of your ASPX to HTML and then converted that HTML content into a PDF file or another way which I use is to create a simple HTML string and then convert it.See below C# code:

C#
using System;
using System.Web;
using System.Web.UI;
using System.IO;
using DuoDimension;


public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string html = "<table width="240">" +
            "<tr style="background-color:#00AAFF"><td width="50%">Product</td><td width="25%">Quantity</td><td>Cost</td></tr>" +
            "<tr><td>Product Name 1</td><td>5</td><td>$100</td></tr>" +
            "<tr><td>Product Name 2</td><td>15</td><td>$300</td></tr>" +
            "<tr><td>Product Name 3</td><td>55</td><td>$500</td></tr>" +
            "</table>";
        string pdf = "pdf_file.pdf";
        DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf();
        conv.PageInfo.PageFormat = ePageFormat.A4;
        conv.PdfDocumentInfo.Title = "Generate PDF from HTML source";
        conv.Header = "<br>HTML table Example";
        try
        {
            conv.OpenHTML(html);
            conv.SavePDF(MapPath("~/Reports/") + pdf);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}</br>


See here http://www.duodimension.com/html_pdf_asp.net/Articles/pdfduo23_090815.html[^]

And here Generate PDF documents from a HTML page using ASP.NET[^]
 
Share this answer
 
v2
Comments
Timir Patel 10-Nov-14 22:26pm    
Thanx.. :)
[no name] 10-Nov-14 23:37pm    
Please accept and up vote it helped you :)
[no name] 19-Nov-14 6:38am    
You can check here also : http://www.codeproject.com/Tips/843671/Export-From-HTML-Table-Using-JQuery

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