Skip to content

Commit

Permalink
Remove /Type entry from trailer
Browse files Browse the repository at this point in the history
When a document is optimized and xref streams are deleted, the
associated trailer might still have the /Type entry set. This leads to
the written trailer dictionary having the /Type entry which might lead
to problems (because the trailer is a standard trailer and not an xref
stream).

There are other ways in which a trailer might have a lingering /Type
entry.

This change deletes the /Type entry from the trailer.
  • Loading branch information
gettalong committed Sep 5, 2024

Unverified

The committer email address is not verified.
1 parent dcbc220 commit 8285ccc
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
with missing font size or color information
* [HexaPDF::Type::AcroForm::SignatureField#field_value] to always return a
correctly wrapped object
* [HexaPDF::Writer] to remove /Type entry from trailer


## 0.46.0 - 2024-08-11
1 change: 1 addition & 0 deletions lib/hexapdf/writer.rb
Original file line number Diff line number Diff line change
@@ -163,6 +163,7 @@ def write_revision(rev, previous_xref_pos = nil)

trailer = rev.trailer.value.dup
trailer.delete(:XRefStm)
trailer.delete(:Type)
if previous_xref_pos
trailer[:Prev] = previous_xref_pos
else
13 changes: 11 additions & 2 deletions test/hexapdf/test_writer.rb
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@
20
endobj
3 0 obj
<</Type/XRef/Size 6/W[1 1 2]/Index[0 4 5 1]/Filter/FlateDecode/DecodeParms<</Columns 4/Predictor 12>>/Length 31>>stream
<</Size 6/Type/XRef/W[1 1 2]/Index[0 4 5 1]/Filter/FlateDecode/DecodeParms<</Columns 4/Predictor 12>>/Length 31>>stream
x\xDAcb`\xF8\xFF\x9F\x89\x89\x95\x91\x91\xE9\x7F\x19\x03\x03\x13\x83\x10\x88he`\x00\x00B4\x04\x1E
endstream
endobj
@@ -80,7 +80,7 @@
endstream
endobj
4 0 obj
<</Type/XRef/Size 7/Root<</Type/Catalog>>/Info 6 0 R/Prev 141/W[1 2 2]/Index[2 1 4 1 6 1]/Filter/FlateDecode/DecodeParms<</Columns 5/Predictor 12>>/Length 22>>stream
<</Size 7/Root<</Type/Catalog>>/Info 6 0 R/Prev 141/Type/XRef/W[1 2 2]/Index[2 1 4 1 6 1]/Filter/FlateDecode/DecodeParms<</Columns 5/Predictor 12>>/Length 22>>stream
x\xDAcbdlg``b`\xB0\x04\x93\x93\x18\x18\x00\f\e\x01[
endstream
endobj
@@ -270,4 +270,13 @@ def assert_document_conversion(input_io)
doc = HexaPDF::Document.new(io: io)
refute(doc.trailer.key?(:XRefStm))
end

it "removes the /Type entry in a non-xref stream trailer" do
io = StringIO.new
doc = HexaPDF::Document.new
doc.trailer[:Type] = :XRef
doc.write(io)
doc = HexaPDF::Document.new(io: io)
refute(doc.trailer.key?(:Type))
end
end

0 comments on commit 8285ccc

Please sign in to comment.