imprimatur 0.5.0-x86_64-linux-gnu → 0.6.1-x86_64-linux-gnu

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 365fabbd18eac059e63f2a01dcee0842dd2ee44adfa5b8a7d560bb233f1f3e6c
4
- data.tar.gz: 9ae1b0b72cb4b865b014faf173014142bc53ee6d4ae4e57fde61bb09a1a514ca
3
+ metadata.gz: 061b07d0d07ac08e51a101cb847d50ad464bc85ca2293fc8fdefa60f89dbde3b
4
+ data.tar.gz: 7d9a54e2667ad053687e86f26f7af5741fb0748c4254cc60972a9f1bd5441b5e
5
5
  SHA512:
6
- metadata.gz: 7f11ddb06ee221c324eee461c681badce4990c58315cceef5b91ca330e9fba2488e0070824134ca9d4d5351628ea7515f207b2230e893a5ffe59aa9005b8969b
7
- data.tar.gz: 7a1b9135e0d0d89bbb04d3e42ece4df35afe3b353d6e0a3e2761eeb828a88b0cc84a128193a030e1c79ec3222427fe8b009c15057ca6fdf1e41720242bc96c91
6
+ metadata.gz: c6c19f54a1390bc6d8ed5899c56ac92910d57b1442235e2bcef252fa0cef5b3770125997a9b68458cdb8b8db72a874715d48c54b4fbaa3235cf6766ff94f0c4a
7
+ data.tar.gz: bdb3a1ebb3c4c0e32c4f0a1c40b567848b300a08ad86eed07f0066e2cfafcbfd2f20e904d49134762d23eb4885fda735bc735bc72b391631c57d7a4685fdc991
data/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ - Isolate PDF metadata and text reads in the bundled resource-limited Rust
6
+ worker, as rendering already is; all three accept `memory_bytes:`.
7
+ - On Linux/FreeBSD, re-exec the worker under its address-space limit before
8
+ reading the PDF, including tiny metadata-only reads.
9
+ - Preserve completed pages on worker termination and recover healthy neighbors
10
+ after page-local stream limits without renewing the overall deadline.
11
+ - Allow a bounded exit grace when macOS cannot inspect an exiting worker;
12
+ persistent monitor failures still terminate and reap a live worker.
13
+
14
+ ## [0.6.1](https://github.com/seuros/imprimatur/compare/v0.6.0...v0.6.1) (2026-10-25)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **pdf:** isolate bounded reads and preserve page recovery ([fbfbbc5](https://github.com/seuros/imprimatur/commit/fbfbbc5e7e44768efae293b37be255b8b797f831))
20
+
21
+ ## [0.6.0](https://github.com/seuros/imprimatur/compare/v0.5.0...v0.6.0) (2026-10-25)
22
+
23
+
24
+ ### Features
25
+
26
+ * bound PDF reads and rendering; deduplicate Rust ([420e096](https://github.com/seuros/imprimatur/commit/420e096591ef08190427c7b090840dcd761010b4))
27
+ * **doc:** set the body font size ([44f7617](https://github.com/seuros/imprimatur/commit/44f76170fd1ad29f143c1ef22c355fd1c1cbf8e1))
28
+
29
+
30
+ ### Bug Fixes
31
+
32
+ * enforce render limits across Unix platforms ([5c7f0ba](https://github.com/seuros/imprimatur/commit/5c7f0bab2076681782c6bfa2de6062ad53c0e7f9))
33
+
3
34
  ## [0.5.0](https://github.com/seuros/imprimatur/compare/v0.4.0...v0.5.0) (2026-10-18)
4
35
 
5
36
 
data/README.md CHANGED
@@ -7,10 +7,9 @@ a 40,000-character cell is refused at the door, not discovered by Excel's
7
7
 
8
8
  - **A Ruby DSL over a native core.** The core is also published on its own,
9
9
  as `imprimatur` on crates.io; the gem wraps it.
10
- - **No third-party format stack.** The XML writer and the zip container are
11
- written here, from ECMA-376 and the zip specification; only deflate
12
- (`miniz_oxide`) and CRC-32 (`crc32fast`) come from crates, and QR Code and
13
- Data Matrix encoding (`qrcode`, `datamatrix`) for barcodes.
10
+ - **Own readers and writers.** XML, zip and PDF reading/writing live here.
11
+ Optional full-page PDF rendering uses Hayro, a pure-Rust CPU renderer;
12
+ no Poppler, PDFium, GPU or system fonts are required.
14
13
  - **Deterministic.** The same document always gives the same bytes.
15
14
  - **Native only.** CRuby 4.0+. No pure Ruby fallback, no JRuby, no TruffleRuby.
16
15
 
@@ -178,7 +177,7 @@ Not yet: merged cells, frozen panes, streaming for very large sheets.
178
177
  One document, two formats:
179
178
 
180
179
  ```ruby
181
- doc = Imprimatur::Document.new(page_size: :a4, page_numbers: true)
180
+ doc = Imprimatur::Document.new(page_size: :a4, font_size: 10, page_numbers: true)
182
181
  doc.heading "Quarterly report"
183
182
  doc.heading "Sales", level: 2
184
183
  doc.paragraph do |p|
@@ -195,12 +194,14 @@ doc.paragraph "Appendix."
195
194
  doc.save_pdf("report.pdf")
196
195
  doc.save_docx("report.docx")
197
196
 
198
- Imprimatur.pdf("memo.pdf") { it.paragraph "Or in one go." } # Imprimatur.docx alike
197
+ Imprimatur.pdf("memo.pdf", font_size: 10) { it.paragraph "Or in one go." } # Imprimatur.docx alike
199
198
  Imprimatur.pdf(page_size: [200, 200], margin: 10) { it.image qr_png, width: 180 }
200
199
  ```
201
200
 
202
201
  - Headings 1 to 3 (real Word heading styles in DOCX), paragraphs of runs
203
202
  (bold, italic, underline, color), alignment, `\n` line breaks and tabs.
203
+ - Body text at `font_size:` points (1 to 1638, in steps of 0.5; 11 unless
204
+ set), in both formats; headings keep their own sizes.
204
205
  - Tables: equal columns, borders, a shaded header row that repeats on every
205
206
  page; cells are converted with `to_s`.
206
207
  - Pictures: PNG or JPEG (a path, the bytes or an IO), at `width:` or
@@ -333,6 +334,61 @@ pages of headings and paragraphs with their position, a workbook's typed
333
334
  cells and comments, a Word document's blocks with their bold, italic and
334
335
  linked stretches.
335
336
 
337
+ For a PDF without text, `content` still returns every page, its empty
338
+ `blocks` and its `images` count. `markdown` and the text-oriented CLI commands
339
+ still report `NoTextLayer`;
340
+ OCR callers need the structure of scanned and blank pages too.
341
+
342
+ ### Bounded PDF pages and OCR rendering
343
+
344
+ ```ruby
345
+ Imprimatur.pdf_info(upload.download) # => {page_count: 20, encrypted: false}
346
+ result = Imprimatur.pdf_pages(upload.download, first_page: 2, last_page: 10, max_pages: 5)
347
+ result[:pages].each { |page| puts [page[:page], page[:status], page[:text]] }
348
+ png = Imprimatur.render_pdf_page(upload.download, page: 2, max_side: 1568)
349
+ ```
350
+
351
+ `pdf_info` counts actual pages without interpreting their content. `pdf_pages`
352
+ only interprets the selected streams, at most 500 pages by default. Each page
353
+ has `status` (`text`, `empty`, `failed`, `skipped`), `text`, `images` (nil if
354
+ unknown), `truncated` and `reason`. It keeps healthy pages when another is
355
+ damaged. Unlike the tolerant Markdown reader, corrupt Flate streams fail
356
+ explicitly. Limits are 256 KiB of text per page and 8 MiB total
357
+ (`max_page_bytes:`, `max_output_bytes:`); truncation respects UTF-8.
358
+
359
+ `render_pdf_page` returns an opaque grayscale PNG of the **whole page**, not
360
+ just its scan image; `grayscale: false` keeps color. It bounds the output surface
361
+ before allocation (`max_pixels:`, 4 million) and encoded output
362
+ (`max_output_bytes:`, 8 MiB). Preflight rejects pages drawing more than 40 million
363
+ source-image pixels. Renderer warnings fail instead of silently dropping content.
364
+ The crate exposes `read::pdf::{info, pages, render_page}` (`render` feature) and
365
+ `read::pdf::isolation::{info_isolated, pages_isolated, render_page_isolated}`
366
+ (`isolation` feature). These take an absolute path to the trusted
367
+ `imprimatur-render-worker` executable. The gem bundles that worker and always
368
+ isolates all three PDF operations; it never falls back to in-process parsing
369
+ or searches PATH.
370
+
371
+ All three accept the normal read limits and `memory_bytes:`
372
+ (1 GiB by default): Linux/FreeBSD enforce an address-space cap; macOS uses a
373
+ sampled RSS watchdog, which can briefly overshoot. A worker is killed and reaped
374
+ on timeout, cancellation or supervisor failure. Each operation has a mandatory
375
+ 60-second process ceiling even with `timeout: nil`; a shorter `timeout:` still
376
+ applies. CPU time, output files and core dumps are also limited.
377
+
378
+ The page worker flushes completed records as it goes. An exhausted stream
379
+ budget triggers individual-page recovery inside that worker: each attempt has
380
+ its own `max_inflated` allowance, while the original overall deadline, process
381
+ memory limit and aggregate text cap remain in force. An oversized page is
382
+ `failed`, not blank, without discarding healthy neighbors. A worker terminated
383
+ after metadata was read preserves completed pages and explicitly marks the
384
+ unreached pages; an expired overall deadline marks them `skipped`. Cancellation
385
+ still raises rather than returning a partial successful call.
386
+
387
+ This is resource containment, **not a filesystem/network security sandbox**.
388
+ The raw crate `info`, `pages` and `render_page` APIs remain in-process;
389
+ `render_page` cannot interrupt Hayro.
390
+ `max_inflated` bounds our preflight, not Hayro's internal decoders.
391
+
336
392
  ```ruby
337
393
  sheet = Imprimatur.content("sales.xlsx")[:sheets].first
338
394
  sheet[:rows][1][:cells]
@@ -441,7 +497,7 @@ The core works without Ruby too; see
441
497
 
442
498
  ```sh
443
499
  bundle install
444
- rake test:all # cargo test, then the Ruby suite on the compiled extension
500
+ rake test:all # core, CLI and Ruby suites on the compiled extension
445
501
  rake lint # dictator, cargo fmt --check, clippy
446
502
  rake gems:native # the precompiled gem for this machine, in pkg/
447
503
  ```
@@ -21,10 +21,11 @@ module Imprimatur
21
21
  # @param page_size [:a4, :letter, Array(Numeric, Numeric)] or its width
22
22
  # and height in points, 36 to 1584 a side
23
23
  # @param margin [Numeric, nil] points on every side, one inch (72) unless set
24
+ # @param font_size [Numeric, nil] body text in points, 1 to 1638 in steps of 0.5; 11 unless set
24
25
  # @param page_numbers [Boolean] number pages "1 / N" in the footer
25
26
  # @raise [ArgumentError] an unknown page size
26
- # @raise [Imprimatur::Error] a page size or margin out of range
27
- def initialize(page_size: :a4, margin: nil, page_numbers: false)
27
+ # @raise [Imprimatur::Error] a page size, margin or font size out of range
28
+ def initialize(page_size: :a4, margin: nil, font_size: nil, page_numbers: false)
28
29
  @native = Native::Document.new
29
30
  numbers = page_numbers ? true : false
30
31
  if page_size.is_a?(Array)
@@ -34,6 +35,7 @@ module Imprimatur
34
35
  @native.set_page(page_size.to_s, numbers)
35
36
  end
36
37
  @native.set_margin(Float(margin)) if margin
38
+ @native.set_font_size(Float(font_size)) if font_size
37
39
  end
38
40
 
39
41
  # A PNG or JPEG in the flow, at +width+ or +height+ points (the other
@@ -15,3 +15,10 @@ rescue LoadError => e
15
15
  raise LoadError, "imprimatur: the native extension did not load (#{e.message}). " \
16
16
  'Install a platform gem, or build it with `rake compile` (toolchain: https://rustup.rs).'
17
17
  end
18
+
19
+ module Imprimatur
20
+ # Always use the companion of the loaded extension, never PATH.
21
+ RENDER_WORKER = File.join(File.dirname($LOADED_FEATURES.find do |path|
22
+ path.end_with?("/imprimatur_native.#{RbConfig::CONFIG['DLEXT']}")
23
+ end), 'imprimatur-render-worker').freeze
24
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Imprimatur
4
+ # Keyword handling only; parsing, limits and rendering live in the native core.
5
+ module PdfReader
6
+ def self.info(document, memory_bytes: 1024 * 1024 * 1024, max_bytes: nil, **limits)
7
+ JSON.parse(Native.pdf_info(Reader.read(document, max_bytes), Reader.limits(max_bytes:, **limits),
8
+ RENDER_WORKER, memory_bytes),
9
+ symbolize_names: true)
10
+ end
11
+
12
+ def self.pages(document, first_page: 1, last_page: 0xFFFFFFFF, max_pages: 500,
13
+ max_page_bytes: 256 * 1024, max_output_bytes: 8 * 1024 * 1024,
14
+ memory_bytes: 1024 * 1024 * 1024, max_bytes: nil, **limits)
15
+ options = [first_page, last_page, max_pages, max_page_bytes, max_output_bytes]
16
+ JSON.parse(Native.pdf_pages(Reader.read(document, max_bytes), Reader.limits(max_bytes:, **limits),
17
+ options, RENDER_WORKER, memory_bytes),
18
+ symbolize_names: true)
19
+ end
20
+
21
+ def self.render(document, page:, max_side: 1568, max_pixels: 4_000_000,
22
+ max_output_bytes: 8 * 1024 * 1024, grayscale: true,
23
+ memory_bytes: 1024 * 1024 * 1024, max_bytes: nil, **limits)
24
+ Native.render_pdf_page(Reader.read(document, max_bytes), Reader.limits(max_bytes:, **limits),
25
+ [page, max_side, max_pixels, max_output_bytes, grayscale],
26
+ RENDER_WORKER, memory_bytes)
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Imprimatur
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.1'
5
5
  end
data/lib/imprimatur.rb CHANGED
@@ -10,6 +10,7 @@ require_relative 'imprimatur/barcode'
10
10
  require_relative 'imprimatur/xlsx'
11
11
  require_relative 'imprimatur/document'
12
12
  require_relative 'imprimatur/reader'
13
+ require_relative 'imprimatur/pdf_reader'
13
14
  require_relative 'imprimatur/spreadsheet'
14
15
  require_relative 'imprimatur/zip'
15
16
 
@@ -45,7 +46,7 @@ module Imprimatur
45
46
  # Builds a {Document} and renders it as PDF. With a path, saves it there
46
47
  # and returns the path; without, returns the bytes.
47
48
  #
48
- # @param options [Hash] +page_size:+ and +page_numbers:+, see {Document#initialize}
49
+ # @param options [Hash] +page_size:+, +margin:+, +font_size:+ and +page_numbers:+, see {Document#initialize}
49
50
  # @yieldparam document [Document]
50
51
  def pdf(path = nil, **options, &) = Document.build(:pdf, path, **options, &)
51
52
 
@@ -92,7 +93,11 @@ module Imprimatur
92
93
  # sheet = Imprimatur.content('sales.xlsx')[:sheets].first
93
94
  # sheet[:rows][1][:cells] # => [{cell: "A2", type: "text", value: "North"}, ...]
94
95
  #
95
- # Takes the arguments of {.markdown}, and raises as it does. With
96
+ # Unlike {.markdown}, a PDF without text still returns every page, with
97
+ # empty +:blocks+ and its image count, rather than raising {NoTextLayer}.
98
+ # This keeps scanned and blank pages visible to OCR callers.
99
+ #
100
+ # Takes the arguments of {.markdown}, and raises as it does otherwise. With
96
101
  # +styles: true+ each sheet also lists its formatted cells' +:styles+:
97
102
  # font, size, bold, italic, underline, ARGB color and fill, alignment,
98
103
  # wrap, border and number format.
@@ -100,6 +105,25 @@ module Imprimatur
100
105
  # @return [Hash] with symbol keys; +:format+ is +"pdf"+, +"xlsx"+ or +"docx"+
101
106
  def content(document, ...) = Reader.content(document, ...)
102
107
 
108
+ # PDF metadata without reading page content.
109
+ # @return [Hash] +page_count:+ and +encrypted:+
110
+ def pdf_info(document, ...) = PdfReader.info(document, ...)
111
+
112
+ # A bounded, one-based page selection. Each page has its status, text,
113
+ # image count (nil when unknown), truncation flag and failure reason.
114
+ # Takes +first_page:+, +last_page:+, +max_pages:+ (500),
115
+ # +max_page_bytes:+ (256 KiB), +max_output_bytes:+ (8 MiB), and read limits.
116
+ # @return [Hash] +page_count:+, +encrypted:+ and +pages:+
117
+ def pdf_pages(document, ...) = PdfReader.pages(document, ...)
118
+
119
+ # A full page as an opaque PNG, not just its embedded images.
120
+ # Takes +page:+ (one-based), +max_side:+ (1568), +max_pixels:+ (4 million),
121
+ # +max_output_bytes:+ (8 MiB), +grayscale:+ (true), and read limits.
122
+ # Rendering checks time/cancellation before and after Hayro, not during it.
123
+ # Untrusted documents still need an externally limited worker process.
124
+ # @return [String] PNG bytes
125
+ def render_pdf_page(document, ...) = PdfReader.render(document, ...)
126
+
103
127
  # A workbook's sheets and their values, read from the same documents
104
128
  # {.markdown} takes (+.xlsx+, +.xls+, +.ods+); see {Spreadsheet}.
105
129
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imprimatur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  platform: x86_64-linux-gnu
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -10,9 +10,10 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: 'A Ruby DSL over a native core that writes Excel workbooks, and PDF and
13
- Word documents from one model, with its own XML, zip and PDF writers: no third-party
14
- format stack. It reads PDF, XLSX, XLS, ODS and DOCX back: as Markdown, as typed
15
- structure, and their images. Precompiled for Linux, macOS and FreeBSD; CRuby only.'
13
+ Word documents from one model, with its own XML, zip and PDF readers and writers.
14
+ It reads PDF, XLSX, XLS, ODS and DOCX back: as Markdown, as typed structure, and
15
+ their images. Full-page PDF rendering uses the pure-Rust Hayro renderer. Precompiled
16
+ for Linux, macOS and FreeBSD; CRuby only.'
16
17
  email:
17
18
  - terminale@gmail.com
18
19
  executables: []
@@ -23,12 +24,14 @@ files:
23
24
  - LICENSE.txt
24
25
  - README.md
25
26
  - lib/imprimatur.rb
27
+ - lib/imprimatur/4.0/imprimatur-render-worker
26
28
  - lib/imprimatur/4.0/imprimatur_native.so
27
29
  - lib/imprimatur/barcode.rb
28
30
  - lib/imprimatur/document.rb
29
31
  - lib/imprimatur/error.rb
30
32
  - lib/imprimatur/formula.rb
31
33
  - lib/imprimatur/native.rb
34
+ - lib/imprimatur/pdf_reader.rb
32
35
  - lib/imprimatur/reader.rb
33
36
  - lib/imprimatur/spreadsheet.rb
34
37
  - lib/imprimatur/style.rb