Skip to content

Commit 0ce1262

Browse files
committed
Don’t add /Info key in compressed trailer if info dict is empty
1 parent 160e680 commit 0ce1262

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pydyf/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ def write(self, output, version=b'1.7', identifier=False, compress=False):
532532
if identifier not in (False, True, None):
533533
identifier = _to_bytes(identifier)
534534

535+
# Add info object if needed
536+
if self.info:
537+
self.add_object(self.info)
538+
535539
# Write header
536540
self.write_line(b'%PDF-' + version, output)
537541
self.write_line(b'%\xf0\x9f\x96\xa4', output)
@@ -595,8 +599,9 @@ def write(self, output, version=b'1.7', identifier=False, compress=False):
595599
'W': Array(xref_lengths),
596600
'Size': len(self.objects) + 1,
597601
'Root': self.catalog.reference,
598-
'Info': self.info.reference,
599602
}
603+
if self.info:
604+
extra['Info'] = self.info.reference
600605
if identifier:
601606
data = b''.join(obj.data for obj in self.objects if obj.free != 'f')
602607
data_hash = md5(data).hexdigest().encode()
@@ -630,7 +635,6 @@ def write(self, output, version=b'1.7', identifier=False, compress=False):
630635
self.write_line(f'/Size {len(self.objects)}'.encode(), output)
631636
self.write_line(b'/Root ' + self.catalog.reference, output)
632637
if self.info:
633-
self.add_object(self.info)
634638
self.write_line(b'/Info ' + self.info.reference, output)
635639
if identifier:
636640
data = b''.join(

0 commit comments

Comments
 (0)