Maintain CSS Styling When Converting HTML to PDF in ASP.NET

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

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

We wrote a small tutorial here.

ASP.Net to PDF conversion

Having worked with iText's old HTML->PDF code, I can suggest that you:

  1. Accept more answers to your questions. :P
  2. Don't do that. iText's HTML->PDF converter is acceptable, but its CSS support is still spotty. The new XMLWorker is an improvement, but there's still Much Better Options available to you.

I've been a committer on iText for a couple years now. HTML->PDF conversion is not its strength. Getting better, still a long way to go.

In particular, I'm quite happy with the results from WKHTML2PDF. I was able to render an HTML page with a GOOGLE MAP to PDF. You won't find that anywhere else (other than a browser's theoretical "current page to PDF" function, which I haven't heard of as yet).

Convert HTML content to Pdf using c# and asp.net

Try to replace width='200px' with width='200' it should work. Remove px from every places with width.

Open Source HTML to PDF Renderer with Full CSS Support

I've always used it on the command line and not as a library, but HTMLDOC gives me excellent results, and it handles at least some CSS (I couldn't easily see how much).

Here's a sample command line

htmldoc --webpage -t pdf --size letter --fontsize 10pt index.html > index.pdf

Convert html tagged text to string for a pdf itext7

I created "Hello World" here and used bold, italic and underline. Copy the source code via "Tools" and just use the following code to convert it via iText7:

String htmlString = "<p><span style=\"text-decoration: underline;\"><em><strong>Hello World</strong></em></span></p>";
HtmlConverter.convertToPdf(htmlString, new PdfWriter(destinationFolder + "test.pdf"));

The resultanting PDF:

Sample Image



Related Topics



Leave a reply



Submit