简体   繁体   中英

Create a PDF using iTextSharp from HTML page with external CSS in a Web Service

I have a js file that call a webservice to create a pdf of an html page I have. I'm using iTextSharp library for that, and I pass the html string as parameter of the web service to create it's pdf, but I want to keep the design. How can I do that. I have seen a lot of tutorial a try to implement the code without success.

AFAIK iTextSharp does not have an HTML layout engine (which is what you'll need to keep your design intact).

If your layout is simple then A Google search of "HTML to Pdf .NET component" will yield tons of results.

Our ActivePDF WebGrabber product will do that for you, but it might be overkill for a simple web service with low volume.

Thanks to all. I already made some tricks to keep design of html when created pdf in server side with iTextSharp. I add manually some clases to the css resolver just like this:

StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(); cssResolver.AddCssFile(Context.Server.MapPath("/Content/FOUNDATION/css/PDF.css"), true); cssResolver.AddCss(".fontSizeTb table, td {font-size: 12px; }", true); cssResolver.AddCss(".ChangeH3 {font-size: 16px; padding-top: 20px; margin-top: 20px; vertical-align: bottom;}", true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM