docpdf 0.1.6 → 0.1.7

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: b68eda5d7355d1d3a227ef71f44d41f95dc7ccbfe7b08af17739e629c9ab26dc
4
- data.tar.gz: 23e0ab911eb89df49eeac3634b50ef6d8bf8f7b74a8861067e2a0e44f3946e82
3
+ metadata.gz: 4fa01d67dead11a1f62eb4ff7f6f387599b97ec99d0c91bd5644e60e98fd26a6
4
+ data.tar.gz: 1dc447f55133af1a3ff94ad3aaaeca8014a1560cdd6db5cf2d85ab30220afa1e
5
5
  SHA512:
6
- metadata.gz: 14aff5944d6ac087f241b078c557e480974f322ca2cbcf3c9d08136e6b37f6598ca1bbd17e14267b060632e83e54491dbb5dc6a42b15768eb64883bbe3fd7838
7
- data.tar.gz: cb43492ce6e3b7257e3c6cc01281904c509dcb473f77e932361ae986f0f39cda9af3bc0a4080b2e8c7d24e2c13adf6d4a8b93230ed455eef6b6ed74ede98e301
6
+ metadata.gz: 3cfa330a65d41f8c24866b04da28d15a795df5c826f2459a9ae1c46c86c470147e92c6ff75952579d3bfd3b6fd4804747a712b868fc829102fab3ece963d0a2d
7
+ data.tar.gz: aa22481e4dfbb0966c9f95b1ecd5924680c491729a3c0ac8b873d2aca03c49b4889a936ce57400a3681594c5ac18078da66c8fa78b20cbed9da211316115f883
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.7] - 2026-10-08
4
+
5
+ ### Fixed
6
+ - The HexaPDF stamper raised `ConversionError` on PDFs with spec violations HexaPDF cannot correct, even though viewers render them fine. One example is a tagged PDF exported from Canva with a structure element missing its parent. The stamper now corrects what HexaPDF can and writes the rest as it came in, the way the `hexapdf` CLI does.
7
+ - `DocPDF.convert` raised `NameError: uninitialized constant DocPDF::InputNormalizer::Pathname` on Ruby 3.3 and 3.4 when nothing else had loaded `pathname`. Bundler and Rails both load it, so only plain Ruby scripts were affected. `DocPDF.watermark` with a file path and `font_file` given as a hash hit the same error. DocPDF now requires `pathname` itself.
8
+
3
9
  ## [0.1.6] - 2026-09-18
4
10
 
5
11
  ### Added
@@ -22,7 +22,7 @@ module DocPDF
22
22
  page.canvas(type: :overlay).xobject(stamp_form, at: [0, 0]) if page_indices.nil? || page_indices.include?(idx)
23
23
  end
24
24
 
25
- write_to_string(doc)
25
+ write_to_string_leniently(doc)
26
26
  rescue HexaPDF::Error, Errno::ENOENT => e
27
27
  raise ConversionError, "HexaPDF failed to stamp PDF: #{e.message}"
28
28
  end
@@ -125,11 +125,23 @@ module DocPDF
125
125
  doc.config["font.map"] = (doc.config["font.map"] || {}).merge(name => map)
126
126
  end
127
127
 
128
- def write_to_string(doc)
128
+ def write_to_string(doc, **write_options)
129
129
  io = StringIO.new
130
- doc.write(io)
130
+ doc.write(io, **write_options)
131
131
  io.string
132
132
  end
133
+
134
+ # The caller's PDF may break the spec in ways HexaPDF cannot repair, like a
135
+ # tagged PDF whose structure elements have no parent. Viewers open those
136
+ # fine, so correct what can be corrected and write the rest as it came in,
137
+ # the way the hexapdf CLI does. Objects are validated one at a time because
138
+ # Document#validate stops at the first one it cannot correct, and the stamp
139
+ # form only becomes an indirect object when validation reaches its page.
140
+ def write_to_string_leniently(doc)
141
+ doc.trailer.validate(auto_correct: true)
142
+ doc.each { |obj| obj.validate(auto_correct: true) }
143
+ write_to_string(doc, validate: false)
144
+ end
133
145
  end
134
146
  end
135
147
  end
@@ -1,3 +1,5 @@
1
+ require "pathname"
2
+
1
3
  module DocPDF
2
4
  # Prawn's built-in AFM fonts only cover Windows-1252, so any text outside it
3
5
  # fails to render. Pointing an adapter at a TrueType file lifts that limit.
@@ -1,3 +1,5 @@
1
+ require "pathname"
2
+
1
3
  module DocPDF
2
4
  class InputNormalizer
3
5
  attr_reader :data, :filename, :source_filename, :mime_type
@@ -1,3 +1,3 @@
1
1
  module DocPDF
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require "pathname"
2
+
1
3
  module DocPDF
2
4
  class Watermarker
3
5
  POSITIONS = %i[center top bottom left right top_left top_right bottom_left bottom_right].freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docpdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Velocity Labs, LLC