Use Puppeteer Sharp in Blazor webassembly

272 Views Asked by At

I want to save razor page as pdf for user.I used the following code in Blazer Web Assembly, but an error was observed.

        using var browserFetcher = new BrowserFetcher();
        await browserFetcher.DownloadAsync();
        await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
        await using var page = await browser.NewPageAsync();
        await page.GoToAsync("http://www.google.com"); // In case of fonts being loaded from a CDN, use WaitUntilNavigation.Networkidle0 as a second param.
        await page.EvaluateExpressionHandleAsync("document.fonts.ready"); // Wait for fonts to be loaded. Omitting this might result in no text rendered in pdf.
        await page.PdfAsync("my.pdf");

Error: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: System.Net.WebClient is not supported on this platform. Use System.Net.Http.HttpClient instead. System.PlatformNotSupportedException: System.Net.WebClient is not supported on this platform. Use System.Net.Http.HttpClient instead.

0

There are 0 best solutions below