@progress/kendo-pdfviewer-common 0.6.0-develop.1 → 0.6.1-develop.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/utils.js CHANGED
@@ -68,7 +68,9 @@ export const download = (options, fileName = 'Document', saveOptions = {}, onDow
68
68
  if (options.pdf) {
69
69
  options.pdf
70
70
  .getData()
71
- .then((data) => new Blob([data], { type: 'application/pdf' }))
71
+ .then((data) =>
72
+ // @ts-ignore
73
+ new Blob([data], { type: 'application/pdf' }))
72
74
  .then((blob) => {
73
75
  if (!onDownload(blob, fileName, saveOptions)) {
74
76
  saveAs(blob, fileName, saveOptions);
@@ -163,8 +163,8 @@ export class Page extends Component {
163
163
  const canvas = this.canvasForPrint;
164
164
  const printContentLoadPromise = this.createPromise();
165
165
  const printContent = new Image();
166
- const pageHeight = canvas.height;
167
- const pageWidth = canvas.width;
166
+ const pageHeight = (canvas.height / this.pdfViewer.getPrintScale()) * this.pdfViewer.getPdfToCssUnits();
167
+ const pageWidth = (canvas.width / this.pdfViewer.getPrintScale()) * this.pdfViewer.getPdfToCssUnits();
168
168
  printContent.src = canvas.toDataURL();
169
169
  printContent.width = pageWidth;
170
170
  printContent.height = pageHeight;
@@ -210,11 +210,8 @@ export class Page extends Component {
210
210
  renderForPrintAsync() {
211
211
  var _a, _b;
212
212
  const printUnits = this.pdfViewer.getPrintUnits();
213
- // this is how pdf.js prints
214
- const printScale = 1;
215
- const { canvasContext, canvas } = this.pdfViewer.createPageElements({
213
+ const { canvasContext, canvas, viewport } = this.pdfViewer.createPageElements({
216
214
  pdfPage: this.pdfPage,
217
- zoom: printScale,
218
215
  printUnits
219
216
  });
220
217
  this.canvasForPrint = canvas;
@@ -226,8 +223,7 @@ export class Page extends Component {
226
223
  });
227
224
  const renderContext = {
228
225
  canvasContext: canvasContext,
229
- transform: [printUnits, 0, 0, printUnits, 0, 0],
230
- viewport: this.pdfPage.getViewport({ scale: printScale, rotation: this.viewport.rotation }),
226
+ viewport: viewport,
231
227
  intent: "print",
232
228
  annotationMode: AnnotationMode.ENABLE_STORAGE,
233
229
  optionalContentConfigPromise,
@@ -59,8 +59,8 @@ export class PdfViewer extends Component {
59
59
  pageChangeScrollThreshold: 0.85,
60
60
  // values higher than 200ms can result in browser zoom
61
61
  pageWheelThrottleDelay: 200,
62
- // ported from pdf.js
63
- printResolution: 100,
62
+ // the print scale that is used for controlling the print quality
63
+ printScale: 3,
64
64
  // the render scale that is used for controlling the render quality
65
65
  renderScale: 3,
66
66
  loadOnDemand: false,
@@ -338,7 +338,20 @@ export class PdfViewer extends Component {
338
338
  return __classPrivateFieldGet(this, _PdfViewer_annotationMode, "f");
339
339
  }
340
340
  getPrintUnits() {
341
- return this.options.printResolution / PixelsPerInch.PDF;
341
+ return this.getPrintScale();
342
+ }
343
+ getPdfToCssUnits() {
344
+ return PixelsPerInch.PDF_TO_CSS_UNITS;
345
+ }
346
+ getPrintScale() {
347
+ return this.getPrintResolution() / PixelsPerInch.PDF;
348
+ }
349
+ getPrintResolution() {
350
+ // the default is 150 in pdf.js, we use 300 to have better DPI by default
351
+ return 100 * this.options.printScale;
352
+ }
353
+ getRenderScale() {
354
+ return getScale(this.options.renderScale);
342
355
  }
343
356
  extendOptions(options) {
344
357
  this.options = deepExtend(this.options, options);
@@ -752,9 +765,9 @@ export class PdfViewer extends Component {
752
765
  if (zoom <= 0) {
753
766
  return;
754
767
  }
755
- let scaleNum = getScale(this.options.renderScale);
768
+ let scaleNum = this.getRenderScale();
756
769
  if (printUnits) {
757
- scaleNum = zoom || scaleNum;
770
+ scaleNum = this.getPrintScale();
758
771
  }
759
772
  // changing the viewport dimensions here requires changes in
760
773
  // page.getPrintContentAsync for the printing dimensions
@@ -769,17 +782,22 @@ export class PdfViewer extends Component {
769
782
  height: `round(var(--scale-factor) * ${viewport.height / scaleNum}px, 1px)`
770
783
  };
771
784
  const pageElement = createElement("div", "k-page", styles);
772
- const canvas = createElement("canvas", '', {
773
- width: "100%",
774
- height: "100%"
775
- });
785
+ const canvas = createElement("canvas", '', {});
776
786
  canvas.height = adjustedHeight;
777
787
  canvas.width = adjustedWidth;
778
788
  if (printUnits) {
779
- canvas.width = Math.floor(canvas.width * (printUnits || 1));
780
- canvas.height = Math.floor(canvas.height * (printUnits || 1));
789
+ canvas.style.width = `${viewport.width / scaleNum}px`;
790
+ canvas.style.height = `${viewport.height / scaleNum}px`;
791
+ }
792
+ else {
793
+ canvas.style.width = "100%";
794
+ canvas.style.height = "100%";
781
795
  }
782
796
  const canvasContext = canvas.getContext("2d");
797
+ if (printUnits) {
798
+ // aim for crisp pixels when printing
799
+ canvasContext.imageSmoothingEnabled = false;
800
+ }
783
801
  const canvasWrapper = convertToHtml(`
784
802
  <div class="${this.options.elementSelectors.pageCanvasWrapper}"></div>
785
803
  `);
@@ -940,6 +958,7 @@ export class PdfViewer extends Component {
940
958
  if (!data) {
941
959
  return;
942
960
  }
961
+ // @ts-ignore
943
962
  return new Blob([data], { type: 'application/pdf' });
944
963
  })
945
964
  .then((blob) => {
@@ -1175,8 +1194,8 @@ export class PdfViewer extends Component {
1175
1194
  }
1176
1195
  openPrintDialog() {
1177
1196
  const pages = this.pages;
1178
- const width = pages[0].rawWidth * this.getPrintUnits();
1179
- const height = pages[0].rawHeight * this.getPrintUnits();
1197
+ const width = pages[0].rawWidth * this.getPdfToCssUnits();
1198
+ const height = pages[0].rawHeight * this.getPdfToCssUnits();
1180
1199
  const printDialog = window.open('', '', 'innerWidth=' + width + ',innerHeight=' + height + 'location=no,titlebar=no,toolbar=no');
1181
1200
  if (!printDialog || !printDialog.document) {
1182
1201
  this.triggerError({
@@ -1195,7 +1214,6 @@ export class PdfViewer extends Component {
1195
1214
  printDialog.print();
1196
1215
  // setTimeout(() => {
1197
1216
  // printDialog.print();
1198
- // done();
1199
1217
  // });
1200
1218
  }
1201
1219
  cacheZoomLevelBeforePrint() {
@@ -68,7 +68,9 @@ export const download = (options, fileName = 'Document', saveOptions = {}, onDow
68
68
  if (options.pdf) {
69
69
  options.pdf
70
70
  .getData()
71
- .then((data) => new Blob([data], { type: 'application/pdf' }))
71
+ .then((data) =>
72
+ // @ts-ignore
73
+ new Blob([data], { type: 'application/pdf' }))
72
74
  .then((blob) => {
73
75
  if (!onDownload(blob, fileName, saveOptions)) {
74
76
  saveAs(blob, fileName, saveOptions);
@@ -163,8 +163,8 @@ export class Page extends Component {
163
163
  const canvas = this.canvasForPrint;
164
164
  const printContentLoadPromise = this.createPromise();
165
165
  const printContent = new Image();
166
- const pageHeight = canvas.height;
167
- const pageWidth = canvas.width;
166
+ const pageHeight = (canvas.height / this.pdfViewer.getPrintScale()) * this.pdfViewer.getPdfToCssUnits();
167
+ const pageWidth = (canvas.width / this.pdfViewer.getPrintScale()) * this.pdfViewer.getPdfToCssUnits();
168
168
  printContent.src = canvas.toDataURL();
169
169
  printContent.width = pageWidth;
170
170
  printContent.height = pageHeight;
@@ -210,11 +210,8 @@ export class Page extends Component {
210
210
  renderForPrintAsync() {
211
211
  var _a, _b;
212
212
  const printUnits = this.pdfViewer.getPrintUnits();
213
- // this is how pdf.js prints
214
- const printScale = 1;
215
- const { canvasContext, canvas } = this.pdfViewer.createPageElements({
213
+ const { canvasContext, canvas, viewport } = this.pdfViewer.createPageElements({
216
214
  pdfPage: this.pdfPage,
217
- zoom: printScale,
218
215
  printUnits
219
216
  });
220
217
  this.canvasForPrint = canvas;
@@ -226,8 +223,7 @@ export class Page extends Component {
226
223
  });
227
224
  const renderContext = {
228
225
  canvasContext: canvasContext,
229
- transform: [printUnits, 0, 0, printUnits, 0, 0],
230
- viewport: this.pdfPage.getViewport({ scale: printScale, rotation: this.viewport.rotation }),
226
+ viewport: viewport,
231
227
  intent: "print",
232
228
  annotationMode: AnnotationMode.ENABLE_STORAGE,
233
229
  optionalContentConfigPromise,
@@ -59,8 +59,8 @@ export class PdfViewer extends Component {
59
59
  pageChangeScrollThreshold: 0.85,
60
60
  // values higher than 200ms can result in browser zoom
61
61
  pageWheelThrottleDelay: 200,
62
- // ported from pdf.js
63
- printResolution: 100,
62
+ // the print scale that is used for controlling the print quality
63
+ printScale: 3,
64
64
  // the render scale that is used for controlling the render quality
65
65
  renderScale: 3,
66
66
  loadOnDemand: false,
@@ -338,7 +338,20 @@ export class PdfViewer extends Component {
338
338
  return __classPrivateFieldGet(this, _PdfViewer_annotationMode, "f");
339
339
  }
340
340
  getPrintUnits() {
341
- return this.options.printResolution / PixelsPerInch.PDF;
341
+ return this.getPrintScale();
342
+ }
343
+ getPdfToCssUnits() {
344
+ return PixelsPerInch.PDF_TO_CSS_UNITS;
345
+ }
346
+ getPrintScale() {
347
+ return this.getPrintResolution() / PixelsPerInch.PDF;
348
+ }
349
+ getPrintResolution() {
350
+ // the default is 150 in pdf.js, we use 300 to have better DPI by default
351
+ return 100 * this.options.printScale;
352
+ }
353
+ getRenderScale() {
354
+ return getScale(this.options.renderScale);
342
355
  }
343
356
  extendOptions(options) {
344
357
  this.options = deepExtend(this.options, options);
@@ -752,9 +765,9 @@ export class PdfViewer extends Component {
752
765
  if (zoom <= 0) {
753
766
  return;
754
767
  }
755
- let scaleNum = getScale(this.options.renderScale);
768
+ let scaleNum = this.getRenderScale();
756
769
  if (printUnits) {
757
- scaleNum = zoom || scaleNum;
770
+ scaleNum = this.getPrintScale();
758
771
  }
759
772
  // changing the viewport dimensions here requires changes in
760
773
  // page.getPrintContentAsync for the printing dimensions
@@ -769,17 +782,22 @@ export class PdfViewer extends Component {
769
782
  height: `round(var(--scale-factor) * ${viewport.height / scaleNum}px, 1px)`
770
783
  };
771
784
  const pageElement = createElement("div", "k-page", styles);
772
- const canvas = createElement("canvas", '', {
773
- width: "100%",
774
- height: "100%"
775
- });
785
+ const canvas = createElement("canvas", '', {});
776
786
  canvas.height = adjustedHeight;
777
787
  canvas.width = adjustedWidth;
778
788
  if (printUnits) {
779
- canvas.width = Math.floor(canvas.width * (printUnits || 1));
780
- canvas.height = Math.floor(canvas.height * (printUnits || 1));
789
+ canvas.style.width = `${viewport.width / scaleNum}px`;
790
+ canvas.style.height = `${viewport.height / scaleNum}px`;
791
+ }
792
+ else {
793
+ canvas.style.width = "100%";
794
+ canvas.style.height = "100%";
781
795
  }
782
796
  const canvasContext = canvas.getContext("2d");
797
+ if (printUnits) {
798
+ // aim for crisp pixels when printing
799
+ canvasContext.imageSmoothingEnabled = false;
800
+ }
783
801
  const canvasWrapper = convertToHtml(`
784
802
  <div class="${this.options.elementSelectors.pageCanvasWrapper}"></div>
785
803
  `);
@@ -940,6 +958,7 @@ export class PdfViewer extends Component {
940
958
  if (!data) {
941
959
  return;
942
960
  }
961
+ // @ts-ignore
943
962
  return new Blob([data], { type: 'application/pdf' });
944
963
  })
945
964
  .then((blob) => {
@@ -1175,8 +1194,8 @@ export class PdfViewer extends Component {
1175
1194
  }
1176
1195
  openPrintDialog() {
1177
1196
  const pages = this.pages;
1178
- const width = pages[0].rawWidth * this.getPrintUnits();
1179
- const height = pages[0].rawHeight * this.getPrintUnits();
1197
+ const width = pages[0].rawWidth * this.getPdfToCssUnits();
1198
+ const height = pages[0].rawHeight * this.getPdfToCssUnits();
1180
1199
  const printDialog = window.open('', '', 'innerWidth=' + width + ',innerHeight=' + height + 'location=no,titlebar=no,toolbar=no');
1181
1200
  if (!printDialog || !printDialog.document) {
1182
1201
  this.triggerError({
@@ -1195,7 +1214,6 @@ export class PdfViewer extends Component {
1195
1214
  printDialog.print();
1196
1215
  // setTimeout(() => {
1197
1216
  // printDialog.print();
1198
- // done();
1199
1217
  // });
1200
1218
  }
1201
1219
  cacheZoomLevelBeforePrint() {
package/dist/npm/utils.js CHANGED
@@ -74,7 +74,9 @@ const download = (options, fileName = 'Document', saveOptions = {}, onDownload)
74
74
  if (options.pdf) {
75
75
  options.pdf
76
76
  .getData()
77
- .then((data) => new Blob([data], { type: 'application/pdf' }))
77
+ .then((data) =>
78
+ // @ts-ignore
79
+ new Blob([data], { type: 'application/pdf' }))
78
80
  .then((blob) => {
79
81
  if (!onDownload(blob, fileName, saveOptions)) {
80
82
  (0, kendo_file_saver_1.saveAs)(blob, fileName, saveOptions);
@@ -163,8 +163,8 @@ class Page extends component_1.Component {
163
163
  const canvas = this.canvasForPrint;
164
164
  const printContentLoadPromise = this.createPromise();
165
165
  const printContent = new Image();
166
- const pageHeight = canvas.height;
167
- const pageWidth = canvas.width;
166
+ const pageHeight = (canvas.height / this.pdfViewer.getPrintScale()) * this.pdfViewer.getPdfToCssUnits();
167
+ const pageWidth = (canvas.width / this.pdfViewer.getPrintScale()) * this.pdfViewer.getPdfToCssUnits();
168
168
  printContent.src = canvas.toDataURL();
169
169
  printContent.width = pageWidth;
170
170
  printContent.height = pageHeight;
@@ -210,11 +210,8 @@ class Page extends component_1.Component {
210
210
  renderForPrintAsync() {
211
211
  var _a, _b;
212
212
  const printUnits = this.pdfViewer.getPrintUnits();
213
- // this is how pdf.js prints
214
- const printScale = 1;
215
- const { canvasContext, canvas } = this.pdfViewer.createPageElements({
213
+ const { canvasContext, canvas, viewport } = this.pdfViewer.createPageElements({
216
214
  pdfPage: this.pdfPage,
217
- zoom: printScale,
218
215
  printUnits
219
216
  });
220
217
  this.canvasForPrint = canvas;
@@ -226,8 +223,7 @@ class Page extends component_1.Component {
226
223
  });
227
224
  const renderContext = {
228
225
  canvasContext: canvasContext,
229
- transform: [printUnits, 0, 0, printUnits, 0, 0],
230
- viewport: this.pdfPage.getViewport({ scale: printScale, rotation: this.viewport.rotation }),
226
+ viewport: viewport,
231
227
  intent: "print",
232
228
  annotationMode: pdf_mjs_1.AnnotationMode.ENABLE_STORAGE,
233
229
  optionalContentConfigPromise,
@@ -41,6 +41,10 @@ export declare class PdfViewer extends Component {
41
41
  set annotationEditorMode({ mode, editId, isFromKeyboard }: any);
42
42
  getAnnotationMode(): number;
43
43
  getPrintUnits(): number;
44
+ getPdfToCssUnits(): number;
45
+ getPrintScale(): number;
46
+ getPrintResolution(): number;
47
+ getRenderScale(): number;
44
48
  extendOptions(options: any): void;
45
49
  setOptions(options: any): void;
46
50
  bindEvents(): void;
@@ -62,8 +62,8 @@ class PdfViewer extends main_1.Component {
62
62
  pageChangeScrollThreshold: 0.85,
63
63
  // values higher than 200ms can result in browser zoom
64
64
  pageWheelThrottleDelay: 200,
65
- // ported from pdf.js
66
- printResolution: 100,
65
+ // the print scale that is used for controlling the print quality
66
+ printScale: 3,
67
67
  // the render scale that is used for controlling the render quality
68
68
  renderScale: 3,
69
69
  loadOnDemand: false,
@@ -341,7 +341,20 @@ class PdfViewer extends main_1.Component {
341
341
  return tslib_1.__classPrivateFieldGet(this, _PdfViewer_annotationMode, "f");
342
342
  }
343
343
  getPrintUnits() {
344
- return this.options.printResolution / pdf_mjs_1.PixelsPerInch.PDF;
344
+ return this.getPrintScale();
345
+ }
346
+ getPdfToCssUnits() {
347
+ return pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS;
348
+ }
349
+ getPrintScale() {
350
+ return this.getPrintResolution() / pdf_mjs_1.PixelsPerInch.PDF;
351
+ }
352
+ getPrintResolution() {
353
+ // the default is 150 in pdf.js, we use 300 to have better DPI by default
354
+ return 100 * this.options.printScale;
355
+ }
356
+ getRenderScale() {
357
+ return (0, utils_1.scale)(this.options.renderScale);
345
358
  }
346
359
  extendOptions(options) {
347
360
  this.options = (0, main_1.deepExtend)(this.options, options);
@@ -755,9 +768,9 @@ class PdfViewer extends main_1.Component {
755
768
  if (zoom <= 0) {
756
769
  return;
757
770
  }
758
- let scaleNum = (0, utils_1.scale)(this.options.renderScale);
771
+ let scaleNum = this.getRenderScale();
759
772
  if (printUnits) {
760
- scaleNum = zoom || scaleNum;
773
+ scaleNum = this.getPrintScale();
761
774
  }
762
775
  // changing the viewport dimensions here requires changes in
763
776
  // page.getPrintContentAsync for the printing dimensions
@@ -772,17 +785,22 @@ class PdfViewer extends main_1.Component {
772
785
  height: `round(var(--scale-factor) * ${viewport.height / scaleNum}px, 1px)`
773
786
  };
774
787
  const pageElement = (0, utils_1.createElement)("div", "k-page", styles);
775
- const canvas = (0, utils_1.createElement)("canvas", '', {
776
- width: "100%",
777
- height: "100%"
778
- });
788
+ const canvas = (0, utils_1.createElement)("canvas", '', {});
779
789
  canvas.height = adjustedHeight;
780
790
  canvas.width = adjustedWidth;
781
791
  if (printUnits) {
782
- canvas.width = Math.floor(canvas.width * (printUnits || 1));
783
- canvas.height = Math.floor(canvas.height * (printUnits || 1));
792
+ canvas.style.width = `${viewport.width / scaleNum}px`;
793
+ canvas.style.height = `${viewport.height / scaleNum}px`;
794
+ }
795
+ else {
796
+ canvas.style.width = "100%";
797
+ canvas.style.height = "100%";
784
798
  }
785
799
  const canvasContext = canvas.getContext("2d");
800
+ if (printUnits) {
801
+ // aim for crisp pixels when printing
802
+ canvasContext.imageSmoothingEnabled = false;
803
+ }
786
804
  const canvasWrapper = (0, main_1.convertToHtml)(`
787
805
  <div class="${this.options.elementSelectors.pageCanvasWrapper}"></div>
788
806
  `);
@@ -943,6 +961,7 @@ class PdfViewer extends main_1.Component {
943
961
  if (!data) {
944
962
  return;
945
963
  }
964
+ // @ts-ignore
946
965
  return new Blob([data], { type: 'application/pdf' });
947
966
  })
948
967
  .then((blob) => {
@@ -1178,8 +1197,8 @@ class PdfViewer extends main_1.Component {
1178
1197
  }
1179
1198
  openPrintDialog() {
1180
1199
  const pages = this.pages;
1181
- const width = pages[0].rawWidth * this.getPrintUnits();
1182
- const height = pages[0].rawHeight * this.getPrintUnits();
1200
+ const width = pages[0].rawWidth * this.getPdfToCssUnits();
1201
+ const height = pages[0].rawHeight * this.getPdfToCssUnits();
1183
1202
  const printDialog = window.open('', '', 'innerWidth=' + width + ',innerHeight=' + height + 'location=no,titlebar=no,toolbar=no');
1184
1203
  if (!printDialog || !printDialog.document) {
1185
1204
  this.triggerError({
@@ -1198,7 +1217,6 @@ class PdfViewer extends main_1.Component {
1198
1217
  printDialog.print();
1199
1218
  // setTimeout(() => {
1200
1219
  // printDialog.print();
1201
- // done();
1202
1220
  // });
1203
1221
  }
1204
1222
  cacheZoomLevelBeforePrint() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@progress/kendo-pdfviewer-common",
3
3
  "description": "Kendo UI TypeScript package exporting functions for PDFViewer component",
4
- "version": "0.6.0-develop.1",
4
+ "version": "0.6.1-develop.1",
5
5
  "keywords": [
6
6
  "Kendo UI"
7
7
  ],