@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.
@@ -1,7 +1,7 @@
1
1
  import { jsPDF, ShadingPattern } from "jspdf";
2
2
  import { svg2pdf } from "svg2pdf.js";
3
3
  import * as fabric from "fabric";
4
- import { g as getCanvasForPage, c as captureFabricCanvasSvgForPdf, f as findNodeById, a as getAbsoluteBounds, p as parseTextMarkdown, r as renderSmartElementToSvg, n as normalizeShapeType, h as hasEdgeFade, b as getProxiedImageUrl, d as bakeEdgeFade, i as isElement, e as isGroup, j as buildRoundedTrianglePath, A as API_URL, k as getImageProxyFetchOptions, l as getRoundedRectRadii, T as TRIANGLE_STROKE_MITER_LIMIT, m as getTrianglePoints } from "./index-D4Dis-kD.js";
4
+ import { p as parseTextMarkdown, r as renderSmartElementToSvg, g as getCanvasForPage, c as captureFabricCanvasSvgForPdf, f as findNodeById, a as getAbsoluteBounds, b as getProxiedImageUrl, d as getImageProxyFetchOptions, A as API_URL, n as normalizeShapeType, i as isElement, e as isGroup, h as buildRoundedTrianglePath, j as hasEdgeFade, k as bakeEdgeFade, l as getRoundedRectRadii, T as TRIANGLE_STROKE_MITER_LIMIT, m as getTrianglePoints } from "./index-DOIdbh-Q.js";
5
5
  import { resetPdfFontRegistry, FONT_FALLBACK_SYMBOLS, FONT_FALLBACK_MATH, FONT_FALLBACK_DEVANAGARI, embedFontWithGoogleFallback, getEmbeddedVariantsList, isFontAvailable, isFamilyEmbedded, resolveBestRegisteredVariant, getEmbeddedJsPDFFontName, resolveFontWeight, doesVariantSupportChar } from "./pdfFonts-DhEaMTZl.js";
6
6
  async function embedFontsForSvg(pdf, svgStr) {
7
7
  var _a;
@@ -554,23 +554,28 @@ async function rewriteSafariInlineJpegImagesToPng(svg) {
554
554
  if (blobUrl) URL.revokeObjectURL(blobUrl);
555
555
  continue;
556
556
  }
557
- const attrW = parseSvgNumber(image.getAttribute("width")) || loaded.naturalWidth || loaded.width;
558
- const attrH = parseSvgNumber(image.getAttribute("height")) || loaded.naturalHeight || loaded.height;
559
- const transformScale = getApproxSvgTransformScale(image);
560
- const renderedW = attrW * transformScale.x;
561
- const renderedH = attrH * transformScale.y;
562
- const density = 2;
563
- const maxEdge = 1800;
564
- let targetW = Math.max(1, Math.round(Math.min(attrW, renderedW * density || attrW)));
565
- let targetH = Math.max(1, Math.round(Math.min(attrH, renderedH * density || attrH)));
566
- const longest = Math.max(targetW, targetH);
567
- if (longest > maxEdge) {
568
- const scale = maxEdge / longest;
569
- targetW = Math.max(1, Math.round(targetW * scale));
570
- targetH = Math.max(1, Math.round(targetH * scale));
557
+ let targetW = Math.max(1, Math.round(loaded.naturalWidth || loaded.width || parseSvgNumber(image.getAttribute("width")) || 1));
558
+ let targetH = Math.max(1, Math.round(loaded.naturalHeight || loaded.height || parseSvgNumber(image.getAttribute("height")) || 1));
559
+ if (__pdfCompressImages) {
560
+ const attrW = parseSvgNumber(image.getAttribute("width")) || targetW;
561
+ const attrH = parseSvgNumber(image.getAttribute("height")) || targetH;
562
+ const transformScale = getApproxSvgTransformScale(image);
563
+ const renderedW = attrW * transformScale.x;
564
+ const renderedH = attrH * transformScale.y;
565
+ const density = 2;
566
+ const maxEdge = 1800;
567
+ targetW = Math.max(1, Math.round(Math.min(attrW, renderedW * density || attrW)));
568
+ targetH = Math.max(1, Math.round(Math.min(attrH, renderedH * density || attrH)));
569
+ const longest = Math.max(targetW, targetH);
570
+ if (longest > maxEdge) {
571
+ const scale = maxEdge / longest;
572
+ targetW = Math.max(1, Math.round(targetW * scale));
573
+ targetH = Math.max(1, Math.round(targetH * scale));
574
+ }
571
575
  }
576
+ const outputAsPng = __pdfCompressImages;
572
577
  let pngDataUrl = null;
573
- for (const shrink of [1, 0.82, 0.68, 0.55]) {
578
+ for (const shrink of __pdfCompressImages ? [1, 0.82, 0.68, 0.55] : [1]) {
574
579
  const canvas = document.createElement("canvas");
575
580
  canvas.width = Math.max(1, Math.round(targetW * shrink));
576
581
  canvas.height = Math.max(1, Math.round(targetH * shrink));
@@ -579,8 +584,8 @@ async function rewriteSafariInlineJpegImagesToPng(svg) {
579
584
  ctx.fillStyle = "#ffffff";
580
585
  ctx.fillRect(0, 0, canvas.width, canvas.height);
581
586
  ctx.drawImage(loaded, 0, 0, canvas.width, canvas.height);
582
- pngDataUrl = canvas.toDataURL("image/png");
583
- if (estimateDataUrlBytesForPdf(pngDataUrl) <= 4e6 || shrink === 0.55) break;
587
+ pngDataUrl = outputAsPng ? canvas.toDataURL("image/png") : canvas.toDataURL("image/jpeg", 1);
588
+ if (!__pdfCompressImages || estimateDataUrlBytesForPdf(pngDataUrl) <= 4e6 || shrink === 0.55) break;
584
589
  }
585
590
  if (blobUrl) URL.revokeObjectURL(blobUrl);
586
591
  if (!pngDataUrl) continue;
@@ -590,6 +595,98 @@ async function rewriteSafariInlineJpegImagesToPng(svg) {
590
595
  }
591
596
  if (rewritten > 0) console.log(`[client-pdf-export] Safari-safe inline JPEG rewrite: ${rewritten} image(s) converted to PNG inside live SVG`);
592
597
  }
598
+ async function rewriteUnsupportedRasterImagesForSvgPdf(svg) {
599
+ if (typeof document === "undefined") return;
600
+ const images = Array.from(svg.querySelectorAll("image")).filter((image) => {
601
+ const href = getSvgImageHref(image).trim();
602
+ if (!href) return false;
603
+ if (/^data:image\/(?:png|jpe?g|svg\+xml)[;,]/i.test(href)) return false;
604
+ if (/^data:image\//i.test(href)) return true;
605
+ if (/\.svg(?:[?#]|$)/i.test(href)) return false;
606
+ return /\.(?:avif|webp|gif|bmp|heic|heif)(?:[?#]|$)/i.test(href);
607
+ });
608
+ if (images.length === 0) return;
609
+ let rewritten = 0;
610
+ for (const image of images) {
611
+ const href = getSvgImageHref(image).trim();
612
+ try {
613
+ let fetchUrl = href.startsWith("data:") || href.startsWith("blob:") ? href : getProxiedImageUrl(href);
614
+ let response = await fetch(fetchUrl, { cache: "no-store", ...getImageProxyFetchOptions() });
615
+ if (!response.ok && (href.startsWith("http://") || href.startsWith("https://")) && !fetchUrl.includes("/image-proxy?")) {
616
+ const proxyUrl = new URL(`${API_URL}/image-proxy`);
617
+ proxyUrl.searchParams.set("url", href);
618
+ fetchUrl = proxyUrl.toString();
619
+ response = await fetch(fetchUrl, { cache: "no-store", ...getImageProxyFetchOptions() });
620
+ }
621
+ if (!response.ok) continue;
622
+ const blob = await response.blob();
623
+ const bitmap = await createImageBitmap(blob);
624
+ let targetW = Math.max(1, Math.round(bitmap.width || parseSvgNumber(image.getAttribute("width")) || 1));
625
+ let targetH = Math.max(1, Math.round(bitmap.height || parseSvgNumber(image.getAttribute("height")) || 1));
626
+ if (__pdfCompressImages) {
627
+ const attrW = parseSvgNumber(image.getAttribute("width")) || targetW;
628
+ const attrH = parseSvgNumber(image.getAttribute("height")) || targetH;
629
+ const transformScale = getApproxSvgTransformScale(image);
630
+ const renderedW = attrW * transformScale.x;
631
+ const renderedH = attrH * transformScale.y;
632
+ const density = 2;
633
+ const maxEdge = 2200;
634
+ targetW = Math.max(1, Math.round(Math.min(bitmap.width || attrW, renderedW * density || attrW)));
635
+ targetH = Math.max(1, Math.round(Math.min(bitmap.height || attrH, renderedH * density || attrH)));
636
+ const longest = Math.max(targetW, targetH);
637
+ if (longest > maxEdge) {
638
+ const scale = maxEdge / longest;
639
+ targetW = Math.max(1, Math.round(targetW * scale));
640
+ targetH = Math.max(1, Math.round(targetH * scale));
641
+ }
642
+ }
643
+ const alphaCanvas = document.createElement("canvas");
644
+ alphaCanvas.width = Math.min(32, targetW);
645
+ alphaCanvas.height = Math.min(32, targetH);
646
+ const alphaCtx = alphaCanvas.getContext("2d");
647
+ let hasAlpha = false;
648
+ if (alphaCtx) {
649
+ alphaCtx.clearRect(0, 0, alphaCanvas.width, alphaCanvas.height);
650
+ alphaCtx.drawImage(bitmap, 0, 0, alphaCanvas.width, alphaCanvas.height);
651
+ const pixels = alphaCtx.getImageData(0, 0, alphaCanvas.width, alphaCanvas.height).data;
652
+ for (let i = 3; i < pixels.length; i += 4) {
653
+ if (pixels[i] !== 255) {
654
+ hasAlpha = true;
655
+ break;
656
+ }
657
+ }
658
+ }
659
+ const canvas = document.createElement("canvas");
660
+ canvas.width = targetW;
661
+ canvas.height = targetH;
662
+ const ctx = canvas.getContext("2d");
663
+ if (!ctx) continue;
664
+ if (!hasAlpha) {
665
+ ctx.fillStyle = "#ffffff";
666
+ ctx.fillRect(0, 0, targetW, targetH);
667
+ } else {
668
+ ctx.clearRect(0, 0, targetW, targetH);
669
+ }
670
+ ctx.imageSmoothingEnabled = true;
671
+ try {
672
+ ctx.imageSmoothingQuality = "high";
673
+ } catch {
674
+ }
675
+ ctx.drawImage(bitmap, 0, 0, targetW, targetH);
676
+ const jpegQuality = __pdfCompressImages ? Math.max(__pdfJpegQuality, 0.6) : 1;
677
+ const safeDataUrl = hasAlpha ? canvas.toDataURL("image/png") : canvas.toDataURL("image/jpeg", jpegQuality);
678
+ image.setAttribute("href", safeDataUrl);
679
+ if (image.hasAttribute("xlink:href")) image.setAttribute("xlink:href", safeDataUrl);
680
+ rewritten++;
681
+ } catch (err) {
682
+ console.warn("[client-pdf-export] failed to rewrite unsupported SVG raster image for PDF", {
683
+ href: href.slice(0, 160),
684
+ error: err instanceof Error ? err.message : String(err)
685
+ });
686
+ }
687
+ }
688
+ if (rewritten > 0) console.log(`[client-pdf-export] PDF-safe raster rewrite: ${rewritten} unsupported image(s) converted inside live SVG`);
689
+ }
593
690
  async function preloadSvgImagesForPdf(svg, options) {
594
691
  const images = Array.from(svg.querySelectorAll("image"));
595
692
  if (!images.length) return;
@@ -632,6 +729,28 @@ async function preloadSvgImagesForPdf(svg, options) {
632
729
  }
633
730
  }
634
731
  }
732
+ async function replaceLiveSvgRasterImagesWithOriginalAssets(svg, originalRasterImagesById) {
733
+ var _a;
734
+ if (__pdfCompressImages || !(originalRasterImagesById == null ? void 0 : originalRasterImagesById.size)) return;
735
+ const images = Array.from(svg.querySelectorAll("image"));
736
+ let replaced = 0;
737
+ for (const image of images) {
738
+ const id = image.getAttribute("data-pixldocs-image-id") || "";
739
+ const originalUrl = id ? originalRasterImagesById.get(id) : void 0;
740
+ if (!originalUrl) continue;
741
+ const currentHref = getSvgImageHref(image).trim();
742
+ if (currentHref === originalUrl) continue;
743
+ const imageData = await fetchImageAsBase64(originalUrl);
744
+ if (!((_a = imageData == null ? void 0 : imageData.data) == null ? void 0 : _a.startsWith("data:image/"))) continue;
745
+ image.setAttribute("href", imageData.data);
746
+ if (image.hasAttribute("xlink:href")) image.setAttribute("xlink:href", imageData.data);
747
+ image.setAttribute("data-pixldocs-original-pdf-asset", imageData.format);
748
+ replaced++;
749
+ }
750
+ if (replaced > 0) {
751
+ console.log(`[client-pdf-export] embedded ${replaced} original raster asset(s) in live SVG PDF path`);
752
+ }
753
+ }
635
754
  function resetPdfColorState(pdf, label) {
636
755
  pdf.setFillColor(0, 0, 0);
637
756
  pdf.setDrawColor(0, 0, 0);
@@ -2056,6 +2175,8 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
2056
2175
  stripRootPageBackgroundFromSvg(svgToDraw);
2057
2176
  }
2058
2177
  sanitizeSvgTreeForPdf(svgToDraw);
2178
+ await replaceLiveSvgRasterImagesWithOriginalAssets(svgToDraw, options == null ? void 0 : options.originalRasterImagesById);
2179
+ await rewriteUnsupportedRasterImagesForSvgPdf(svgToDraw);
2059
2180
  await rewriteSafariInlineJpegImagesToPng(svgToDraw);
2060
2181
  try {
2061
2182
  await logTextMeasurementDiagnostic(svgToDraw);
@@ -2680,7 +2801,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2680
2801
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2681
2802
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2682
2803
  try {
2683
- const { getNormalizedSvgUrl } = await import("./index-D4Dis-kD.js").then((n) => n.a6);
2804
+ const { getNormalizedSvgUrl } = await import("./index-DOIdbh-Q.js").then((n) => n.a6);
2684
2805
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2685
2806
  } catch {
2686
2807
  return null;
@@ -3367,6 +3488,17 @@ function drawText(pdf, text, x, y, width, fontSizePx, fontFamily, fontWeight, fo
3367
3488
  }
3368
3489
  }
3369
3490
  }
3491
+ let __pdfCompressImages = true;
3492
+ function __setPdfCompressImages(v) {
3493
+ __pdfCompressImages = v;
3494
+ }
3495
+ let __pdfJpegQuality = 0.82;
3496
+ function __setPdfJpegQuality(v) {
3497
+ if (typeof v === "number" && isFinite(v) && v > 0 && v <= 1) __pdfJpegQuality = v;
3498
+ }
3499
+ function pdfRasterCompression() {
3500
+ return __pdfCompressImages ? "SLOW" : "NONE";
3501
+ }
3370
3502
  function normalizeBgColor(bg) {
3371
3503
  if (!bg || bg === "transparent" || bg === "none") return "#ffffff";
3372
3504
  return bg;
@@ -3412,8 +3544,12 @@ async function detectAlpha(blob) {
3412
3544
  return false;
3413
3545
  }
3414
3546
  function getTargetPixelSize(bitmap, opts) {
3547
+ if (!__pdfCompressImages && !(opts.resolutionMultiplier && opts.resolutionMultiplier > 1)) {
3548
+ return { w: bitmap.width, h: bitmap.height };
3549
+ }
3415
3550
  const dpiScale = 1.5 * (opts.resolutionMultiplier ?? 1);
3416
- const maxPx = opts.resolutionMultiplier && opts.resolutionMultiplier > 1 ? 4400 : 2200;
3551
+ const hasMultiplier = !!(opts.resolutionMultiplier && opts.resolutionMultiplier > 1);
3552
+ const maxPx = !__pdfCompressImages ? 1e4 : hasMultiplier ? 4400 : 2200;
3417
3553
  const capByBitmap = !(opts.resolutionMultiplier && opts.resolutionMultiplier > 1);
3418
3554
  const desiredW = Math.max(1, Math.round((opts.targetWidthPt ?? bitmap.width) * dpiScale));
3419
3555
  const desiredH = Math.max(1, Math.round((opts.targetHeightPt ?? bitmap.height) * dpiScale));
@@ -3443,7 +3579,8 @@ async function rasterizeToDataUrl(blob, opts, out, flattenBackground) {
3443
3579
  }
3444
3580
  ctx.drawImage(bitmap, 0, 0, w, h);
3445
3581
  if (out === "JPEG") {
3446
- return canvas.toDataURL("image/jpeg", 0.82);
3582
+ const quality = __pdfCompressImages ? __pdfJpegQuality : 1;
3583
+ return canvas.toDataURL("image/jpeg", quality);
3447
3584
  }
3448
3585
  return canvas.toDataURL("image/png");
3449
3586
  }
@@ -3471,7 +3608,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3471
3608
  }
3472
3609
  let fetchUrl = imageUrl;
3473
3610
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3474
- const { isPrivateUrl } = await import("./index-D4Dis-kD.js").then((n) => n.a6);
3611
+ const { isPrivateUrl } = await import("./index-DOIdbh-Q.js").then((n) => n.a6);
3475
3612
  if (isPrivateUrl(imageUrl)) return null;
3476
3613
  const proxyUrl = new URL(`${API_URL}/image-proxy`);
3477
3614
  proxyUrl.searchParams.set("url", imageUrl);
@@ -4368,13 +4505,13 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
4368
4505
  anyPdf2.advancedAPI(() => {
4369
4506
  pdf.saveGraphicsState();
4370
4507
  anyPdf2.setCurrentTransformationMatrix(anyPdf2.Matrix(...mPdf));
4371
- pdf.addImage(png, "PNG", localX, localY, frameW, frameH, void 0, "SLOW");
4508
+ pdf.addImage(png, "PNG", localX, localY, frameW, frameH, void 0, pdfRasterCompression());
4372
4509
  pdf.restoreGraphicsState();
4373
4510
  });
4374
4511
  pdf.setGState(pdf.GState({ opacity: 1, "stroke-opacity": 1 }));
4375
4512
  return;
4376
4513
  }
4377
- pdf.addImage(png, "PNG", norm.x, norm.y, frameW, frameH, void 0, "SLOW");
4514
+ pdf.addImage(png, "PNG", norm.x, norm.y, frameW, frameH, void 0, pdfRasterCompression());
4378
4515
  pdf.setGState(pdf.GState({ opacity: 1, "stroke-opacity": 1 }));
4379
4516
  return;
4380
4517
  }
@@ -4495,7 +4632,7 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
4495
4632
  anyPdf.setCurrentTransformationMatrix(anyPdf.Matrix(...mPdf));
4496
4633
  const localX = -intrinsicW / 2;
4497
4634
  const localY = -intrinsicH / 2;
4498
- pdf.addImage(imageData2.data, imageData2.format, localX, localY, intrinsicW, intrinsicH, void 0, "SLOW");
4635
+ pdf.addImage(imageData2.data, imageData2.format, localX, localY, intrinsicW, intrinsicH, void 0, pdfRasterCompression());
4499
4636
  pdf.restoreGraphicsState();
4500
4637
  });
4501
4638
  }
@@ -4522,7 +4659,7 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
4522
4659
  anyPdf.setCurrentTransformationMatrix(anyPdf.Matrix(...mPdf));
4523
4660
  const localX = -intrinsicW / 2;
4524
4661
  const localY = -intrinsicH / 2;
4525
- pdf.addImage(imageData.data, imageData.format, localX, localY, intrinsicW, intrinsicH, void 0, "SLOW");
4662
+ pdf.addImage(imageData.data, imageData.format, localX, localY, intrinsicW, intrinsicH, void 0, pdfRasterCompression());
4526
4663
  pdf.restoreGraphicsState();
4527
4664
  });
4528
4665
  return;
@@ -4882,7 +5019,7 @@ async function drawElementContentCore(pdf, element, norm, x, y, w, h, embeddedFo
4882
5019
  try {
4883
5020
  const fadedCrop = await bakeEdgeFadeIntoDataUrl(croppedPng, element);
4884
5021
  const finalCropPng = fadedCrop || croppedPng;
4885
- pdf.addImage(finalCropPng, "PNG", x, y, w, h, void 0, "SLOW");
5022
+ pdf.addImage(finalCropPng, "PNG", x, y, w, h, void 0, pdfRasterCompression());
4886
5023
  break;
4887
5024
  } catch {
4888
5025
  }
@@ -4929,7 +5066,7 @@ async function drawElementContentCore(pdf, element, norm, x, y, w, h, embeddedFo
4929
5066
  imageData2.format = "PNG";
4930
5067
  }
4931
5068
  try {
4932
- pdf.addImage(imageData2.data, imageData2.format, x, y, w, h, void 0, "SLOW");
5069
+ pdf.addImage(imageData2.data, imageData2.format, x, y, w, h, void 0, pdfRasterCompression());
4933
5070
  } catch {
4934
5071
  }
4935
5072
  }
@@ -4953,7 +5090,7 @@ async function drawElementContentCore(pdf, element, norm, x, y, w, h, embeddedFo
4953
5090
  imageData.format = "PNG";
4954
5091
  }
4955
5092
  try {
4956
- pdf.addImage(imageData.data, imageData.format, x, y, w, h, void 0, "SLOW");
5093
+ pdf.addImage(imageData.data, imageData.format, x, y, w, h, void 0, pdfRasterCompression());
4957
5094
  } catch {
4958
5095
  }
4959
5096
  }
@@ -5087,10 +5224,48 @@ function getExpectedRasterImageIdsForPdfPage(page) {
5087
5224
  }
5088
5225
  return [...new Set(ids)];
5089
5226
  }
5227
+ function getOriginalRasterImageUrlMapForPdfPage(page) {
5228
+ const byId = /* @__PURE__ */ new Map();
5229
+ const isSvgUrl = (url) => /\.svg(?:\?|#|$)/i.test(url) || /^data:image\/svg/i.test(url);
5230
+ for (const item of page.elements) {
5231
+ if (isGroupBackgroundDrawable(item) || item.type !== "image" || item.visible === false) continue;
5232
+ const src = String(item.src || item.imageUrl || "").trim();
5233
+ if (!src || item.sourceFormat === "svg" || isSvgUrl(src)) continue;
5234
+ byId.set(item.id, src);
5235
+ }
5236
+ return byId;
5237
+ }
5090
5238
  async function exportMultiPagePdf(pages, options) {
5091
- var _a, _b, _c, _d, _e, _f, _g;
5092
- const { filename = "document.pdf", title, watermark = false, returnBlob = false, pdfTextMode = "selectable", skipLiveCanvasSvgFastPath = false, useLiveCanvasObjectPdfPath = false } = options;
5239
+ const { filename = "document.pdf", title, watermark = false, returnBlob = false, pdfTextMode = "selectable", skipLiveCanvasSvgFastPath = false, useLiveCanvasObjectPdfPath = false, compressImages = true, compressionQuality } = options;
5093
5240
  resetPdfFontRegistry();
5241
+ const __prevCompress = __pdfCompressImages;
5242
+ const __prevQuality = __pdfJpegQuality;
5243
+ __pdfCompressImages = compressImages;
5244
+ if (typeof compressionQuality === "number" && isFinite(compressionQuality) && compressionQuality > 0 && compressionQuality <= 1) {
5245
+ __pdfJpegQuality = compressionQuality;
5246
+ }
5247
+ try {
5248
+ return await __exportMultiPagePdfInner(pages, {
5249
+ filename,
5250
+ title,
5251
+ watermark,
5252
+ returnBlob,
5253
+ pdfTextMode,
5254
+ // Keep the SVG fast path even when compression is off — it routes through
5255
+ // fetchImageAsBase64 which preserves JPEG bytes as-is (smallest PDF size).
5256
+ // Forcing the object path here would re-rasterize every image to PNG via
5257
+ // Fabric, ballooning the file size.
5258
+ skipLiveCanvasSvgFastPath,
5259
+ useLiveCanvasObjectPdfPath
5260
+ });
5261
+ } finally {
5262
+ __pdfCompressImages = __prevCompress;
5263
+ __pdfJpegQuality = __prevQuality;
5264
+ }
5265
+ }
5266
+ async function __exportMultiPagePdfInner(pages, options) {
5267
+ var _a, _b, _c, _d, _e, _f, _g;
5268
+ const { filename, title, watermark, returnBlob, pdfTextMode, skipLiveCanvasSvgFastPath, useLiveCanvasObjectPdfPath } = options;
5094
5269
  if (pages.length === 0) {
5095
5270
  throw new Error("No pages to export");
5096
5271
  }
@@ -5101,7 +5276,7 @@ async function exportMultiPagePdf(pages, options) {
5101
5276
  unit: "px",
5102
5277
  format: [firstPage.width, firstPage.height],
5103
5278
  hotfixes: ["px_scaling"],
5104
- compress: true
5279
+ compress: __pdfCompressImages
5105
5280
  });
5106
5281
  if (title) {
5107
5282
  pdf.setProperties({ title, creator: "DocuForge" });
@@ -5266,7 +5441,10 @@ async function exportMultiPagePdf(pages, options) {
5266
5441
  liveSvgWidth,
5267
5442
  liveSvgHeight,
5268
5443
  `page-${pageIndex + 1}`,
5269
- { stripPageBackground: !!page.backgroundGradient }
5444
+ {
5445
+ stripPageBackground: !!page.backgroundGradient,
5446
+ originalRasterImagesById: getOriginalRasterImageUrlMapForPdfPage(page)
5447
+ }
5270
5448
  );
5271
5449
  if (liveSvg) {
5272
5450
  const seq = ++debugSvgDrawSequence;
@@ -5497,6 +5675,8 @@ async function exportMultiPagePdf(pages, options) {
5497
5675
  pdf.save(filename);
5498
5676
  }
5499
5677
  export {
5678
+ __setPdfCompressImages,
5679
+ __setPdfJpegQuality,
5500
5680
  bakeTextAnchorPositionsFromLiveSvg,
5501
5681
  convertSvgTextDecorationsToLinesString,
5502
5682
  drawPreparedLiveCanvasSvgPageToPdf,
@@ -5507,4 +5687,4 @@ export {
5507
5687
  preparePagesForExport,
5508
5688
  rewriteSvgFontsForJsPDFWithSourceMeta
5509
5689
  };
5510
- //# sourceMappingURL=vectorPdfExport-HZVoeZf3.js.map
5690
+ //# sourceMappingURL=vectorPdfExport-C0GsER0C.js.map