Render PDF to iTextSharp from HTML with CSS

Any idea how to make PDF using iTextSharp so that it renders the page using CSS. Css can be embedded in HTML or passed separately, I donโ€™t care, I just want it to work.

Specific code examples will be especially appreciated.

In addition, I would really like to stick with iTextSharp, although if you have suggestions for something else, it should be free, open source and have a license that allows you to use it in commercial software.

+20
html c # pdf itextsharp
Jan 10 '09 at 0:45
source share
3 answers

This is not possible now, but nothing is stopping you from starting an open source project that will do it. I could start it because I need it too!

Basically, you'll need a parser that converts html and css markup to iTextSharp classes. So <table> becames iTextSharp.SimpleTable etc.

It would be easy to create a prototype that could work with a limited subset of html and css.

Update: As long as this is possible, I temporarily allowed this for myself. Only two steps:

  • Tell your users to download an open source application called PDFCreator
  • Make all your friendly html reports printable by providing print stylesheets. A.

    If some of your multi-page reports have headers on each page, set them in the THEAD html tag.

Now users can print, and if they choose the PDFCreator printer driver, they can even receive a report in PDF format (there are other PDF file drivers, but this is free and open source).

I also know that HTML is not as flexible as PDF, but it can be good enough. I did some tests with real users, and they really like it, because not only can they print anything in PDF format now (even outside my application), but their workflow is faster because they donโ€™t have to download and wait until their PDF reader opens up. they just print (or export to pdf) what they see on the website, directly from their web browser ... something makes sense.

+8
Jan 10 '09 at 4:21
source share

Try WKHTMLTOPDF.

This is an open source webkit implementation. Both are free.

We set up a little tutorial here

+6
Aug 31 '09 at 13:47
source share
  List<DateTime[]> getListWeeks(int annee) { List<DateTime[]> weeks = new List<DateTime[]>(); DateTime beginDate = new DateTime(annee, 1, 1); DateTime endDate = new DateTime(annee, 12, 31); int nb =(int)beginDate.DayOfWeek; DateTime monday = beginDate.AddDays(-nb+1); ; DateTime saturday = monday.AddDays(6); while (monday < endDate) { weeks.Add(new DateTime[] { monday, saturday }); monday = monday.AddDays(7); saturday = monday.AddDays(6); } return weeks; } 
+2
Dec 22 '15 at 12:19
source share



All Articles