Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
hi every one
how i can convert html to pdf
by .net code
without any external library
thanks for any help
<b></b>
Posted
Updated 24-Jan-18 18:10pm
Comments
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#.
adriancs 18-Aug-18 9:13am    
.NET framework does not has build-in function for doing this. Which ends up you need en external library.
adriancs 18-Aug-18 9:14am    
http://bfy.tw/7zxf

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
 
Share this answer
 
Comments
Orcun Iyigun 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
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.
 
Share this answer
 
Comments
Mostafa Elsadany 6-May-11 0:49am    
asp.ent working
Quyền Trịnh 22-Sep-17 5:59am    
123123123
I think without library you can not convert html to pdf you can use itextsharp library for the same .......
 
Share this answer
 
Comments
bbirajdar 12-Nov-12 4:44am    
No need to answer the question that are too old.The user must have found answer by now
bbirajdar 12-Nov-12 4:46am    
No third party tools , as the question says
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.........
 
Share this answer
 
Hi ,

This sample will help you.


C#
 //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();
 
Share this answer
 
Comments
bbirajdar 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900