Click here to Skip to main content
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 5

Saaspose.PDF use .net language to convert html to pdf you can try using that converter and its web-based so you can convert your document online no need to download it.
  Permalink  
Comments
aspnet_regiis -i at 12-Nov-12 4:45am
   
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..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

Below solution uses three lines of key code via a Spire.PDF, it can convert html, aspx, htm webpage to PDF.
C#:
[STAThread] 
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            String url = "http://www.london2012.com/news/articles/paralympic-torch-relay-route-revealed-1258473.html";
            doc.LoadFromHTML(url, false, true, true);
            //Save pdf file.
            doc.SaveToFile("sample.pdf");
            doc.Close();
        }
 
VB.NET:
<STAThread> _
    Private Shared Sub Main(args As String())
        'Create a pdf document.
        Dim doc As New PdfDocument()
        Dim url As [String] = "http://www.london2012.com/news/articles/paralympic-torch-relay-route-revealed-1258473.html"
        doc.LoadFromHTML(url, False, True, True)
        'Save pdf file.
        doc.SaveToFile("sample.pdf")
        doc.Close()
    End Sub
  Permalink  
Comments
aspnet_regiis -i at 12-Nov-12 4:45am
   
No third party tools , as the question says
Harishankar maurya at 14-Jun-13 4:16am
   
how to convert a invoice of html(webpage) into pdf

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

  Print Answers RSS
0 CPallini 365
1 Sergey Alexandrovich Kryukov 317
2 OriginalGriff 165
3 George Jonsson 159
4 Abdul Samad KP 125
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,860
2 CPallini 5,125
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 30 Sep 2013
Copyright © CodeProject, 1999-2014
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