在ASP.NET中将HTML转换为PDF时,请保持CSS样式

问题描述:

我使用ITextSharp将HTML页面转换为PDF。

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

但是,ITextSharp直接在STYLE声明中打印CSS,即使在编程添加时也忽略样式表,只有一些内联样式(例如字体大小和颜色,而不是背景颜色)。

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

有一些我缺少的ITextSharp,

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

提前感谢,

看看WKHTMLTOPDF。它是开源的,基于webkit和免费。

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

我们写了一个小教程此处