tags:

views:

14159

answers:

19

I want to generate PDF by passing HTML contents to a function. I have made use of ItextSharp for this but it does not perform well when it encounters Table and the layout just gets messy.

Is there any free library available ?

+1  A: 

It depends on any other requirements you have.

A really simple but not easily deployable solution is to use a WebBrowser control to load the Html and then using the Print method printing to a locally installed PDF printer. There are several free PDF printers available and the WebBrowser control is a part of the .Net framework.

EDIT: If you Html is XHtml you can use PDFizer to do the job.

Rune Grimstad
+1  A: 

You could give HTML2PDF a try. I haven't tried it myself though.

Adrian Grigore
+3  A: 

Winnovative offer a .Net PDF library that supports HTML input. They offer an unlimited free trial. Depending on how you wish to deploy your project, this might be sufficient.

Stewart
+2  A: 

If you don't really need a true .Net PDF library, there are numerous free HTML to PDF tools, many of which can run from a command-line.

One solution would be to pick one of those and then write a thin wrapper around that in C#. E.g., as done in this tutorial.

Stewart
A: 

This shows an excellent example from CodeProject:

http://www.codeproject.com/KB/showcase/TallComponents.aspx

+1  A: 

Free code at Code Project

http://www.codeproject.com/KB/cs/Easy_PDF_Programming.aspx

Josh
+1  A: 

I was also looking for this a while back. I ran into HTMLDOC http://www.easysw.com/htmldoc/ which is a free open source command line app that takes an HTML file as an argument and spits out a PDF from it. It's worked for me pretty well for my side project, but it all depends on what you actually need.

The company that makes it sells the compiled binaries, but you are free to download and compile from source and use it for free. I managed to compile a pretty recent revision (for version 1.9) and I intend on releasing a binary installer for it in a few days, so if you're interested I can provide a link to it as soon as I post it.

enriquein
hi, can u provide a link and also a guide on how to use it with c# asp.net thanks
http://static.persistedthoughts.com/htmldoc_1.9.1586-setup.exeBe aware that this is a command line program. You have to execute it from within your application to get it to work. You can find the documentation for its arguments and caveats from Chapter 4 on: http://www.easysw.com/htmldoc/documentation.php
enriquein
A: 

Try this PDF Duo .Net converting component for converting HTML to PDF from ASP.NET application without using additional dlls.

You can pass the HTML string or file, or stream to generate the PDF. Use the code below (Example C#):

string file_html = @"K:\hdoc.html";   
string file_pdf = @"K:\new.pdf";   
try   
{   
    DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf();   
    conv.OpenHTML(file_html);   
    conv.SavePDF(file_pdf);   
    textBox4.Text = "C# Example: Converting succeeded";   
}   

Info + C#/VB examples you can find at: http://www.duodimension.com/html_pdf_asp.net/component_html_pdf.aspx

Constantine
+1  A: 

Ok, using this technologies....

The src can be downloaded from here it needs nant

jjchiw
+9  A: 

Try wkhtmtopdf. It is the best tool I have found so far.

marko
This tool is excellent! The use of the webkit engine is far superior to alternatives using IE.
Josiah
supports .NET ??
alhambraeidos
+4  A: 

To convert HTML to PDF in C# use ABCpdf.

ABCpdf makes use of Microsoft XML Core Services (MSXML) so your HTML table will render the same as it appears in Internet Explorer.

There's an on-line demo of ABCpdf at www.abcpdfeditor.com. You could use this to check out how your tables will render first, without needing to download and install software.

For rendering entire web pages you'll need the AddImageUrl or AddImageHtml functions. But if all you want to do is simply add HTML styled text then you could try the AddHtml function, as below:

Doc theDoc = new Doc();
theDoc.FontSize = 72;
theDoc.AddHtml("<b>Some HTML styled text</b>");
theDoc.Save(Server.MapPath("docaddhtml.pdf"));
theDoc.Clear();

ABCpdf is a commercial software title, however the standard edition can often be obtained for free under special offer.

AffineMesh94464
You should really write in all your answers that you work for websupergoo. From the faq: `However, you must disclose your affiliation with the product in your answers. Also, if a huge percentage of your posts include a mention of your product, you're clearly here for the wrong reasons.` **All your answers have been about ABCpdf**
jgauffin
A: 

Web2PDFConvert has web API.

Tomas
A: 

This component names PDF Vision .Net, it can convert HTML to PDF:

  • Any URL or ASPX page to PDF
  • HTML to PDF
  • Split/Merge PDF
  • TIFF to PDF

Link to download: http://www.sautinsoft.com/components/pdf_vision_net.zip

Maximus
A: 

PDF Vision is good. However, you have to have Full Trust to use it. I already emailed and asked why my HTML wasn't being converted on the server but it worked fine on localhost.

Mike
A: 

The PDF Metamorphosis .Net can convert HTML to PDF at server-side in C#, VB.Net, ColdFusion.

For example if you want to convert HTML string to PDF on fly:

SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
byte[] pdf = p.HtmlToPdfConvertStringToByte("<b>Sample header in HTML format</b>");
//next show pdf to user
    if (pdf != null)
    {
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = "application/PDF";
        Response.BinaryWrite(pdf);
        Response.Flush();
        Response.End();
    }

Also you may add page numbers, specify header/footer and even merge PDF documents:

 //specify some options
 p.PageStyle.PageOrientation.Landscape();
 //specify header in HTML format
 p.Header.Html("<b>Sample header in HTML format</b>");

 //specify footer in RTF format
 p.Footer.Rtf("{\b Bold footer}");

 //specify page numbers
 p.PageStyle.PageNumFormat = "Page {page} of {numpages}";
Maximus
nice product, hardly free...
SomeMiscGuy
A: 

I am using winnovatives Html to PDF tool. In my web page I need to rotate a div and I used -webkit-transform to do that. In output the PDF fails to produce the required result. Are there any tools which support the transform feature of webkit?

Hasan
A: 

I used ExpertPDF Html To Pdf Converter. Does a decent job. Unfortunatelly, it's not free.

Flores
A: 

Found this open source solution. Looks promising!

PDFsharp

peace | dewde

dewde
A: 

There's also a new web-based document generation app - DocRaptor.com. Seems easy to use, and there's a free option.

Paul