question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to print an html element’s content using the os print dialog. I have the following code snippet that launches the print dialog with expected content in the device browser.

    const printContent = document.getElementById('print-container');
    const prtFrame = document.getElementById("iframe_to_print").contentWindow;
    prtFrame.document.open();
    prtFrame.document.write(printContent.innerHTML);
    prtFrame.document.close();
    prtFrame.focus();
    prtFrame.print();

However nothing just happens within react-native app using the webview.

  • webview version: 8.1.0
  • react-native: 0.61.5

Looks like something is preventing the system print dialog from showing up in the app.

Is there a step that I’m overlooking or another known way of doing printing in webview?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

3reactions
macdiggercommented, Apr 28, 2022

Thanks!

Unfortunately what I need to do is printing a PDF file shown inside web view.

Doesn’t seem possible to fetch its data from web view using messaging. Because it’s a PDF, not HTML content.

I probably need to download the PDF and use some sort of library to display it separately from web view, and print it out. But so far I could only find some commercial solutions without even pricing announced. I’m currently researching this approach but no clear solution yet.

I can’t even open PDF inside OS browser because it requires some specific authentication cookies to be set before PDF can be served to a user 😦

Would’ve been nice to just be able to have a print command 🤷‍♂️

1reaction
TinJendacommented, Apr 28, 2022

I had tip: I used postMessage event of react-native-webview to send data to native app, then used react-native-print lib to print as desired

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vistaprint US Online Printing: Business Cards, Signage & More
Create and order printed marketing materials, business signs, and promotional products directly from your office. Satisfaction Absolutely Guaranteed.
Read more >
Printing & Marketing Services | Staples®
Shop Staples Print Marketing Services for affordable copies, custom business cards, business stationery, promotional items, & more. Fast shipping available.
Read more >
Printing - Wikipedia
Printing is a process for mass reproducing text and images using a master form or template. The earliest non-paper products involving printing include ......
Read more >
Prints | Order Photo Prints Online - Shutterfly
Prints by Mail or in Minutes. Get your photos as quickly as you need them — place an order for delivery or pick...
Read more >
Print on Demand Online Printing - FedEx Office
Use the FedEx Office online printing tool to quickly and easily create, edit, and order custom business cards, posters, brochures, canvas prints and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found