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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

HTML string to PDF does not apply CSS styling

Thread ID:

Created:

Updated:

Platform:

Replies:

144401 May 5,2019 02:00 AM UTC May 7,2019 04:53 AM UTC ASP.NET MVC - EJ 2 3
loading
Tags: PDF
Juan Jiminez
Asked On May 5, 2019 02:04 AM UTC

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


Prakash Viswanathan [Syncfusion]
Replied On 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.  

Regards, 
Prakash V 


Juan Jiminez
Replied On May 6, 2019 05:28 PM UTC

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

Prakash Viswanathan [Syncfusion]
Replied On 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.  
 
Regards, 
Prakash V 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon