Click here to Skip to main content
11,578,241 members (65,396 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# .NET VB.NET
hi every one
how i can convert html to pdf
by .net code
without any external library
thanks for any help
<b></b>
Posted 5-May-11 12:30pm
Comments
Mohibur Rashid at 9-Nov-12 3:06am
   
You are already reported by two user. Don't do stupidity like this.
Rate this: bad
good
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
  Permalink  
Comments
orc_orc_orc at 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; http://www.codeproject.com/KB/aspnet/HTML2PDF.aspx
Rate this: bad
good
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 http://www.adobe.com/devnet/pdf/pdf_reference_archive.html. It will give you all the information you need for the PDF format.
  Permalink  
Comments
mostafa.elsadany at 6-May-11 0:49am
   
asp.ent working
Rate this: bad
good
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 .......
  Permalink  
Comments
aspnet_regiis -i at 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 at 12-Nov-12 4:46am
   
No third party tools , as the question says
Rate this: bad
good
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.........
  Permalink  
Rate this: bad
good
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));
        document.Open();
        //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++)
        {
            document.Add((IElement)htmlarraylist[k]);
        }
 
        document.Close();
        WebClient myWeb = new WebClient();
        Byte[] myBuff = myWeb.DownloadData(filename);
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", myBuff.Length.ToString());
        Response.BinaryWrite(myBuff);
        Response.Flush();
        Response.Close();
 
  Permalink  
Comments
aspnet_regiis -i at 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
0 Richard MacCutchan 165
1 OriginalGriff 150
2 Peter Leow 150
3 Afzaal Ahmad Zeeshan 100
4 Frankie-C 75
0 OriginalGriff 880
1 Sergey Alexandrovich Kryukov 685
2 Abhinav S 573
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 393


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 22 May 2015
Copyright © CodeProject, 1999-2015
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