this project fork from Microsoft WebView2Samples, plus large PDF file size handling
I tested 7MB, 15MB, 26MB pdf, all are successfully read and view in webView2
add requestedFilter on URL https://example.com
or https://template/*
in my code
in the captured event, custom generate your webpage with the big pdf in base64 in HTML
fire your webView2 always on the https://example.com
or https://template/*
e.g webView.Source = new Uri($@"https://template/");
Which I didn't implement
Suggested to append id in URL e.g https://example.com?file=fileId for easy to trace, logging for debug and/or HTTP redirections purpose
the user requirements may concern save as, print by right click or tool bar on webView2
Please read HiddenPdfToolbarItems Property
capture the mouse and deactivate “right click”
https://stackoverflow.com/questions/18398058/disable-right-click-menu-on-webview
void AddResourceFilterCmdExecuted(object target, ExecutedRoutedEventArgs e)
{
// Add a filter to intercept requests made to https://example.com
// Then replace the response with a large html string.
webView.CoreWebView2.AddWebResourceRequestedFilter("https://example.com", CoreWebView2WebResourceContext.All);
webView.CoreWebView2.WebResourceRequested += WebView_OnWebResourceRequested;
}
void WebView_OnWebResourceRequested(object sender, CoreWebView2WebResourceRequestedEventArgs e)
{
// Intercept the web resource request; set the response as the large html content string.
string responseDataString = "<html><head><title>Hello World</title></head><body><h1>Large content</h1></body></html>";
UTF8Encoding utfEncoding = new UTF8Encoding();
byte[] responseData = utfEncoding.GetBytes(
responseDataString);
...
e.Response = webResourceResponse;
}