crabbly / Print.js

A tiny javascript library to help printing from the web.
MIT License
4.28k stars 672 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 weeks 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