@embedpdf/engines 1.0.4 → 1.0.5

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.
@@ -267,7 +267,7 @@ var PdfiumErrorCode;
267
267
  PdfiumErrorCode[PdfiumErrorCode["XFALoad"] = 7] = "XFALoad";
268
268
  PdfiumErrorCode[PdfiumErrorCode["XFALayout"] = 8] = "XFALayout";
269
269
  })(PdfiumErrorCode || (PdfiumErrorCode = {}));
270
- const browserImageDataToBlobConverter = (pdfImageData) => {
270
+ const browserImageDataToBlobConverter = (pdfImageData, imageType = 'image/webp') => {
271
271
  // Check if we're in a browser environment
272
272
  if (typeof OffscreenCanvas === 'undefined') {
273
273
  throw new Error('OffscreenCanvas is not available in this environment. ' +
@@ -277,7 +277,7 @@ const browserImageDataToBlobConverter = (pdfImageData) => {
277
277
  const imageData = new ImageData(pdfImageData.data, pdfImageData.width, pdfImageData.height);
278
278
  const off = new OffscreenCanvas(imageData.width, imageData.height);
279
279
  off.getContext('2d').putImageData(imageData, 0, 0);
280
- return off.convertToBlob({ type: 'image/webp' });
280
+ return off.convertToBlob({ type: imageType });
281
281
  };
282
282
  /**
283
283
  * Pdf engine that based on pdfium wasm
@@ -783,7 +783,7 @@ class PdfiumEngine {
783
783
  *
784
784
  * @public
785
785
  */
786
- renderPage(doc, page, scaleFactor = 1, rotation = models.Rotation.Degree0, dpr = 1, options = { withAnnotations: false }) {
786
+ renderPage(doc, page, scaleFactor = 1, rotation = models.Rotation.Degree0, dpr = 1, options = { withAnnotations: false }, imageType = 'image/webp') {
787
787
  const task = new models.Task();
788
788
  this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderPage', doc, page, scaleFactor, rotation, dpr, options);
789
789
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPage`, 'Begin', `${doc.id}-${page.index}`);
@@ -800,7 +800,7 @@ class PdfiumEngine {
800
800
  size: page.size,
801
801
  }, scaleFactor, rotation, dpr, options);
802
802
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPage`, 'End', `${doc.id}-${page.index}`);
803
- this.imageDataConverter(imageData).then((blob) => task.resolve(blob));
803
+ this.imageDataConverter(imageData, imageType).then((blob) => task.resolve(blob));
804
804
  return task;
805
805
  }
806
806
  /**
@@ -808,7 +808,7 @@ class PdfiumEngine {
808
808
  *
809
809
  * @public
810
810
  */
811
- renderPageRect(doc, page, scaleFactor, rotation, dpr, rect, options) {
811
+ renderPageRect(doc, page, scaleFactor, rotation, dpr, rect, options, imageType = 'image/webp') {
812
812
  const task = new models.Task();
813
813
  this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderPageRect', doc, page, scaleFactor, rotation, dpr, rect, options);
814
814
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPageRect`, 'Begin', `${doc.id}-${page.index}`);
@@ -822,7 +822,7 @@ class PdfiumEngine {
822
822
  }
823
823
  const imageData = this.renderPageRectToImageData(ctx, page, rect, scaleFactor, rotation, dpr, options);
824
824
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPageRect`, 'End', `${doc.id}-${page.index}`);
825
- this.imageDataConverter(imageData).then((blob) => task.resolve(blob));
825
+ this.imageDataConverter(imageData, imageType).then((blob) => task.resolve(blob));
826
826
  return task;
827
827
  }
828
828
  /**