Monday, March 5, 2012

Export HTML to Image or PDF

Export HTML to Image or PDF

A few days back one of my friend asked to me How can we export HTML page into Pdf.
We searched a lot there are a large number of thired party tools are available to do this but these
all tools are paid. So we cant buy a tool and because it also include Html reandring engine code so its
not easy to create a tool for project its time consuming task.

As i told you above we are not able to export HTML to Pdf we used a differnt approach to resolve it.
We planned to convert HTML to Image and then write down this image into Pdf and it working for us.

Now i am going to explain it Step by Step:

1. Get reference of System.UI.Form , System.Drawing
2. Create object of WebBrowser
3. On Completed event

    a) Create Bitmap object and specify size of Bitmap
    b) Convert WebBrowser to Control and then use DrawToImage()
    c) Save Bitmap to jpg file.
   
4. Add Reference of iTextSharp
5. Create a Object of Document
6. Create a Object of PdfWriter
7. Add Image to PdfWriter using PdfWriter.Add();
8. Close PdfWriter and Document Object.

Happy Living...
Happy Coding...
Happy Concepts...




No comments:

Post a Comment