We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

HTML string to PDF does not apply CSS styling

I'm following this sample to generate a PDF file from an HTML string: https://ej2.syncfusion.com/aspnetmvc/PDF/HTMLtoPDF#/material, however no styles are applied and it should have at least the basic bootstrap layout styling.

I have a partial view with its own bootstrap reference which renders well when loaded on the browser (on its own). I'm taking this partial view and pre-rendering it to an HTML string which includes the external CSS files. I've tried with local stylesheet, CDN and even putting the specific styles inline with a style tag but not even the basic bootstrap column styles are applied. This is how my HTML converter looks like with a sample HTML string:

string htmlStr = "
Column 1
Column 2

   HtmlConverter htmlConv = new HtmlConverter
                EnableJavaScript = true,
                AutoDetectPageBreak = true,
                EnableHyperlinks = true,
            HtmlToPdfResult result = htmlConv.Convert(htmlStr, string.Empty, ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);

3 Replies

PV Prakash Viswanathan Syncfusion Team May 6, 2019 07:21 AM UTC

Hi Juan Jiminez, 

Thank you for contacting Syncfusion support. 

The sample from this page is using IE rendering engine for converting HTML to PDF, we can specify the base URL when converting HTML string to PDF. Please make sure the HTML string is displayed properly in IE browser by saving it as a HTML file. Also, try the conversion with file URL to PDF instead of HTML string, so that you can compare the PDF document with input HTML file in IE browser.  
Please refer below links for more details, 

Syncfusion provides HTML to PDF conversion support using WebKit, Blink and IE rendering engine, please refer below links for comparing the rendering engines. Kindly try the WebKit/Blink rendering engines which supports many features and it will generated PDF documents as like how the HTML file is displayed in web browsers.  

If you are using IE rendering engine for any specific reason, please provide more details such as complete code snippet, input HTML string, output PDF document etc, to reproduce the issue in our end. So that it will helpful for us to analyze and assist you further on this.  

Prakash V 

JJ Juan Jiminez May 6, 2019 05:28 PM UTC

Webkit converter is way better. Thanks for pointing me in the right direction. 

PV Prakash Viswanathan Syncfusion Team May 7, 2019 04:53 AM UTC

Hi Juan Jiminez, 
Thank you for your update.  
Please let us know if you need any further assistance on this.  
Prakash V 

Live Chat Icon For mobile
Up arrow icon