Skip to content

Unterminated object when using PdfWriter with incremental=True #3118

Open
@m32

Description

@m32

Environment

Linux-6.1.0-31-amd64-x86_64-with-glibc2.36
pypdf==5.3.0, crypt_provider=('cryptography', '44.0.0'), PIL=11.1.0

Code + PDF

This is a minimal, complete example that shows the issue:

import fpdf
doc = fpdf.FPDF()
doc.set_compression(0)
font = 'helvetica'

for i in range(2):
    doc.add_page()
    doc.set_font(font, '', 13.0)
    link = None
    doc.cell(w=75.0, h=22.0, align='C', text='Hello, world page=%d.' % i, border=0, new_x=fpdf.XPos.LEFT, new_y=fpdf.YPos.NEXT, link=link)
doc.output('pdf.pdf')

import io
from pypdf import PdfReader, PdfWriter

stream = io.BytesIO()
writer = PdfWriter('pdf.pdf', incremental=True)
writer.add_blank_page(72, 72)
writer.write(stream)
with open('pdf-out.pdf', 'wb') as fp:
    fp.write(stream.getvalue())

Last object in generated pdf is XRef table but it has no endobj tag:
12 0 obj<<
/Type /XRef
...
/Length 18

stream
....
endstream
endobj <- this element is missing
startxref
1742
%%EOF

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFworkflow-mergeFrom a users perspective, merging is the affected feature/workflow

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions