diff --git a/core/output/printer.js b/core/output/printer.js index e7463368e..6fff389c4 100644 --- a/core/output/printer.js +++ b/core/output/printer.js @@ -1,3 +1,5 @@ +import { isIOS, isAndroid } from "../util/browser.js"; + const PACKETS = { DOCUMENT_START: 0, DOCUMENT_CHUNK: 1, @@ -5,19 +7,25 @@ const PACKETS = { }; const printDocument = async (data) => { - const iframe = document.createElement("iframe"); - iframe.style.display = "none"; - document.body.appendChild(iframe); - - iframe.onload = () => { - setTimeout(() => { - iframe.focus(); - iframe.contentWindow.print(); - }, 1); - }; - - const blob = new Blob([new Uint8Array(data)], { type: "application/pdf" }); - iframe.src = URL.createObjectURL(blob); + if (!(isIOS() || isAndroid())) { + const iframe = document.createElement("iframe"); + iframe.style.display = "none"; + document.body.appendChild(iframe); + + iframe.onload = () => { + setTimeout(() => { + iframe.focus(); + iframe.contentWindow.print(); + }, 1); + }; + + const blob = new Blob([new Uint8Array(data)], { type: "application/pdf" }); + iframe.src = URL.createObjectURL(blob); + } else { + const blob = new Blob([new Uint8Array(data)], { type: "application/pdf" }); + const blobUrl = URL.createObjectURL(blob); + window.open(blobUrl, '_blank'); + } } export default (rfb) => { @@ -60,4 +68,4 @@ export default (rfb) => { } rfb.subscribeUnixRelay("printer", processRelayData); -} \ No newline at end of file +} diff --git a/core/util/browser.js b/core/util/browser.js index 436738b96..7d46075d0 100644 --- a/core/util/browser.js +++ b/core/util/browser.js @@ -96,6 +96,10 @@ export function isIOS() { !!(/ipod/i).exec(navigator.platform)); } +export function isAndroid() { + return navigator && navigator.userAgent.match(/Android/i); +} + export function isSafari() { return navigator && (navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1);