From b27eacb40f3a931525d594a6a1bea035374bdbc2 Mon Sep 17 00:00:00 2001 From: Daniil Yastremskiy Date: Thu, 26 Aug 2021 17:27:37 +0300 Subject: [PATCH 1/2] Allow printing PDF from blob --- package.json | 4 ++-- src/js/init.js | 1 + src/js/pdf.js | 5 +++++ test/manual/index.html | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 352da94..225fb7d 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ "production": "webpack --mode production --progress --hide-modules", "coverage": "open coverage/lcov-report/index.html", "coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", - "start": "webpack-dev-server --public http://localhost:8080/test/manual --open", - "standard:fix": "standard --fix" + "start": "webpack-dev-server --public http://localhost:8080/test/manual --open", + "standard:fix": "standard --fix" }, "author": "Rodrigo Vieira ", "standard": { diff --git a/src/js/init.js b/src/js/init.js index bfda427..42b1abf 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -40,6 +40,7 @@ export default { style: null, scanStyles: true, base64: false, + blob: false, // Deprecated onPdfOpen: null, diff --git a/src/js/pdf.js b/src/js/pdf.js index c4c5d72..8e0f7db 100644 --- a/src/js/pdf.js +++ b/src/js/pdf.js @@ -3,6 +3,11 @@ import { cleanUp } from './functions' export default { print: (params, printFrame) => { + if (params.blob) { + createBlobAndPrint(params, printFrame, params.printable) + return + } + // Check if we have base64 data if (params.base64) { const bytesArray = Uint8Array.from(atob(params.printable), c => c.charCodeAt(0)) diff --git a/test/manual/index.html b/test/manual/index.html index 0b606ec..07513e8 100644 --- a/test/manual/index.html +++ b/test/manual/index.html @@ -37,6 +37,18 @@ }) } + function printPdfBlob() { + fetch('/test/manual/test.pdf').then(function(response) { + response.blob().then(function(blob) { + printJS({ + printable: blob, + type: 'pdf', + blob: true + }) + }) + }) + } + function printHtml() { printJS({ printable: 'test', @@ -228,6 +240,9 @@

Print.js Test Page

+