user1272566
user1272566

Reputation: 31

iTextSharp HTML to PDF Conversion

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?

Upvotes: 2

Views: 1633

Answers (2)

DanM7
DanM7

Reputation: 2246

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")

Upvotes: 0

nicholmikey
nicholmikey

Reputation: 358

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.

Upvotes: 2

Related Questions