Maintain CSS styling when converting HTML to PDF in ASP.NET

I am using ITextSharp to convert an HTML page to PDF.

However, ITextSharp prints the CSS in the STYLE declaration straight out, ignores stylesheets even when added programmatically and only listens to some inline styles (e.g. font-size and color but not background-color).

Is there something I am missing with ITextSharp, or is there a better (and free) way of doing this conversion?

Thanks in advance,


Have a look at WKHTMLTOPDF. It is open source, based on webkit and free.

We wrote a small tutorial here.

HTML / CSS support in iText / iTextSharp is very basic. It's just not the right tool to convert html to pdf. Take a look at these solutions instead:

These render html to an image. Then you can insert them in your PDF with iTextSharp.

Otherwise you could try converting HTML -> XSL-FO -> PDF, but including CSS there is a whole other thing.

Try PDF Duo .NET converter. You can apply for support if you need a special feature.

ABCpdf provides two HTML rendering engines. One is based around the MSHTML version installed on the system. The other is based around the FireFox Gecko rendering engine.

So there's plenty of room for manouver if you want a particular set of features. It's very real world.

In terms of quality I would just say that we do get a lot of people settling on ABCpdf after trying a lot of different alternatives.

I work on the ABCpdf .NET software component so my replies may feature concepts based around ABCpdf. It's just what I know. :-)

Why not use online API? There are plenty of them available and they do the work well, which let you worry about your core work, not how to render a PDF correctly :)

You mention something "free". It depends on your usage, but most services offer free conversions to start with, ranging from 50 to 250 (and even more). Maybe it would be enough for you?

All you'd have to do then is a basic POST request to the service with your HTML data (or link), and you'll get a PDF in response.

Here are a list of API to convert HTML to PDF (not exhaustive):

Need Your Help

SQL table change distribution

c# winforms visual-studio-2008 software-distribution sql-server-2008-express

I have a WinForm application built with VS 2008 (C#) and SQL Server Express 2008 that is currently deployed on test users PC.

Which is the suitable javascript framework to develop Single page application with php as backend?

javascript php web-applications single-page-application

We want to create a single page application with php as backend language. Which javascript framework would be a suitable one to develop this?