crabbly / Print.js

A tiny javascript library to help printing from the web.
MIT License
4.33k stars 674 forks source link

Mobile Android and IOS chrome browser not working #677

Open bhavinangular28 opened 1 year ago

bhavinangular28 commented 1 year ago

base64 content is not properly working please any suggestion

eduardocalixtokorp commented 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

bhavinangular28 commented 1 year ago

@eduardocalixtokorp ok thanks but the IOS Chrome browser is not working for mobile

eduardocalixtokorp commented 1 year ago

@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.

bhavinangular28 commented 1 year ago

@eduardocalixtokorp I want to change the name, I can do it and how will it be done

Screenshot_2

eduardocalixtokorp commented 1 year ago

@bhavinangular28, probably something like this. I didn't worry about it at the time, but iframe seems to be a reasonable solution

bhavinangular28 commented 1 year ago

@eduardocalixtokorp does not proper show the title

image

bhavinangular28 commented 1 year ago

@eduardocalixtokorp any suggestion please help

eduardocalixtokorp commented 1 year ago

@bhavinangular28 Maybe this

edmandell commented 3 months ago

@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

algarsys commented 1 month ago

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'); } }