2
votes

I have converted an HTML sting into a PDF document using iTextSharp in VB.Net; however, the style tags are not being applied to the PDF document. The HTML string is supplied by an outside source so I need to pull the styles elements out and apply them to the generated PDF. The nested classes in the CSS elements are fouling things up. What is the best way to handle the nested CSS classes?

2
You should post some code showing what you tried. - kuujinbo
Is still alive this discussion? I have the same question. I've using itextsharp 5.X and the only way is adding one by one the styles like this: <br/> <br/> HtmlMovies2 movies = new HtmlMovies2(); St yleSheet styles = new StyleSheet(); styles.loadTagStyle("ul", "indent", "10"); styles.loadStyle("country", "color", "#008080"); styles.loadStyle("director", "b", ""); movies.setStyles(styles); <br/> Is it possible to add an entire css stylesheet to the document? - rolivares

2 Answers

2
votes

I had a similar issue. iTextSharp is appropriate for WEB to PDF with very simple styling. If you want to convert an entire site to PDF and have it look exactly like the site you should use a library like EO.PDF. Just 2 lines of code and you are done.

0
votes

The EO.PDF product line was created for this exactly. Here's most of the VB.NET you would need:

Imports System.Drawing

'This is usually the only namespace needed if you only use HTML to PDF
Imports EO.Pdf

'This is the main namespace you will need in order to use ACM (Abstract Content Model)
Imports EO.Pdf.Acm

'The following two namespaces are only needed if you use low-level content API
Imports EO.Pdf.Drawing

Imports EO.Pdf.Contents

'Convert a Url to PDF file
HtmlToPdf.ConvertUrl("http://www.google.com", "c:\test.pdf")