Open bhavinangular28 opened 1 year ago
I made the following workaround:
export function printJsSuportMobile(printJsConfig: Configuration) {
const isAndroidDevice = navigator.userAgent.match(/Android/i);
if (isAndroidDevice) {
const byteArray = Uint8Array.from(atob(printJsConfig.printable).split('').map(char => char.charCodeAt(0)));
const blob = new Blob([byteArray], { type: 'application/pdf' });
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl, '_blank');
} else {
printJS(printJsConfig);
}
}
Edit: Obviouly it is only for Android, but in iOS, printJS was working just fine
@eduardocalixtokorp ok thanks but the IOS Chrome browser is not working for mobile
@bhavinangular28 I see. I tested in the latest Safari version not in chrome, but probably you can alter the code above and test it. It'd be something like:
export function printJsSuportMobile(printJsConfig: Configuration) {
const isAndroidDevice = navigator.userAgent.match(/Android/i);
const isAppleDevice = (/iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) && !window.MSStream
if (isAndroidDevice || isAppleDevice) {
const byteArray = Uint8Array.from(atob(printJsConfig.printable).split('').map(char => char.charCodeAt(0)));
const blob = new Blob([byteArray], { type: 'application/pdf' });
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl, '_blank');
} else {
printJS(printJsConfig);
}
}
IDK if isAppleDevice works, just got it from a random stackoverflow.
@eduardocalixtokorp I want to change the name, I can do it and how will it be done
@bhavinangular28, probably something like this. I didn't worry about it at the time, but iframe seems to be a reasonable solution
@eduardocalixtokorp does not proper show the title
@eduardocalixtokorp any suggestion please help
@bhavinangular28 Maybe this
@eduardocalixtokorp ok thanks but the IOS Chrome browser is not working for mobile
same for me, it prints the the contents of the webpage instead of the pdf file
Fix for printJS(div_id,'html')
function printJSFixed(options) { if (-1 !== navigator.userAgent.toLowerCase().indexOf('crios') || -1 !== navigator.userAgent.toLowerCase().indexOf('fxios')) { var newWindow = window.open('', '_blank'); newWindow.document.write($('#'+options).html()); newWindow.print(); } else { printJS(options,'html'); } }
base64 content is not properly working please any suggestion