-1

I want to convert a static html file to pdf file with the styles as it is. I have only a few fields in html , Like text,select,textarea,button,label ( but all contains inline styles) I have checked itextsharp, which is converting to pdf with no styles.

Can I generate the pdf as I see the html file in browser

I am using c# win-form application to do that.

Xavi López
  • 27,550
  • 11
  • 97
  • 161
D J
  • 963
  • 2
  • 14
  • 22
  • Take a look at [wkhtmtopdf](http://code.google.com/p/wkhtmltopdf/). Also, possible duplicate of [Convert HTML to PDF in .NET](http://stackoverflow.com/questions/564650/convert-html-to-pdf-in-net) – Xavi López Sep 19 '12 at 13:07
  • i have updated my answer have a look – iJade Sep 19 '12 at 13:20
  • possible duplicate of [C# HTML to PDF code for use in a service (on a server)](http://stackoverflow.com/questions/12058560/c-sharp-html-to-pdf-code-for-use-in-a-service-on-a-server) – yms Sep 19 '12 at 13:58

3 Answers3

1

Generating pdf from html page using http://www.html-to-pdf.net/ First download dll from site and refer it in ur code...i have written rest of the code below, have a look.

 PdfConverter pdfConverter = new PdfConverter();
            //pdfConverter.LicenseKey = "put your license key here";

            pdfConverter.PdfDocumentOptions.EmbedFonts = false;
            pdfConverter.PdfDocumentOptions.ShowFooter = false;
            pdfConverter.PdfDocumentOptions.ShowHeader = false;
            pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;
            pdfConverter.ActiveXEnabled = true;
            pdfConverter.AvoidImageBreak = true;
            pdfConverter.NavigationTimeout = 2147483647;

            pdfConverter.ScriptsEnabled = true;
            pdfConverter.PdfDocumentOptions.AutoSizePdfPage = true;
            pdfConverter.SavePdfFromUrlToFile(html file path, output file path filepath);
iJade
  • 23,144
  • 56
  • 154
  • 243
0

I use WKHtmlToPdf a shell utility which is based on the standard WebKit engine. Give it a try.

Dummy01
  • 1,985
  • 1
  • 16
  • 21
0

Amyuni WebkitPDF is a free library that can be used for HTML to PDF conversion. It comes with sample code in C# and C++ and a sample desktop application that you can use for evaluating the results.

usual disclaimer applies

yms
  • 10,361
  • 3
  • 38
  • 68