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 ?
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 ?
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.
You could give HTML2PDF a try. I haven't tried it myself though.
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.
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.
This shows an excellent example from CodeProject:
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.
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
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.
This component names PDF Vision .Net, it can convert HTML to PDF:
Link to download: http://www.sautinsoft.com/components/pdf_vision_net.zip
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.
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}";
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?
I used ExpertPDF Html To Pdf Converter. Does a decent job. Unfortunatelly, it's not free.
There's also a new web-based document generation app - DocRaptor.com. Seems easy to use, and there's a free option.