Click here to Skip to main content
12,691,948 members (29,554 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ C# VB .NET VB.NET
hi every one
how i can convert html to pdf
by .net code
without any external library
thanks for any help
Posted 5-May-11 13:30pm
Mohibur Rashid 9-Nov-12 3:06am
You are already reported by two user. Don't do stupidity like this.
Easked 9-Dec-15 4:20am
You cannot achieve this without some external library, .NET framework does not provide any means with which you can create a PDF file through C# code.
That is why I used an external Word library for .NET, it can directly convert input HTML to output PDF with C#.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

have a read of this msdn social thread, it gives a list of open source converters

How to Convert HTML to PDF[^]

sadly there is no built in methods to do what your after
orc_orc_orc 5-May-11 19:51pm
In addition to Simon's answer you can pick one of the tools that you find and write a wrapper around that in C#. Here is an example how you can do this;
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The easiest method is to use an external library, but if you really can't do that then you probable need to start with PDF Reference, Sixth Edition, version 1.7. It is a wonderful read at just over 1300 pages and you can find it at It will give you all the information you need for the PDF format.
mostafa.elsadany 6-May-11 0:49am
asp.ent working
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

I think without library you can not convert html to pdf you can use itextsharp library for the same .......
aspnet_regiis -i 12-Nov-12 4:44am
No need to answer the question that are too old.The user must have found answer by now
aspnet_regiis -i 12-Nov-12 4:46am
No third party tools , as the question says
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

You dont want to use external library then read reference build one as s_magus2K suggested.

Or you can install a virtual pdf printer and through api you can print your desired data into pdf file and save in proper place and then redirect to download.........
Rate this: bad
Please Sign up or sign in to vote.

Solution 7

Hi ,

This sample will help you.

        //saving HTML as PDF locally and then opening 

        Document document = new Document();
        string filename = Path.GetTempPath() + "MyFiles.pdf";
        StringBuilder strSelectUserListBuilder = new StringBuilder();
       // strSelectUserListBuilder.Append("<table border="2" width="300" cellspacing="1" cellpadding="1" bgcolor="#DD00AA"><tr rowspan="2"><td>TEST1</td><td rowspan="2">TEST2</td></tr><tr><td>TEST3</td><td>TEST4</td></tr><tr><td>TEST5</td><td>TEST6</td></tr></table>");
        strSelectUserListBuilder.Append("<h1>This is my test PDF sample</h1><table border="1" bgcolor="#CCCE0E">  <tr> <td colspan="2">my  table</td> </tr> <tr> <td>my  table</td> <td>my  table</td> </tr>   <tr> <td>200</td> <td>100</td> </tr> <tr> <td>500</td> <td>100</td> </tr> <tr> <td>700</td> <td>500</td> </tr></table>");
        //writer - have our own path!!! and see you have write permissions...
        PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
        //Here is where your HTML source goes................
        String htmlText = strSelectUserListBuilder.ToString();
        //make an arraylist ....with STRINGREADER since its no IO reading file...

        ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null);
        //add the collection to the document

        for (int k = 0; k < htmlarraylist.Count; k++)

        WebClient myWeb = new WebClient();
        Byte[] myBuff = myWeb.DownloadData(filename);
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", myBuff.Length.ToString());

aspnet_regiis -i 12-Nov-12 4:44am
No third party tools please..

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170117.1 | Last Updated 22 May 2015
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100