Skip to content

Path objects get copied with incorrect position and scale #1266

@programmarchy

Description

@programmarchy

I have PDF containing a grid, which I merge with a blank page. (The PDF was exported from PowerPoint.) However, the lines in the grid do not get faithfully reproduced. Instead, the lines get shifted over and down. See the following screenshot, with the original at 25% opacity and the output at 100% opacity:

line_bug

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
macOS-12.5.1-arm64-arm-64bit

$ python -c "import PyPDF2;print(PyPDF2.__version__)"
2.10.3

Code + PDF

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

from PyPDF2 import PdfReader, PdfWriter, PageObject

reader = PdfReader('./grid.pdf')
writer = PdfWriter()

page = reader.pages[0]
mediabox = page.mediabox
blank_page = PageObject.create_blank_page(None, mediabox.width, mediabox.height)
page.merge_page(blank_page)
page.mediabox = mediabox
writer.add_page(page)
writer.add_metadata(reader.metadata)

with open('./grid-output.pdf', 'wb') as outfile:
  writer.write(outfile)

grid.pdf

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 PDF

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions