@qrcommunication/gigapdf-lib 0.54.0 → 0.55.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,37 @@ 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.55.1] - 2026-06-21
8
+
9
+ ### Fixed
10
+
11
+ - **`imageToPdf` now embeds every PNG variant — no more empty buffer.** The pure-Rust
12
+ PNG decoder only handled 8-bit, non-interlaced images, so any PNG with a 16-bit
13
+ depth (common from screenshots and image editors), a sub-byte depth (1/2/4-bit
14
+ greyscale and palette), or Adam7 interlacing was rejected — `imageToPdf` returned
15
+ an **empty array** for those inputs. The decoder now supports the full PNG matrix:
16
+ colour types 0/2/3/4/6 at bit depths 1, 2, 4, 8 and 16, both non-interlaced and
17
+ interlaced, plus `tRNS` colour-key transparency for greyscale and truecolour
18
+ images. Transparency (PNG alpha and transcoded GIF/WebP/AVIF alpha) is preserved
19
+ via a `/DeviceGray` soft mask (`/SMask`), never flattened.
20
+
21
+ ### Added
22
+
23
+ - **`imageToPdf(image)` — raster image → one-page PDF.** PNG, JPEG, GIF, WebP and
24
+ AVIF are accepted (format auto-detected); the image is centred and scaled to fit
25
+ on an A4 portrait page and embedded as a real `/Image` XObject. PNG/JPEG embed
26
+ directly (JPEG verbatim via `/DCTDecode`); **GIF/WebP/AVIF are transcoded to PNG**
27
+ first (native `gif`/`webp`/`avif` decode → PNG encode), since the embedder only
28
+ writes PNG/JPEG XObjects. Returns an empty array for unrecognized bytes. Pure
29
+ Rust/WASM — no third-party image library.
30
+ - **AVIF dimension probe.** The image-header reader now recognizes AVIF/HEIF-still
31
+ containers and reads the canvas size from the `meta → iprp → ipco → ispe` box (a
32
+ cheap header parse, no AV1 decode; falls back to a full decode for unusual box
33
+ orderings), so `image_to_model` lowers an AVIF to a full-page image document too.
34
+ - **`mergePdfs(pdfs)` — concatenate several PDFs into one.** Appends each input's
35
+ pages in order onto the first (empty list → empty bytes; single PDF → returned
36
+ unchanged). Built on the existing `appendPages`.
37
+
7
38
  ## [0.54.0] - 2026-06-20
8
39
 
9
40
  ### 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
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