chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.09k stars 450 forks source link

CefPdfPrintSettings - Custom margins are ignored #3651

Closed hopfen-heiner closed 4 months ago

hopfen-heiner commented 4 months ago

Custom margins are ignored when printing to PDF. Original issue (not mine) for CefSharp (which still exists in version 121): https://github.com/cefsharp/CefSharp/issues/4466 I've only reproduced it with CefSharp WPF myself.

Steps to reproduce the behavior: Print some HTML to PDF with margin_left set to 1 and margin_type set to Custom. The printed text is still placed at the very left.

Expected behavior The text is printed with a 1" margin to the left.

Versions:

magreenblatt commented 4 months ago

CEF PrintToPDF uses the same code as DevTools Page.printToPDF. If that's not working you can file a bug with Chromium at https://crbug.com/new.

magreenblatt commented 2 months ago

Check the CSS margin configuration in your source HTML page. This works for me at M124:

  1. Load an HTML example with 0 margins.
  2. Configure settings with no margin and background enabled:
    CefPdfPrintSettings settings;
    settings.margin_type = PDF_PRINT_MARGIN_NONE;
    settings.print_background = true;
  3. Resulting PDF file shows the red rectangle at the top-left corner as expected.