From 71f604207b61056c783cfe8c1d52fa2614aefda6 Mon Sep 17 00:00:00 2001 From: phayes Date: Fri, 26 Mar 2021 15:24:45 -0700 Subject: [PATCH 1/3] Adding suppot for custom http headers when printing a PDF --- src/index.d.ts | 1 + src/js/pdf.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/index.d.ts b/src/index.d.ts index d52f589..88fd5d6 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -31,6 +31,7 @@ declare namespace printJS { onPrintDialogClose?: () => void; onIncompatibleBrowser?: () => void; base64?: boolean; + httpHeaders?: { [key: string]: string } // Deprecated onPdfOpen?: () => void; diff --git a/src/js/pdf.js b/src/js/pdf.js index c4c5d72..3346989 100644 --- a/src/js/pdf.js +++ b/src/js/pdf.js @@ -41,6 +41,11 @@ export default { }) req.open('GET', params.printable, true) + if (params.httpHeaders) { + for (const [header, value] of Object.entries(params.httpHeaders)) { + req.setRequestHeader(header, value) + } + } req.send() } } From 54e94839a69f05dd968b8ec8954c2a10828139a7 Mon Sep 17 00:00:00 2001 From: phayes Date: Wed, 31 Mar 2021 18:36:34 -0700 Subject: [PATCH 2/3] Initialize empty http headers --- src/js/init.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/init.js b/src/js/init.js index bfda427..4332ab1 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -40,6 +40,7 @@ export default { style: null, scanStyles: true, base64: false, + httpHeaders: {}, // Deprecated onPdfOpen: null, From c8e11e75ef9fc30bdc069e1b327f8d745f5e62bb Mon Sep 17 00:00:00 2001 From: PHAYES Date: Wed, 31 Mar 2021 19:34:18 -0700 Subject: [PATCH 3/3] Update index.d.ts --- src/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.d.ts b/src/index.d.ts index 88fd5d6..94e873c 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -31,7 +31,7 @@ declare namespace printJS { onPrintDialogClose?: () => void; onIncompatibleBrowser?: () => void; base64?: boolean; - httpHeaders?: { [key: string]: string } + httpHeaders?: { [key: string]: string }; // Deprecated onPdfOpen?: () => void;