ngx-print
ngx-print copied to clipboard
Does not work on mobile Chrome
This is a great component, and works really well on desktops. But, I need to use this functionality on mobile browsers.
On mobile browsers, such as Chrome, it doesn't seem to work. It will just open up a window and says "There was a problem printing the page. Please try again".
Anyone has any solution?
Thanks.
Important functionality for me too, any solution?
No solution. I ended up generating the page as a PDF file on the server, and download that for printing.
I also have the same issue :(
Any update? I need this functionality....
any progress in this issue @sdecianu @jmijmi @calldeludo @davemecha @dopinder100 ,@selemxmn ....
Hi everyone... since no one shared a solution, i refused to use this library because this problem seems that no body will fix it. The bug is just easy, chrome on mobile just close the tab before print thats why ngx-print fails, so i decided to do something similar
With this approach i just control if the device is a mobile or desktop, if it is a mobile just remove window.close onload body.
printContents = document.getElementById('print-section').innerHTML;
popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
popupWin.document.open();
if (this.deviceService.isDesktop()) {
popupWin.document.write(`
<html>
<head>
<title>${titulo}</title>
//ADD BOOTSTRAP IF YOU ARE USING IT
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
<style>
//........Customized style.......
...
</style>
</head>
<body onload="window.print();window.close()">${printContents}</body>
</html>`
);
popupWin.document.close();
} else { //REMOVE window.close() if the device is a mobile.
popupWin.document.write(`
<html>
<head>
<title>Print tab</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
<style>
//........Customized style.......
....
</style>
</head>
<body onload="window.print()">${printContents}</body>
</html>`
);
popupWin.document.close();
}
}
I hope it helps someone, for me is working perfectly!
Hi everyone... since no one shared a solution, i refused to use this library because this problem seems that no body will fix it. The bug is just easy, chrome on mobile just close the tab before print thats why ngx-print fails, so i decided to do something similar With this approach i just control if the device is a mobile or desktop, if it is a mobile just remove window.close onload body.
printContents = document.getElementById('print-section').innerHTML; popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto'); popupWin.document.open(); if (this.deviceService.isDesktop()) { popupWin.document.write(` <html> <head> <title>${titulo}</title> //ADD BOOTSTRAP IF YOU ARE USING IT <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script> <style> //........Customized style....... ... </style> </head> <body onload="window.print();window.close()">${printContents}</body> </html>` ); popupWin.document.close(); } else { //REMOVE window.close() if the device is a mobile. popupWin.document.write(` <html> <head> <title>Print tab</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script> <style> //........Customized style....... .... </style> </head> <body onload="window.print()">${printContents}</body> </html>` ); popupWin.document.close(); } }
I hope it helps someone, for me is working perfectly!
@calldeludo thanks alot ,thats work for me as well ,except (I just use document/window . ,instead of starting with popUpWin) ..I don't know if it could rise any issue in the future r what was the essence of starting with popUpWin ?
@calldeludo thanks alot ,thats work for me as well ,except (I just use document/window . ,instead of starting with popUpWin) ..I don't know if it could rise any issue in the future r what was the essence of starting with popUpWin ?
i think it is all about user experience... in my case is more useful to open it as a popup and then close after print... but using document/window should be the same.
@calldeludo @Kijacode - Thanks a lot, this works for me too.
But one issue is that, my page does not contain background color in print preview on mobile device but i get it in desktop.
Hello, @calldeludo thank you very much, that works so nicely. @sohebcakewalk I am late, but for anyone else, adding
* { color-adjust: exact;
-webkit-print-color-adjust: exact;}
to the section solves the problem, at least form me in Chrome and Firefox.
However, the fix for this issue would be so appreciated.
Hi everyone... since no one shared a solution, i refused to use this library because this problem seems that no body will fix it. The bug is just easy, chrome on mobile just close the tab before print thats why ngx-print fails, so i decided to do something similar
With this approach i just control if the device is a mobile or desktop, if it is a mobile just remove window.close onload body.
printContents = document.getElementById('print-section').innerHTML; popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto'); popupWin.document.open(); if (this.deviceService.isDesktop()) { popupWin.document.write(` <html> <head> <title>${titulo}</title> //ADD BOOTSTRAP IF YOU ARE USING IT <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script> <style> //........Customized style....... ... </style> </head> <body onload="window.print();window.close()">${printContents}</body> </html>` ); popupWin.document.close(); } else { //REMOVE window.close() if the device is a mobile. popupWin.document.write(` <html> <head> <title>Print tab</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script> <style> //........Customized style....... .... </style> </head> <body onload="window.print()">${printContents}</body> </html>` ); popupWin.document.close(); } }
I hope it helps someone, for me is working perfectly!
@calldeludo can you help me, where I have to put the code in my component, I am new to Angular...
Hello @abahuus , I have document most of the ways to help you to cover this up . check this blog post here
@Kijacode nice post 👍 @abahuus go to his blog, all is good explained there
Regards
@Kijacode @calldeludo ... thanks for your kind attention...
Same problem in Reactjs also can you give solution to me.
Same problem in Reactjs also can you give solution to me.
Hello @PRANITHMEESALA , please also check this out using the package known as printjs
This has been fixed with the [closeWindow] option in #165