jspdf-utils 0.3.0 → 0.4.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.
@@ -4,6 +4,7 @@
4
4
  * Helpers that prepare an HTML element for clean, paginated PDF output
5
5
  * via jsPDF's doc.html() renderer.
6
6
  */
7
+ import { type Options as Html2CanvasOptions } from "html2canvas-pro";
7
8
  import jsPDF from "jspdf-with-html2canvas-pro";
8
9
  export interface Margin {
9
10
  top: number;
@@ -48,7 +49,7 @@ export interface PrepareResult {
48
49
  /**
49
50
  * Render an HTML element to PDF using doc.html().
50
51
  */
51
- declare function generatePDF(doc: jsPDF, source: HTMLElement, opts?: PageOptionsInput & Pick<ImagePDFOptions, "marginContent" | "forcedPageCount" | "textBorder" | "border">): Promise<jsPDF>;
52
+ declare function generatePDF(doc: jsPDF, source: HTMLElement, opts?: PageOptionsInput & Pick<ImagePDFOptions, "marginContent" | "forcedPageCount" | "textBorder" | "border" | "html2canvasOptions">): Promise<jsPDF>;
52
53
  type MarginResult = HTMLElement | string | null | undefined | void;
53
54
  type MarginFactory = (page: number, totalPages: number) => MarginResult;
54
55
  export interface Border {
@@ -112,6 +113,13 @@ export interface ImagePDFOptions {
112
113
  * Example: 1 means only page 1 is generated/exported.
113
114
  */
114
115
  forcedPageCount?: number;
116
+ /**
117
+ * Options forwarded directly to html2canvas-pro. Anything supported by
118
+ * html2canvas (e.g. `foreignObjectRendering`, `useCORS`, `proxy`,
119
+ * `windowWidth`, `logging`) can be set here. Note that `scale` and
120
+ * `backgroundColor` are controlled by this library and will be overridden.
121
+ */
122
+ html2canvasOptions?: Partial<Html2CanvasOptions>;
115
123
  }
116
124
  /**
117
125
  * Render an HTML element as an image-based PDF. Each page is a rasterized
@@ -124,9 +132,17 @@ declare function generateImagePDF(source: HTMLElement, opts?: PageOptionsInput &
124
132
  * visual output of renderImagePDF.
125
133
  */
126
134
  declare function generateImages(source: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions): Promise<string[]>;
135
+ export interface PreviewOptions {
136
+ /**
137
+ * Height of the preview container. A number is treated as pixels;
138
+ * a string is used verbatim (e.g. "400px", "60vh", "30rem").
139
+ * Defaults to one full page height (`pageHeight` in mm).
140
+ */
141
+ containerHeight?: number | string;
142
+ }
127
143
  /**
128
144
  * Render an HTML element as page images and inject them into a scrollable
129
145
  * container. Each image is sized to match the page format dimensions.
130
146
  */
131
- declare function previewImages(source: HTMLElement, container: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions): Promise<void>;
147
+ declare function previewImages(source: HTMLElement, container: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions & PreviewOptions): Promise<void>;
132
148
  export { PAGE_SIZES, PAGE_MARGINS, generatePDF, generateImagePDF, generateImages, previewImages, };
@@ -5497,7 +5497,11 @@ async function Rg(t, A, e = {}) {
5497
5497
  n.margin.right,
5498
5498
  n.margin.bottom,
5499
5499
  n.margin.left
5500
- ]
5500
+ ],
5501
+ // jspdf's bundled html2canvas type is older than html2canvas-pro's
5502
+ // (e.g. onclone signature differs). The runtime call forwards
5503
+ // identically, so cast through unknown.
5504
+ html2canvas: e.html2canvasOptions
5501
5505
  });
5502
5506
  });
5503
5507
  } finally {
@@ -5893,6 +5897,7 @@ async function Gg(t, A = {}) {
5893
5897
  );
5894
5898
  try {
5895
5899
  const a = await ae(o, {
5900
+ ...A.html2canvasOptions,
5896
5901
  scale: s,
5897
5902
  backgroundColor: null
5898
5903
  }), { jsPDF: c } = await import("./jspdf.es.min-BDu0IqVE.js").then((p) => p.j), l = Jn(a, n, B, s), g = Math.ceil(a.height / l.contentHeightPx), Q = _n(
@@ -5948,6 +5953,7 @@ async function Mg(t, A = {}) {
5948
5953
  );
5949
5954
  try {
5950
5955
  const a = await ae(o, {
5956
+ ...A.html2canvasOptions,
5951
5957
  scale: s,
5952
5958
  backgroundColor: null
5953
5959
  }), c = Jn(a, n, B, s), l = Math.ceil(a.height / c.contentHeightPx), g = _n(
@@ -5984,20 +5990,22 @@ async function Mg(t, A = {}) {
5984
5990
  }
5985
5991
  }
5986
5992
  async function Ng(t, A, e = {}) {
5987
- const r = le(e), s = await Mg(t, e);
5993
+ const r = le(e), s = await Mg(t, e), n = e.containerHeight == null ? r.pageHeight + "mm" : typeof e.containerHeight == "number" ? e.containerHeight + "px" : e.containerHeight;
5988
5994
  A.innerHTML = "", Object.assign(A.style, {
5989
5995
  display: "flex",
5990
5996
  flexDirection: "column",
5991
5997
  direction: "ltr",
5992
5998
  width: "fit-content",
5993
- height: r.pageHeight + "mm",
5994
- maxHeight: "100vh",
5995
- overflowY: s.length > 1 ? "auto" : "hidden",
5999
+ height: n,
6000
+ maxHeight: n,
6001
+ // When the caller fixes the height, content may overflow even with a
6002
+ // single page, so always allow scrolling in that case.
6003
+ overflowY: e.containerHeight != null || s.length > 1 ? "auto" : "hidden",
5996
6004
  background: "#e0e0e0"
5997
6005
  });
5998
- for (let n = 0; n < s.length; n++) {
5999
- const o = document.createElement("img");
6000
- o.src = s[n], o.alt = `Page ${n + 1}`, Object.assign(o.style, {
6006
+ for (let o = 0; o < s.length; o++) {
6007
+ const B = document.createElement("img");
6008
+ B.src = s[o], B.alt = `Page ${o + 1}`, Object.assign(B.style, {
6001
6009
  width: r.pageWidth + "mm",
6002
6010
  maxWidth: "100%",
6003
6011
  height: "auto",
@@ -6005,7 +6013,7 @@ async function Ng(t, A, e = {}) {
6005
6013
  border: "1px solid #bbb",
6006
6014
  boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
6007
6015
  marginBottom: "16px"
6008
- }), o.style.setProperty("display", "inline", "important"), A.appendChild(o);
6016
+ }), B.style.setProperty("display", "inline", "important"), A.appendChild(B);
6009
6017
  }
6010
6018
  }
6011
6019
  async function Og(t, A, e = {}, r, s) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Utility helpers for jsPDF's doc.html() renderer with automatic page breaking, table splitting, and RTL support",
5
5
  "type": "module",
6
6
  "main": "dist/html-to-pdf.js",