PrintToPdfAsync not using external style sheets?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

PrintToPdfAsync not using external style sheets?

Postby jgodfrey » Wed Apr 04, 2018 4:30 pm

First, I was directed here when I asked this same question on StackOverflow. For reference, that's here:

https://stackoverflow.com/questions/496 ... yle-sheets

I'm using CefSharp (v63) to convert HTML-based reports (stored on the local file system) to PDF for portability via the PrintToPdfAsync method.

Generally, this works exactly as intended and produces a faithful copy of the rendered HTML in PDF format. However, if the original HTML document contains a reference to an external style sheet (also stored on the local file system), those styles are not reflected in the resulting PDF file.

Note, the rendered HTML is using the external style sheets as intended. That is, in the CefSharp browser, the results are rendered as expected. However, once exported, externally referenced styles do not get baked int the resulting PDF.

Specifically, I notice issues with basic table formatting in the PDF (incorrect margins, paddings, borders, ...).

If I instead put the externally referenced style content directly in the HTML document, the style info is correctly reflected in the final PDF.

I have experimented with the WPF and the OffScreen assemblies. Both seem to exhibit the same behavior.

Any input appreciated.
jgodfrey
Newbie
 
Posts: 3
Joined: Wed Apr 04, 2018 4:27 pm

Re: PrintToPdfAsync not using external style sheets?

Postby magreenblatt » Wed Apr 04, 2018 5:19 pm

How does it behave in Google Chrome at the same version when you print the document?
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: PrintToPdfAsync not using external style sheets?

Postby jgodfrey » Wed Apr 04, 2018 5:35 pm

magreenblatt wrote:How does it behave in Google Chrome at the same version when you print the document?

A few comments..

First, I've downloaded the CEF sample app to verify my findings (3.3239.1723.g071d1c1 which matches my installation). There, I see the same results that I originally reported.

As suggested, I also opened the document in Chrome. In that case, the document renders correctly in the browser window (same as my CefSharp-based app). When I open Chrome's print dialog, the rendered preview looks the same as my PDF output. That is, the styles contained in the external CSS references are not present in the preview rendering.

I'm not sure if you're looking for more than the above or not. If so, feel free to ask again.
jgodfrey
Newbie
 
Posts: 3
Joined: Wed Apr 04, 2018 4:27 pm

Re: PrintToPdfAsync not using external style sheets?

Postby magreenblatt » Wed Apr 04, 2018 5:54 pm

OK, so it sounds like it's behaving the same in Chrome. You can file a bug at https://crbug.com/new.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: PrintToPdfAsync not using external style sheets?

Postby jgodfrey » Wed Apr 04, 2018 6:14 pm

Thanks for the quick input. Knowing that this is a "chrome issue" and not just a "cefsharp issue" opened up a much wider search scope for me. Looking for similar issues related to Chrome, it sounds like the problem could be that my CSS doesn't contain any print-specific styling.

I'm not a web developer, so I'm stepping off the deep end here... However, some quick hacking with a print-specific CSS file has gotten me closer. Specifically, my tables now render fairly well in PDF, though I still don't see the background color changing on every-other row as I do in the browser-based rendering. I assume that's likely something in my hacked print CSS.

So, perhaps not a bug after all?
jgodfrey
Newbie
 
Posts: 3
Joined: Wed Apr 04, 2018 4:27 pm

Re: PrintToPdfAsync not using external style sheets?

Postby magreenblatt » Wed Apr 04, 2018 6:26 pm

I'm not sure how print-specific CSS is supposed to work. Hosting from file:// may also have an impact. Your google searching is likely the best approach to finding an answer.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 57 guests