react-to-print icon indicating copy to clipboard operation
react-to-print copied to clipboard

Printing entire UI on mobile

Open hrutvikpatel opened this issue 5 years ago • 24 comments

ReacToPrint is able to print the specific react component I want to print on browsers on the desktop and on the IPad safari works as well. However, when printing the react component using chrome on the IPad the entire UI is printed.

I checked the console and there were no errors present.

I also checked that the ref returned to the content property is referring to the react component that needs to be printed.

I am not sure why ReactToPrint defaults to printing the entire UI on chrome on the IPad, I was wondering if someone else also ran into this issue.

hrutvikpatel avatar Dec 09 '19 13:12 hrutvikpatel

I am trying to understand the code and was wondering what the purpose of the setTimeout is in the startPrint method?

hrutvikpatel avatar Dec 09 '19 15:12 hrutvikpatel

It appears to be an issue with iframe. Where iframe.contentwindow.print() seems to have an issue printing on safari/chrome on IOS. It prints the entire UI instead. I wonder if there is a workaround to this.

hrutvikpatel avatar Dec 09 '19 17:12 hrutvikpatel

Unfortunately we have no control (to my knowledge) of what the browser decides to do after we call .print(). It sounds like those browsers print everything open, not just the iframe. If you know of a solution we can use to fix this issue I would be happy to include it.

MatthewHerbst avatar Dec 09 '19 23:12 MatthewHerbst

ReacToPrint is able to print the specific react component I want to print on browsers on the desktop and on the IPad safari works as well. However, when printing the react component using chrome on the IPad the entire UI is printed.

I checked the console and there were no errors present.

I also checked that the ref returned to the content property is referring to the react component that needs to be printed.

I am not sure why ReactToPrint defaults to printing the entire UI on chrome on the IPad, I was wondering if someone else also ran into this issue.

Hi. Ran into the same issue. Did you find a workaround?

Cheers.

ekediala avatar Sep 18 '20 18:09 ekediala

@ekediala as noted above, to the best of my knowledge this is not something we can fix. If you know of a solution please let me know

MatthewHerbst avatar Sep 18 '20 19:09 MatthewHerbst

@MatthewHerbst thank you. Will let you know if I do.

ekediala avatar Sep 18 '20 19:09 ekediala

Any news on this one?

Also ran into this when building a GatsbyJS website and I found the package perfect for the job.

Will also do some digging if there is something doable here ;)

nate-vukovich avatar Apr 20 '21 14:04 nate-vukovich

Hmm looking for any news for this issue. We have tested all other browsers with this great library, but I we were not able to print in Chrome on iPad. The print preview returns entire application... hmm, I will try to use different print method, and update here.

joungwoo-jay avatar Oct 11 '21 16:10 joungwoo-jay

Same issue still here in latest iOS with Chrome. But furthermore, there is an issue with onBeforeGetContent effects not showing in the iOS print. For example, I have a table in my code that I paginate. Before printing, I un-paginate it for the full print. This works on web, but on iOS, the page does change to remove pagination, but the printout shows with pagination still.

I also can't get the CodeSandbox to print on mobile at all except for the Text-only option. (https://codesandbox.io/s/rzdhd)

james-e-morris avatar Aug 04 '22 17:08 james-e-morris

Also having the same issue. Let us know if there is a solution

pjethali avatar Oct 07 '22 13:10 pjethali

Facing the same issue. Does anyone have any update on this?

nehashende avatar Nov 22 '22 12:11 nehashende

I found a way around it that worked for me. I used

<ReactToPrint
    onBeforePrint={() => setIsPrinting(true)}
    onAfterPrint={() => setIsPrinting(false)}
...

Then make the particular component to take up the whole screen if isPrinting

onyedika-anagha avatar Mar 08 '23 12:03 onyedika-anagha

i have the same issue, @onyedika-anagha solution seems to work, but not in my case. because the size of the component that i am printing is important, so if i make the component to take the whole screen then it will not be the size that i want it

m-a-h1 avatar Jun 22 '23 08:06 m-a-h1

@m-a-h1 could you maybe trick the browser by adding a wrapping div around your component that is transparent and takes up the whole screen, and then has your component as its only child?

MatthewHerbst avatar Jun 22 '23 09:06 MatthewHerbst

@m-a-h1 could you maybe trick the browser by adding a wrapping div around your component that is transparent and takes up the whole screen, and then has your component as its only child?

it will not change the print size. the printer that i use is small, and even if the component take the whole screen , the print final print page will be the full page, not the size that i defined on the component

m-a-h1 avatar Jun 22 '23 10:06 m-a-h1

Has anyone got the solution for this issue?

PatidarNikunj avatar Sep 03 '23 12:09 PatidarNikunj

Looking forward for the solution or any alternate library that can use for mobile chrome and firefox ?

Pallavi-mah avatar Oct 03 '23 14:10 Pallavi-mah

Any news on this one?

Also ran into this when building a GatsbyJS website and I found the package perfect for the job.

Will also do some digging if there is something doable here ;)

Can you please let me know the package?

Pallavi-mah avatar Oct 10 '23 02:10 Pallavi-mah

I found a way around it that worked for me. I used

<ReactToPrint
    onBeforePrint={() => setIsPrinting(true)}
    onAfterPrint={() => setIsPrinting(false)}
...

Then make the particular component to take up the whole screen if isPrinting

It seems that onAfterPrint is being called before printing is even finished on iOS (chrome and firefox). Adding timeout helps for initial view, but if you change some print settings it re-renders bad preview.

simaks avatar Nov 17 '23 16:11 simaks

It seems that onAfterPrint is being called before printing is even finished on iOS (chrome and firefox). Adding timeout helps for initial view, but if you change some print settings it re-renders bad preview.

This is a known issue that is specifically called out on our README. It is not something we can fix. Please note that all browsers on iOS use WebKit under the hood (Apple forces this) so they are basically all the same as Safari. Apple may allow non-WebKit browsers in the near future due to anti-trust issues, especially in the EU and UK 🙏

MatthewHerbst avatar Nov 17 '23 19:11 MatthewHerbst

So in iOS it works on safari, but doesn't on other browsers. I wonder is it a bug of iOS or all iOS browsers except safari?

simaks avatar Nov 17 '23 20:11 simaks