@Wael Sedky, Welcome to Microsoft Q&A, you could try to use CoreWebView2.PrintToPdfAsync(String, CoreWebView2PrintSettings) Method to print pdf from webview2 control.
Here is a code example you could refer to.
private async void Form1_Load(object sender, EventArgs e)
{
await webView21.EnsureCoreWebView2Async();
webView21.CoreWebView2.Navigate("https://www.example.com");
}
private async void button1_Click(object sender, EventArgs e)
{
var printSettings = webView21.CoreWebView2.Environment.CreatePrintSettings();
printSettings.PageHeight = 297; // A4 paper size
printSettings.PageWidth = 210;
printSettings.MarginTop = 10;
printSettings.MarginBottom = 10;
printSettings.MarginLeft = 10;
printSettings.MarginRight = 10;
var pdfData = await webView21.CoreWebView2.PrintToPdfAsync("B:\\test1.pdf",printSettings);
}
Tested result:
Hope my code could help you.
Best Regards,
Jack
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.