Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for printing content of a webview. #7

Closed
mobiletonster opened this issue May 10, 2019 · 12 comments
Closed

Support for printing content of a webview. #7

mobiletonster opened this issue May 10, 2019 · 12 comments
Labels
feature request feature request

Comments

@mobiletonster
Copy link

Unlike WebView(EDGEhtml), please, please support printing of contents of a webview. All the crazy gyrations needed to print webview content in a UWP application today doesn't work well.

Thanks for your consideration.

@lingamy
Copy link
Collaborator

lingamy commented May 10, 2019

Thanks for your feedback. You can use CapturePreview to capture an image of what WebView is displaying. Will that work for your scenario?

@lingamy lingamy added the feature request feature request label May 10, 2019
@mobiletonster
Copy link
Author

mobiletonster commented May 10, 2019 via email

@lingamy
Copy link
Collaborator

lingamy commented May 10, 2019

Thanks for providing additional details. We'll look into how to meet the requirement for your scenario.

@dianaqu
Copy link
Contributor

dianaqu commented Jun 4, 2019

Hey @mobiletonster ,

I'm the developer looking into this feature request. Just trying to get more information from you. Can you tell me more about what you need this feature for? You mentioned Spartan WebView printing support which was complicated to hook up to UWP/WinRT printing support, do you mean a similar functionality to hook up to UWP printing APIs?

Thank you!

@mobiletonster
Copy link
Author

Yes, thank you very much for looking in to this feature. We build an application (UWP) which displays content formatted in HTML. As part of this app, we allow users to annotate and highlight, add notes, tags, etc. to the content for study purposes. The users often want to print the content along with their annotations. We use the webview control to display this content and would love to be able to print the content directly from the webview control as it is displayed on the screen. Today, we export the html, css, etc. to a local file on disk and invoke the default web browser then invoke a print command via injected Javascript...problem is, it only works part of the time and isn't always as precise as what we display within the application. Printing directly from UWP is currently very cumbersome and rarely works well.

If you would like to try the app, download Gospel Library from the Microsoft Store and try it out.

Thanks.

@liminzhu
Copy link
Member

Thanks for the context @mobiletonster !

Today, we export the html, css, etc. to a local file on disk and invoke the default web browser then invoke a print command via injected Javascript...

If you don't mind me asking, why are you going through this? Would injecting a script to WebView directly to invoke window.print work for you?

@mobiletonster
Copy link
Author

Thanks for the context @mobiletonster !

Today, we export the html, css, etc. to a local file on disk and invoke the default web browser then invoke a print command via injected Javascript...

If you don't mind me asking, why are you going through this? Would injecting a script to WebView directly to invoke window.print work for you?

Currently, the UWP or EdgeHTML WebView provides no printing support. invoking window.print doesn't actually do anything in the WebView control. Worse yet, in later version of Edge, you can no longer export your HTML/CSS to the file system and invoke a window.print due to security updates. Chrome, Firefox do still support it, so if your default browser is not Edge, it will still work. The print capabilities of the browsers are already very good (and support @media print CSS directives). To reproduce all of that capability ourselves in our app is not practical. We would prefer to access the native print capabilities of the new (or even existing) Edge browser and invoke it directly from our app/WebView control...in otherwords, be able to print what is currently loaded in the WebView control....just as the browser would do.

Thanks.

@liminzhu
Copy link
Member

liminzhu commented Jun 26, 2019

Thanks for all the links and bringing this up. I wasn't aware window.print isn't working in EdgeHTML WebView.

For the WebView2 we're building though, you can use window.print. WebView opens the same printing prompt and prints what the browser does. I was messing with this,

webviewWindow->Navigate(L"https://www.twitter.com/");
EventRegistrationToken token;
webviewWindow->add_NavigationCompleted(Callback<IWebView2NavigationCompletedEventHandler>(
    [](IWebView2WebView* wv, IWebView2NavigationCompletedEventArgs* args) -> HRESULT {
        webviewWindow->ExecuteScript(L"window.print();", nullptr);
        return S_OK;
    }).Get(), &token);

print

@mobiletonster
Copy link
Author

mobiletonster commented Jun 26, 2019

That looks promising! As long as we can invoke the webview's print api's, then that would be perfect!

@liminzhu
Copy link
Member

Great! I think the issue is resolved at this point, but feel free to reopen if you have additional comments on this topic.

@asklar
Copy link

asklar commented May 21, 2021

the platform has requests around converting html or other web content into pdf, which would benefit from this feature being implemented. See microsoft/react-native-windows#7723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request
Projects
None yet
Development

No branches or pull requests

5 participants