cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.89k stars 2.92k forks source link

PrintToPdf - PdfPrintSettings - Custom Margins do not work #4466

Closed TomasPojezny-IdeaStatiCa closed 10 months ago

TomasPojezny-IdeaStatiCa commented 1 year ago
  private static PdfPrintSettings GetPdfPrintSettings()
  {
      double MillimetersToInches (double millimeter) => millimeter / 25.4;

      return new PdfPrintSettings
      {
          PaperWidth = MillimetersToInches(210.0),
          PaperHeight = MillimetersToInches(297.0),

          // NOTE: Margins input does not seem to work in CefSharp version 110.0.300
          MarginType = CefPdfPrintMarginType.Custom,
          MarginLeft = MillimetersToInches(20.0),
          MarginTop = MillimetersToInches(30.0),
          MarginRight = MillimetersToInches(10.0),
          MarginBottom = MillimetersToInches(25.0),

          PrintBackground = true
      };
  }

  // ...

  webBrowserHost.GetBrowser().GetHost().PrintToPdf(dialog.FileName, GetPdfPrintSettings(), callback);
amaitland commented 1 year ago
  • What version of the product are you using? Nuget 110.0.300

Please test with the current release.

Custom Margins do not work

CefSharp does little more than populate the structure and call the underlying CEF method. So I suspect this is a problem in CEF

https://github.com/cefsharp/CefSharp/blob/v112.2.70/CefSharp.Core.Runtime/Internals/CefBrowserHostWrapper.cpp#L96

https://github.com/chromiumembedded/cef/blob/5615/include/internal/cef_types.h#L2536

If the problem reproduces in the current supported version then it's probably worth stepping through with the debugger to confirm the correct values is being passed through. On the surface it looks like an upstream issue in CEF.

aimcosoftware commented 1 year ago

I've implemented PDF.js, which gives you complete control https://mozilla.github.io/pdf.js/

hronlukas commented 1 year ago

Hi, I've tested it with 115.3.130 and still it doesn't work.

amaitland commented 1 year ago

stepping through with the debugger to confirm the correct values is being passed through. On the surface it looks like an upstream issue in CEF.

Build the project from source, confirm the values are being passed through correctly. The actual implementation is at the CEF/Chromium level.

amaitland commented 10 months ago

Closing as upstream. If this still reproduces with the current supported version of CEF (M121 at time of writing) then you'll need to raise an issue at https://github.com/chromiumembedded/cef/issues (Post a link back here for reference)

hopfen-heiner commented 9 months ago

Still happens in 121, I've created an issue here.