Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions core/output/printer.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import { isIOS, isAndroid } from "../util/browser.js";

const PACKETS = {
DOCUMENT_START: 0,
DOCUMENT_CHUNK: 1,
DOCUMENT_END: 2
};

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) => {
Expand Down Expand Up @@ -60,4 +68,4 @@ export default (rfb) => {
}

rfb.subscribeUnixRelay("printer", processRelayData);
}
}
4 changes: 4 additions & 0 deletions core/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down