0

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.

Jeff Godfrey
  • 718
  • 8
  • 18
  • CefSharp is just a wrapper, CEF has it's own forum see ://magpcss.org/ceforum/index.php – amaitland Apr 04 '18 at 20:59
  • Thanks - I'll drop a question there also. – Jeff Godfrey Apr 04 '18 at 21:26
  • Before doing so you will need to test with the latest version of the CEF sample application. See https://github.com/cefsharp/CefSharp/blob/master/CONTRIBUTING.md#cefsharp-vs-chromium-embedded-frameworkcef – amaitland Apr 04 '18 at 21:47
  • 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. – Jeff Godfrey Apr 05 '18 at 00:06
  • @JeffGodfrey Did you ever get resolution on this? Printing cell backgrounds in tables still does not seem to work even today (2020!) – A X Feb 03 '20 at 06:16

0 Answers0