@qrcommunication/gigapdf-lib 0.54.0 → 0.56.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,50 @@ All notable changes to `@qrcommunication/gigapdf-lib` are documented here.
4
4
  The format follows [Keep a Changelog](https://keepachangelog.com/) and the
5
5
  project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.56.0] - 2026-06-21
8
+
9
+ ### Added
10
+
11
+ - **`renderPageNoText(page, scale?)` — text-free page raster.** Rasterise a page to
12
+ PNG **without** its page-content text (glyphs from `Tj`/`'`/`"`/`TJ` are suppressed)
13
+ while every non-text element — vectors, gradients/shadings, images and patterns —
14
+ plus annotation/widget appearances are rendered in full. Built for editors that
15
+ overlay real, editable text on top of a text-free background. Native rasteriser, no
16
+ third-party image library. New ABI `gp_render_page_no_text(handle, page, scale,
17
+ out_len)` and core `Document::render_page_no_text`, alongside the existing
18
+ `renderPage` / `gp_render_page`.
19
+
20
+ ## [0.55.1] - 2026-06-21
21
+
22
+ ### Fixed
23
+
24
+ - **`imageToPdf` now embeds every PNG variant — no more empty buffer.** The pure-Rust
25
+ PNG decoder only handled 8-bit, non-interlaced images, so any PNG with a 16-bit
26
+ depth (common from screenshots and image editors), a sub-byte depth (1/2/4-bit
27
+ greyscale and palette), or Adam7 interlacing was rejected — `imageToPdf` returned
28
+ an **empty array** for those inputs. The decoder now supports the full PNG matrix:
29
+ colour types 0/2/3/4/6 at bit depths 1, 2, 4, 8 and 16, both non-interlaced and
30
+ interlaced, plus `tRNS` colour-key transparency for greyscale and truecolour
31
+ images. Transparency (PNG alpha and transcoded GIF/WebP/AVIF alpha) is preserved
32
+ via a `/DeviceGray` soft mask (`/SMask`), never flattened.
33
+
34
+ ### Added
35
+
36
+ - **`imageToPdf(image)` — raster image → one-page PDF.** PNG, JPEG, GIF, WebP and
37
+ AVIF are accepted (format auto-detected); the image is centred and scaled to fit
38
+ on an A4 portrait page and embedded as a real `/Image` XObject. PNG/JPEG embed
39
+ directly (JPEG verbatim via `/DCTDecode`); **GIF/WebP/AVIF are transcoded to PNG**
40
+ first (native `gif`/`webp`/`avif` decode → PNG encode), since the embedder only
41
+ writes PNG/JPEG XObjects. Returns an empty array for unrecognized bytes. Pure
42
+ Rust/WASM — no third-party image library.
43
+ - **AVIF dimension probe.** The image-header reader now recognizes AVIF/HEIF-still
44
+ containers and reads the canvas size from the `meta → iprp → ipco → ispe` box (a
45
+ cheap header parse, no AV1 decode; falls back to a full decode for unusual box
46
+ orderings), so `image_to_model` lowers an AVIF to a full-page image document too.
47
+ - **`mergePdfs(pdfs)` — concatenate several PDFs into one.** Appends each input's
48
+ pages in order onto the first (empty list → empty bytes; single PDF → returned
49
+ unchanged). Built on the existing `appendPages`.
50
+
7
51
  ## [0.54.0] - 2026-06-20
8
52
 
9
53
  ### Added
package/README.md CHANGED
@@ -107,6 +107,12 @@ Task-oriented snippets using the high-level classes. Each assumes
107
107
 
108
108
  ### Merge several PDFs
109
109
 
110
+ ```ts
111
+ const merged = giga.mergePdfs([first, second, third]); // one PDF, pages in order
112
+ ```
113
+
114
+ Or, for finer control, append page-by-page yourself:
115
+
110
116
  ```ts
111
117
  const doc = giga.open(first); // the base document
112
118
  for (const extra of [second, third]) doc.appendPages(extra); // append every page
@@ -114,6 +120,13 @@ const merged = doc.saveCompressed();
114
120
  doc.close();
115
121
  ```
116
122
 
123
+ ### Image → PDF
124
+
125
+ ```ts
126
+ const pdf = giga.imageToPdf(imageBytes); // PNG/JPEG/GIF/WebP/AVIF → one A4 page
127
+ // (image centred, shrink-to-fit, never upscaled; empty array if not an image)
128
+ ```
129
+
117
130
  ### Split — extract a page range into a new PDF
118
131
 
119
132
  ```ts
@@ -254,7 +267,8 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
254
267
  > signatures and defaults also ship in the bundled `.d.ts`.
255
268
 
256
269
  - **`GigaPdfEngine`** — `load`/`loadDefault`, `open`/`openEncrypted`,
257
- `txtToPdf`/`htmlToPdf`/`rtfToPdf`/`officeToPdf`, `fontCatalog`/`fontRequestUrl`/`parseCssFontUrl`.
270
+ `txtToPdf`/`htmlToPdf`/`rtfToPdf`/`officeToPdf`/`imageToPdf` (PNG/JPEG/GIF/WebP/AVIF → A4 page),
271
+ `mergePdfs` (concatenate many PDFs), `fontCatalog`/`fontRequestUrl`/`parseCssFontUrl`.
258
272
  - **`GigaPdfDoc`** — text intelligence (`textRuns`, `structuredText`, `search`,
259
273
  `ocr`, `ocrText`, `elements`, `elementAt`), editing (`replaceText`,
260
274
  `removeElement`, `moveElement`, `duplicateElement`, `redact`), vector drawing
@@ -262,7 +276,9 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
262
276
  `addImage` (PNG/JPEG, alpha + opacity)), pages (`rotatePage`, `deletePage`,
263
277
  `movePage`, `appendPages`, `extractPages`, `resizePage`, `addPage`, `copyPage`,
264
278
  `pageInfo`),
265
- `renderPage`, fonts (base-14 `addStandardText`, embed **any** TrueType/OpenType
279
+ `renderPage` (and `renderPageNoText` — a text-free background for editors that
280
+ overlay real editable text; vectors/gradients/images/annotations still rendered),
281
+ fonts (base-14 `addStandardText`, embed **any** TrueType/OpenType
266
282
  via `embedFont`/`addText`, font-aware editing `replaceText`,
267
283
  the document's own faces `embeddedFonts`/`extractFont`, `neededFonts`),
268
284
  conversions (`toText/Html/Docx/Pptx/Odp/Odt/Xlsx/Ods/Rtf/PdfA`, plus
package/dist/index.cjs CHANGED
@@ -268,6 +268,40 @@ var GigaPdfEngine = class _GigaPdfEngine {
268
268
  (p, l) => this._buffer((o) => this.ex.gp_office_to_pdf(p, l, o))
269
269
  );
270
270
  }
271
+ /**
272
+ * Image (PNG/JPEG/GIF/WebP/AVIF) → one-page PDF, format auto-detected: the
273
+ * image is centred and scaled to fit on an A4 portrait page. PNG/JPEG embed
274
+ * directly; GIF/WebP/AVIF are transcoded to PNG first — all in pure Rust/WASM,
275
+ * no third-party image library. Empty array if the bytes are not a recognized
276
+ * image. To combine many images into a single document, pipe each result
277
+ * through {@link mergePdfs}.
278
+ */
279
+ imageToPdf(image) {
280
+ return this._withBytes(
281
+ image,
282
+ (p, l) => this._buffer((o) => this.ex.gp_image_to_pdf(p, l, o))
283
+ );
284
+ }
285
+ /**
286
+ * Merge several PDFs into one by appending their pages in order. Returns an
287
+ * empty document for an empty list, or the single input unchanged for a list
288
+ * of one. Each subsequent PDF is appended onto the first via
289
+ * {@link GigaPdfDoc.appendPages}; the merged bytes are returned and the working
290
+ * document is closed.
291
+ */
292
+ mergePdfs(pdfs) {
293
+ if (pdfs.length === 0) return new Uint8Array(0);
294
+ if (pdfs.length === 1) return pdfs[0];
295
+ const base = this.open(pdfs[0]);
296
+ try {
297
+ for (let i = 1; i < pdfs.length; i++) {
298
+ base.appendPages(pdfs[i]);
299
+ }
300
+ return base.save();
301
+ } finally {
302
+ base.close();
303
+ }
304
+ }
271
305
  /**
272
306
  * Write a host-built grid (`pages[rows][cells]`) to an `.xlsx` workbook — one
273
307
  * sheet per page — with the engine's native spreadsheet writer (no
@@ -1204,6 +1238,16 @@ var GigaPdfDoc = class {
1204
1238
  renderPage(page, scale = 1) {
1205
1239
  return this.g._buffer((o) => this.ex().gp_render_page(this.h, page, scale, o));
1206
1240
  }
1241
+ /**
1242
+ * Rasterize a page to a PNG **without the page content stream's text** — glyphs
1243
+ * are suppressed while gradients, shadings, images, vectors and patterns are
1244
+ * preserved. Annotation/widget appearances are still painted in full. Use this
1245
+ * to paint a text-free raster background the editor can overlay real, editable
1246
+ * text on top of.
1247
+ */
1248
+ renderPageNoText(page, scale = 1) {
1249
+ return this.g._buffer((o) => this.ex().gp_render_page_no_text(this.h, page, scale, o));
1250
+ }
1207
1251
  // fonts — embed a downloaded font, then add real selectable text
1208
1252
  /**
1209
1253
  * Embed an outline font program as a Type0 font and return its object number