C# How to use CoreWebView2PrintSettings correctly?

789 Views Asked by At

I'm using PrintToPdfAsync to print the content of my WebView in pdf, but when trying to adjust the top margin I'm not getting a response. The file is created but the margin comes as default.

CoreWebView2PrintSettings printSettings = _instance.webView21.CoreWebView2.Environment.CreatePrintSettings();
printSettings.Orientation = CoreWebView2PrintOrientation.Landscape;
printSettings.MarginTop = 100;
_instance.webView21.CoreWebView2.PrintToPdfAsync(output, printSettings)
1

There are 1 best solutions below

0
vickiezee On

The unit for margins is inches, and the value can't exceed the page height (default is 11 inches). See the WebView2 Reference.