CefSharp PrintToPdfAsync not using external CSS?

121 views
Skip to first unread message

Jeff Godfrey

unread,
Apr 4, 2018, 1:18:39 PM4/4/18
to CefSharp
I'm using CefSharp (v63) to convert *local* HTML-based reports to PDF for portability. Generally, this works exactly as intended. However, it seems that if the HTML references an *external* CSS stylesheet, the styles are not represented in the exported PDF file.

Note, the rendered HTML shown in my CefSharp-based app looks as expected. That is, the stylesheet info is being used there. However, once I export the document to PDF (via PrintToPdfAsync), the stylesheet info seems to be lost or no longer referenced lost.

Specifically, I notice issues in table formats (no backgrounds, no borders, incorrect padding, ...).

If I instead put the CSS styles directly within the HTML file (instead of referencing it externally) the PDF does reflect the correct styles. While I haven't looked at the core code involved here, I assumed the PDF export was driven from the already-rendered browser document (which, again, is correct), but maybe that's not the case?

Thanks for any tips or pointers.

Jeff Godfrey

unread,
Apr 4, 2018, 8:09:33 PM4/4/18
to CefSharp
So, this seems to be less a bug and more an issue of my document missing a print-specific style sheet. Defining a print style sheet has mostly fixed the issue. At least now my table styling is generally correct, though I can't get any cell background colors to render to PDF - even after enabling the PdfPrintSettings.BackgroundsEnabled property. Also, the results I see from my CefSharp-based app are identical to what i see if I view the same file in Chrome and look at the print preview there. So, whatever the issue, it's related to the Chrome core and not CefSharp specifically
Reply all
Reply to author
Forward
0 new messages