@pixldocs/canvas-renderer 0.5.207 → 0.5.209

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/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-BqxoYEaM.cjs");
3
+ const index = require("./index-DQF_on2h.cjs");
4
4
  exports.DEPLOYMENT_VERSION_MARKER = index.DEPLOYMENT_VERSION_MARKER;
5
5
  exports.FONT_FALLBACK_DEVANAGARI = index.FONT_FALLBACK_DEVANAGARI;
6
6
  exports.FONT_FALLBACK_MATH = index.FONT_FALLBACK_MATH;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D, F, o, q, s, P, t, u, v, w, x, y, z, B, C, E, G, H, I, J, K, L, M, b, N, O, Q, R, S, U, V, W, X, Y, Z, _, $, a0, a1, a2, a3, a4, a5 } from "./index-D4Dis-kD.js";
1
+ import { D, F, o, q, s, P, t, u, v, w, x, y, z, B, C, E, G, H, I, J, K, L, M, b, N, O, Q, R, S, U, V, W, X, Y, Z, _, $, a0, a1, a2, a3, a4, a5 } from "./index-DOIdbh-Q.js";
2
2
  export {
3
3
  D as DEPLOYMENT_VERSION_MARKER,
4
4
  F as FONT_FALLBACK_DEVANAGARI,
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jspdf = require("jspdf");
4
4
  const svg2pdf_js = require("svg2pdf.js");
5
5
  const fabric = require("fabric");
6
- const index = require("./index-BqxoYEaM.cjs");
6
+ const index = require("./index-DQF_on2h.cjs");
7
7
  const pdfFonts = require("./pdfFonts-BTj2f465.cjs");
8
8
  function _interopNamespaceDefault(e) {
9
9
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -573,23 +573,28 @@ async function rewriteSafariInlineJpegImagesToPng(svg) {
573
573
  if (blobUrl) URL.revokeObjectURL(blobUrl);
574
574
  continue;
575
575
  }
576
- const attrW = parseSvgNumber(image.getAttribute("width")) || loaded.naturalWidth || loaded.width;
577
- const attrH = parseSvgNumber(image.getAttribute("height")) || loaded.naturalHeight || loaded.height;
578
- const transformScale = getApproxSvgTransformScale(image);
579
- const renderedW = attrW * transformScale.x;
580
- const renderedH = attrH * transformScale.y;
581
- const density = 2;
582
- const maxEdge = 1800;
583
- let targetW = Math.max(1, Math.round(Math.min(attrW, renderedW * density || attrW)));
584
- let targetH = Math.max(1, Math.round(Math.min(attrH, renderedH * density || attrH)));
585
- const longest = Math.max(targetW, targetH);
586
- if (longest > maxEdge) {
587
- const scale = maxEdge / longest;
588
- targetW = Math.max(1, Math.round(targetW * scale));
589
- targetH = Math.max(1, Math.round(targetH * scale));
576
+ let targetW = Math.max(1, Math.round(loaded.naturalWidth || loaded.width || parseSvgNumber(image.getAttribute("width")) || 1));
577
+ let targetH = Math.max(1, Math.round(loaded.naturalHeight || loaded.height || parseSvgNumber(image.getAttribute("height")) || 1));
578
+ if (__pdfCompressImages) {
579
+ const attrW = parseSvgNumber(image.getAttribute("width")) || targetW;
580
+ const attrH = parseSvgNumber(image.getAttribute("height")) || targetH;
581
+ const transformScale = getApproxSvgTransformScale(image);
582
+ const renderedW = attrW * transformScale.x;
583
+ const renderedH = attrH * transformScale.y;
584
+ const density = 2;
585
+ const maxEdge = 1800;
586
+ targetW = Math.max(1, Math.round(Math.min(attrW, renderedW * density || attrW)));
587
+ targetH = Math.max(1, Math.round(Math.min(attrH, renderedH * density || attrH)));
588
+ const longest = Math.max(targetW, targetH);
589
+ if (longest > maxEdge) {
590
+ const scale = maxEdge / longest;
591
+ targetW = Math.max(1, Math.round(targetW * scale));
592
+ targetH = Math.max(1, Math.round(targetH * scale));
593
+ }
590
594
  }
595
+ const outputAsPng = __pdfCompressImages;
591
596
  let pngDataUrl = null;
592
- for (const shrink of [1, 0.82, 0.68, 0.55]) {
597
+ for (const shrink of __pdfCompressImages ? [1, 0.82, 0.68, 0.55] : [1]) {
593
598
  const canvas = document.createElement("canvas");
594
599
  canvas.width = Math.max(1, Math.round(targetW * shrink));
595
600
  canvas.height = Math.max(1, Math.round(targetH * shrink));
@@ -598,8 +603,8 @@ async function rewriteSafariInlineJpegImagesToPng(svg) {
598
603
  ctx.fillStyle = "#ffffff";
599
604
  ctx.fillRect(0, 0, canvas.width, canvas.height);
600
605
  ctx.drawImage(loaded, 0, 0, canvas.width, canvas.height);
601
- pngDataUrl = canvas.toDataURL("image/png");
602
- if (estimateDataUrlBytesForPdf(pngDataUrl) <= 4e6 || shrink === 0.55) break;
606
+ pngDataUrl = outputAsPng ? canvas.toDataURL("image/png") : canvas.toDataURL("image/jpeg", 1);
607
+ if (!__pdfCompressImages || estimateDataUrlBytesForPdf(pngDataUrl) <= 4e6 || shrink === 0.55) break;
603
608
  }
604
609
  if (blobUrl) URL.revokeObjectURL(blobUrl);
605
610
  if (!pngDataUrl) continue;
@@ -609,6 +614,98 @@ async function rewriteSafariInlineJpegImagesToPng(svg) {
609
614
  }
610
615
  if (rewritten > 0) console.log(`[client-pdf-export] Safari-safe inline JPEG rewrite: ${rewritten} image(s) converted to PNG inside live SVG`);
611
616
  }
617
+ async function rewriteUnsupportedRasterImagesForSvgPdf(svg) {
618
+ if (typeof document === "undefined") return;
619
+ const images = Array.from(svg.querySelectorAll("image")).filter((image) => {
620
+ const href = getSvgImageHref(image).trim();
621
+ if (!href) return false;
622
+ if (/^data:image\/(?:png|jpe?g|svg\+xml)[;,]/i.test(href)) return false;
623
+ if (/^data:image\//i.test(href)) return true;
624
+ if (/\.svg(?:[?#]|$)/i.test(href)) return false;
625
+ return /\.(?:avif|webp|gif|bmp|heic|heif)(?:[?#]|$)/i.test(href);
626
+ });
627
+ if (images.length === 0) return;
628
+ let rewritten = 0;
629
+ for (const image of images) {
630
+ const href = getSvgImageHref(image).trim();
631
+ try {
632
+ let fetchUrl = href.startsWith("data:") || href.startsWith("blob:") ? href : index.getProxiedImageUrl(href);
633
+ let response = await fetch(fetchUrl, { cache: "no-store", ...index.getImageProxyFetchOptions() });
634
+ if (!response.ok && (href.startsWith("http://") || href.startsWith("https://")) && !fetchUrl.includes("/image-proxy?")) {
635
+ const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
636
+ proxyUrl.searchParams.set("url", href);
637
+ fetchUrl = proxyUrl.toString();
638
+ response = await fetch(fetchUrl, { cache: "no-store", ...index.getImageProxyFetchOptions() });
639
+ }
640
+ if (!response.ok) continue;
641
+ const blob = await response.blob();
642
+ const bitmap = await createImageBitmap(blob);
643
+ let targetW = Math.max(1, Math.round(bitmap.width || parseSvgNumber(image.getAttribute("width")) || 1));
644
+ let targetH = Math.max(1, Math.round(bitmap.height || parseSvgNumber(image.getAttribute("height")) || 1));
645
+ if (__pdfCompressImages) {
646
+ const attrW = parseSvgNumber(image.getAttribute("width")) || targetW;
647
+ const attrH = parseSvgNumber(image.getAttribute("height")) || targetH;
648
+ const transformScale = getApproxSvgTransformScale(image);
649
+ const renderedW = attrW * transformScale.x;
650
+ const renderedH = attrH * transformScale.y;
651
+ const density = 2;
652
+ const maxEdge = 2200;
653
+ targetW = Math.max(1, Math.round(Math.min(bitmap.width || attrW, renderedW * density || attrW)));
654
+ targetH = Math.max(1, Math.round(Math.min(bitmap.height || attrH, renderedH * density || attrH)));
655
+ const longest = Math.max(targetW, targetH);
656
+ if (longest > maxEdge) {
657
+ const scale = maxEdge / longest;
658
+ targetW = Math.max(1, Math.round(targetW * scale));
659
+ targetH = Math.max(1, Math.round(targetH * scale));
660
+ }
661
+ }
662
+ const alphaCanvas = document.createElement("canvas");
663
+ alphaCanvas.width = Math.min(32, targetW);
664
+ alphaCanvas.height = Math.min(32, targetH);
665
+ const alphaCtx = alphaCanvas.getContext("2d");
666
+ let hasAlpha = false;
667
+ if (alphaCtx) {
668
+ alphaCtx.clearRect(0, 0, alphaCanvas.width, alphaCanvas.height);
669
+ alphaCtx.drawImage(bitmap, 0, 0, alphaCanvas.width, alphaCanvas.height);
670
+ const pixels = alphaCtx.getImageData(0, 0, alphaCanvas.width, alphaCanvas.height).data;
671
+ for (let i = 3; i < pixels.length; i += 4) {
672
+ if (pixels[i] !== 255) {
673
+ hasAlpha = true;
674
+ break;
675
+ }
676
+ }
677
+ }
678
+ const canvas = document.createElement("canvas");
679
+ canvas.width = targetW;
680
+ canvas.height = targetH;
681
+ const ctx = canvas.getContext("2d");
682
+ if (!ctx) continue;
683
+ if (!hasAlpha) {
684
+ ctx.fillStyle = "#ffffff";
685
+ ctx.fillRect(0, 0, targetW, targetH);
686
+ } else {
687
+ ctx.clearRect(0, 0, targetW, targetH);
688
+ }
689
+ ctx.imageSmoothingEnabled = true;
690
+ try {
691
+ ctx.imageSmoothingQuality = "high";
692
+ } catch {
693
+ }
694
+ ctx.drawImage(bitmap, 0, 0, targetW, targetH);
695
+ const jpegQuality = __pdfCompressImages ? Math.max(__pdfJpegQuality, 0.6) : 1;
696
+ const safeDataUrl = hasAlpha ? canvas.toDataURL("image/png") : canvas.toDataURL("image/jpeg", jpegQuality);
697
+ image.setAttribute("href", safeDataUrl);
698
+ if (image.hasAttribute("xlink:href")) image.setAttribute("xlink:href", safeDataUrl);
699
+ rewritten++;
700
+ } catch (err) {
701
+ console.warn("[client-pdf-export] failed to rewrite unsupported SVG raster image for PDF", {
702
+ href: href.slice(0, 160),
703
+ error: err instanceof Error ? err.message : String(err)
704
+ });
705
+ }
706
+ }
707
+ if (rewritten > 0) console.log(`[client-pdf-export] PDF-safe raster rewrite: ${rewritten} unsupported image(s) converted inside live SVG`);
708
+ }
612
709
  async function preloadSvgImagesForPdf(svg, options) {
613
710
  const images = Array.from(svg.querySelectorAll("image"));
614
711
  if (!images.length) return;
@@ -651,6 +748,28 @@ async function preloadSvgImagesForPdf(svg, options) {
651
748
  }
652
749
  }
653
750
  }
751
+ async function replaceLiveSvgRasterImagesWithOriginalAssets(svg, originalRasterImagesById) {
752
+ var _a;
753
+ if (__pdfCompressImages || !(originalRasterImagesById == null ? void 0 : originalRasterImagesById.size)) return;
754
+ const images = Array.from(svg.querySelectorAll("image"));
755
+ let replaced = 0;
756
+ for (const image of images) {
757
+ const id = image.getAttribute("data-pixldocs-image-id") || "";
758
+ const originalUrl = id ? originalRasterImagesById.get(id) : void 0;
759
+ if (!originalUrl) continue;
760
+ const currentHref = getSvgImageHref(image).trim();
761
+ if (currentHref === originalUrl) continue;
762
+ const imageData = await fetchImageAsBase64(originalUrl);
763
+ if (!((_a = imageData == null ? void 0 : imageData.data) == null ? void 0 : _a.startsWith("data:image/"))) continue;
764
+ image.setAttribute("href", imageData.data);
765
+ if (image.hasAttribute("xlink:href")) image.setAttribute("xlink:href", imageData.data);
766
+ image.setAttribute("data-pixldocs-original-pdf-asset", imageData.format);
767
+ replaced++;
768
+ }
769
+ if (replaced > 0) {
770
+ console.log(`[client-pdf-export] embedded ${replaced} original raster asset(s) in live SVG PDF path`);
771
+ }
772
+ }
654
773
  function resetPdfColorState(pdf, label) {
655
774
  pdf.setFillColor(0, 0, 0);
656
775
  pdf.setDrawColor(0, 0, 0);
@@ -2075,6 +2194,8 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
2075
2194
  stripRootPageBackgroundFromSvg(svgToDraw);
2076
2195
  }
2077
2196
  sanitizeSvgTreeForPdf(svgToDraw);
2197
+ await replaceLiveSvgRasterImagesWithOriginalAssets(svgToDraw, options == null ? void 0 : options.originalRasterImagesById);
2198
+ await rewriteUnsupportedRasterImagesForSvgPdf(svgToDraw);
2078
2199
  await rewriteSafariInlineJpegImagesToPng(svgToDraw);
2079
2200
  try {
2080
2201
  await logTextMeasurementDiagnostic(svgToDraw);
@@ -2699,7 +2820,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2699
2820
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2700
2821
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2701
2822
  try {
2702
- const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-BqxoYEaM.cjs")).then((n) => n.canvasImageLoader);
2823
+ const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-DQF_on2h.cjs")).then((n) => n.canvasImageLoader);
2703
2824
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2704
2825
  } catch {
2705
2826
  return null;
@@ -3386,6 +3507,17 @@ function drawText(pdf, text, x, y, width, fontSizePx, fontFamily, fontWeight, fo
3386
3507
  }
3387
3508
  }
3388
3509
  }
3510
+ let __pdfCompressImages = true;
3511
+ function __setPdfCompressImages(v) {
3512
+ __pdfCompressImages = v;
3513
+ }
3514
+ let __pdfJpegQuality = 0.82;
3515
+ function __setPdfJpegQuality(v) {
3516
+ if (typeof v === "number" && isFinite(v) && v > 0 && v <= 1) __pdfJpegQuality = v;
3517
+ }
3518
+ function pdfRasterCompression() {
3519
+ return __pdfCompressImages ? "SLOW" : "NONE";
3520
+ }
3389
3521
  function normalizeBgColor(bg) {
3390
3522
  if (!bg || bg === "transparent" || bg === "none") return "#ffffff";
3391
3523
  return bg;
@@ -3431,8 +3563,12 @@ async function detectAlpha(blob) {
3431
3563
  return false;
3432
3564
  }
3433
3565
  function getTargetPixelSize(bitmap, opts) {
3566
+ if (!__pdfCompressImages && !(opts.resolutionMultiplier && opts.resolutionMultiplier > 1)) {
3567
+ return { w: bitmap.width, h: bitmap.height };
3568
+ }
3434
3569
  const dpiScale = 1.5 * (opts.resolutionMultiplier ?? 1);
3435
- const maxPx = opts.resolutionMultiplier && opts.resolutionMultiplier > 1 ? 4400 : 2200;
3570
+ const hasMultiplier = !!(opts.resolutionMultiplier && opts.resolutionMultiplier > 1);
3571
+ const maxPx = !__pdfCompressImages ? 1e4 : hasMultiplier ? 4400 : 2200;
3436
3572
  const capByBitmap = !(opts.resolutionMultiplier && opts.resolutionMultiplier > 1);
3437
3573
  const desiredW = Math.max(1, Math.round((opts.targetWidthPt ?? bitmap.width) * dpiScale));
3438
3574
  const desiredH = Math.max(1, Math.round((opts.targetHeightPt ?? bitmap.height) * dpiScale));
@@ -3462,7 +3598,8 @@ async function rasterizeToDataUrl(blob, opts, out, flattenBackground) {
3462
3598
  }
3463
3599
  ctx.drawImage(bitmap, 0, 0, w, h);
3464
3600
  if (out === "JPEG") {
3465
- return canvas.toDataURL("image/jpeg", 0.82);
3601
+ const quality = __pdfCompressImages ? __pdfJpegQuality : 1;
3602
+ return canvas.toDataURL("image/jpeg", quality);
3466
3603
  }
3467
3604
  return canvas.toDataURL("image/png");
3468
3605
  }
@@ -3490,7 +3627,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3490
3627
  }
3491
3628
  let fetchUrl = imageUrl;
3492
3629
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3493
- const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-BqxoYEaM.cjs")).then((n) => n.canvasImageLoader);
3630
+ const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-DQF_on2h.cjs")).then((n) => n.canvasImageLoader);
3494
3631
  if (isPrivateUrl(imageUrl)) return null;
3495
3632
  const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
3496
3633
  proxyUrl.searchParams.set("url", imageUrl);
@@ -4387,13 +4524,13 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
4387
4524
  anyPdf2.advancedAPI(() => {
4388
4525
  pdf.saveGraphicsState();
4389
4526
  anyPdf2.setCurrentTransformationMatrix(anyPdf2.Matrix(...mPdf));
4390
- pdf.addImage(png, "PNG", localX, localY, frameW, frameH, void 0, "SLOW");
4527
+ pdf.addImage(png, "PNG", localX, localY, frameW, frameH, void 0, pdfRasterCompression());
4391
4528
  pdf.restoreGraphicsState();
4392
4529
  });
4393
4530
  pdf.setGState(pdf.GState({ opacity: 1, "stroke-opacity": 1 }));
4394
4531
  return;
4395
4532
  }
4396
- pdf.addImage(png, "PNG", norm.x, norm.y, frameW, frameH, void 0, "SLOW");
4533
+ pdf.addImage(png, "PNG", norm.x, norm.y, frameW, frameH, void 0, pdfRasterCompression());
4397
4534
  pdf.setGState(pdf.GState({ opacity: 1, "stroke-opacity": 1 }));
4398
4535
  return;
4399
4536
  }
@@ -4514,7 +4651,7 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
4514
4651
  anyPdf.setCurrentTransformationMatrix(anyPdf.Matrix(...mPdf));
4515
4652
  const localX = -intrinsicW / 2;
4516
4653
  const localY = -intrinsicH / 2;
4517
- pdf.addImage(imageData2.data, imageData2.format, localX, localY, intrinsicW, intrinsicH, void 0, "SLOW");
4654
+ pdf.addImage(imageData2.data, imageData2.format, localX, localY, intrinsicW, intrinsicH, void 0, pdfRasterCompression());
4518
4655
  pdf.restoreGraphicsState();
4519
4656
  });
4520
4657
  }
@@ -4541,7 +4678,7 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
4541
4678
  anyPdf.setCurrentTransformationMatrix(anyPdf.Matrix(...mPdf));
4542
4679
  const localX = -intrinsicW / 2;
4543
4680
  const localY = -intrinsicH / 2;
4544
- pdf.addImage(imageData.data, imageData.format, localX, localY, intrinsicW, intrinsicH, void 0, "SLOW");
4681
+ pdf.addImage(imageData.data, imageData.format, localX, localY, intrinsicW, intrinsicH, void 0, pdfRasterCompression());
4545
4682
  pdf.restoreGraphicsState();
4546
4683
  });
4547
4684
  return;
@@ -4901,7 +5038,7 @@ async function drawElementContentCore(pdf, element, norm, x, y, w, h, embeddedFo
4901
5038
  try {
4902
5039
  const fadedCrop = await bakeEdgeFadeIntoDataUrl(croppedPng, element);
4903
5040
  const finalCropPng = fadedCrop || croppedPng;
4904
- pdf.addImage(finalCropPng, "PNG", x, y, w, h, void 0, "SLOW");
5041
+ pdf.addImage(finalCropPng, "PNG", x, y, w, h, void 0, pdfRasterCompression());
4905
5042
  break;
4906
5043
  } catch {
4907
5044
  }
@@ -4948,7 +5085,7 @@ async function drawElementContentCore(pdf, element, norm, x, y, w, h, embeddedFo
4948
5085
  imageData2.format = "PNG";
4949
5086
  }
4950
5087
  try {
4951
- pdf.addImage(imageData2.data, imageData2.format, x, y, w, h, void 0, "SLOW");
5088
+ pdf.addImage(imageData2.data, imageData2.format, x, y, w, h, void 0, pdfRasterCompression());
4952
5089
  } catch {
4953
5090
  }
4954
5091
  }
@@ -4972,7 +5109,7 @@ async function drawElementContentCore(pdf, element, norm, x, y, w, h, embeddedFo
4972
5109
  imageData.format = "PNG";
4973
5110
  }
4974
5111
  try {
4975
- pdf.addImage(imageData.data, imageData.format, x, y, w, h, void 0, "SLOW");
5112
+ pdf.addImage(imageData.data, imageData.format, x, y, w, h, void 0, pdfRasterCompression());
4976
5113
  } catch {
4977
5114
  }
4978
5115
  }
@@ -5106,10 +5243,48 @@ function getExpectedRasterImageIdsForPdfPage(page) {
5106
5243
  }
5107
5244
  return [...new Set(ids)];
5108
5245
  }
5246
+ function getOriginalRasterImageUrlMapForPdfPage(page) {
5247
+ const byId = /* @__PURE__ */ new Map();
5248
+ const isSvgUrl = (url) => /\.svg(?:\?|#|$)/i.test(url) || /^data:image\/svg/i.test(url);
5249
+ for (const item of page.elements) {
5250
+ if (isGroupBackgroundDrawable(item) || item.type !== "image" || item.visible === false) continue;
5251
+ const src = String(item.src || item.imageUrl || "").trim();
5252
+ if (!src || item.sourceFormat === "svg" || isSvgUrl(src)) continue;
5253
+ byId.set(item.id, src);
5254
+ }
5255
+ return byId;
5256
+ }
5109
5257
  async function exportMultiPagePdf(pages, options) {
5110
- var _a, _b, _c, _d, _e, _f, _g;
5111
- const { filename = "document.pdf", title, watermark = false, returnBlob = false, pdfTextMode = "selectable", skipLiveCanvasSvgFastPath = false, useLiveCanvasObjectPdfPath = false } = options;
5258
+ const { filename = "document.pdf", title, watermark = false, returnBlob = false, pdfTextMode = "selectable", skipLiveCanvasSvgFastPath = false, useLiveCanvasObjectPdfPath = false, compressImages = true, compressionQuality } = options;
5112
5259
  pdfFonts.resetPdfFontRegistry();
5260
+ const __prevCompress = __pdfCompressImages;
5261
+ const __prevQuality = __pdfJpegQuality;
5262
+ __pdfCompressImages = compressImages;
5263
+ if (typeof compressionQuality === "number" && isFinite(compressionQuality) && compressionQuality > 0 && compressionQuality <= 1) {
5264
+ __pdfJpegQuality = compressionQuality;
5265
+ }
5266
+ try {
5267
+ return await __exportMultiPagePdfInner(pages, {
5268
+ filename,
5269
+ title,
5270
+ watermark,
5271
+ returnBlob,
5272
+ pdfTextMode,
5273
+ // Keep the SVG fast path even when compression is off — it routes through
5274
+ // fetchImageAsBase64 which preserves JPEG bytes as-is (smallest PDF size).
5275
+ // Forcing the object path here would re-rasterize every image to PNG via
5276
+ // Fabric, ballooning the file size.
5277
+ skipLiveCanvasSvgFastPath,
5278
+ useLiveCanvasObjectPdfPath
5279
+ });
5280
+ } finally {
5281
+ __pdfCompressImages = __prevCompress;
5282
+ __pdfJpegQuality = __prevQuality;
5283
+ }
5284
+ }
5285
+ async function __exportMultiPagePdfInner(pages, options) {
5286
+ var _a, _b, _c, _d, _e, _f, _g;
5287
+ const { filename, title, watermark, returnBlob, pdfTextMode, skipLiveCanvasSvgFastPath, useLiveCanvasObjectPdfPath } = options;
5113
5288
  if (pages.length === 0) {
5114
5289
  throw new Error("No pages to export");
5115
5290
  }
@@ -5120,7 +5295,7 @@ async function exportMultiPagePdf(pages, options) {
5120
5295
  unit: "px",
5121
5296
  format: [firstPage.width, firstPage.height],
5122
5297
  hotfixes: ["px_scaling"],
5123
- compress: true
5298
+ compress: __pdfCompressImages
5124
5299
  });
5125
5300
  if (title) {
5126
5301
  pdf.setProperties({ title, creator: "DocuForge" });
@@ -5285,7 +5460,10 @@ async function exportMultiPagePdf(pages, options) {
5285
5460
  liveSvgWidth,
5286
5461
  liveSvgHeight,
5287
5462
  `page-${pageIndex + 1}`,
5288
- { stripPageBackground: !!page.backgroundGradient }
5463
+ {
5464
+ stripPageBackground: !!page.backgroundGradient,
5465
+ originalRasterImagesById: getOriginalRasterImageUrlMapForPdfPage(page)
5466
+ }
5289
5467
  );
5290
5468
  if (liveSvg) {
5291
5469
  const seq = ++debugSvgDrawSequence;
@@ -5515,6 +5693,8 @@ async function exportMultiPagePdf(pages, options) {
5515
5693
  }
5516
5694
  pdf.save(filename);
5517
5695
  }
5696
+ exports.__setPdfCompressImages = __setPdfCompressImages;
5697
+ exports.__setPdfJpegQuality = __setPdfJpegQuality;
5518
5698
  exports.bakeTextAnchorPositionsFromLiveSvg = bakeTextAnchorPositionsFromLiveSvg;
5519
5699
  exports.convertSvgTextDecorationsToLinesString = convertSvgTextDecorationsToLinesString;
5520
5700
  exports.drawPreparedLiveCanvasSvgPageToPdf = drawPreparedLiveCanvasSvgPageToPdf;
@@ -5524,4 +5704,4 @@ exports.exportMultiPagePdf = exportMultiPagePdf;
5524
5704
  exports.logTextMeasurementDiagnostic = logTextMeasurementDiagnostic;
5525
5705
  exports.preparePagesForExport = preparePagesForExport;
5526
5706
  exports.rewriteSvgFontsForJsPDFWithSourceMeta = rewriteSvgFontsForJsPDFWithSourceMeta;
5527
- //# sourceMappingURL=vectorPdfExport-Cz5kaWEh.cjs.map
5707
+ //# sourceMappingURL=vectorPdfExport-B04JIcJr.cjs.map