In the end, Blazor components just render html. The browser converts the html and style to a print image. You can better control with media css queries.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Printing
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Target framework: net7.0-windows10.0.19041.0
I need to print some components from my app. When I read about JS interop I thought that's going to be easy. However printing like that seems to strip some (not all) of the applications styles - currently colors and icons.
I'm using MudBlazor components, so I dug in how they are doing their CSS and I found that they have defined placeholders in their CSS that are then dynamically replaced using C# and I thought maybe that's why it ends up missing half the styles. So using several tools I transformed my Blazor component to an HTML string with in-line styles that produce the same result in web-based HTML evaluators. However the Print result is still lacking any colors/icons. Why could that be?
Are there other ways to print MAUI Blazor components?
In the end, Blazor components just render html. The browser converts the html and style to a print image. You can better control with media css queries.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Printing
I've found the solution of my problem. Turns out Edge's engine has an option that disables styles by default:
Now all styles are properly rendered.