views:

126

answers:

3

Hello Everyone,

i m using asp.net mvc2 for my application. i have a view that accepts a model and renders its data in some format. i want this page to be converted into pdf file so it can be sent via attachment or created and downloaded on the fly. i have some success creating pdf with itextsharp library but they say it has very basic support for html and css. if anyone has rendered complex html pages to pdf using itextsharp or any other library plz help me in solving this problem. any comments are highly appreciated

thanks

A: 

Although not free, you may want to look at the PDF Conversion Services. The latest beta supports HTML conversion with great precision.

Have a look at this post, it works well with .net and java based environments.

I worked on this product so the usual disclaimers apply. Happy to answer any questions.

Muhimbi
@Muhimbi i appriciate ur reply but i m more inclined towards an open source solution
Muhammad Adeel Zahid
A: 

You could also look into using http://itextpdf.com/ which offers html to pdf conversion.

"iText can convert an XML or an HTML file to PDF, but only on a very basic level. Converting documents from one format to another is outside the scope of iText. And no: iText does not convert Word documents to PDF!"

BuildStarted
@BuildStarted thanks for assistance, i have tried itextsharp but it does not fulfill my requirements and yes its indeed very basic
Muhammad Adeel Zahid
+1  A: 

I think this related question will help to a degree. Just note that HTML displays and PDF documents serve to different purposes as described here. The basic thought is that the latter "is designed for print output", and the other "is designed for video display".

My suggestion is that in most cases when one prints from the web, there is an option to create a separate stylesheet for printing using this declaration. The idea is to dumb down the styling and make it more print friendly (=less complex).

The following article from A List Apart provides some further insight into this option.

<link rel="stylesheet" type="text/css" media="print" href="print.css" /> 

The other free PDF library to look at is PDFSharp. However, they do not support conversion from HTML to PDF.

Other related SO questions

Ahmad