Skip to content

pdf.set_display_mode(zoom=...) not working #926

@macdeport

Description

@macdeport

I discovered fpdf2 and tried it out. Thanks for this interesting library.

Describe the bug

Error details
I couldn't make

pdf.set_display_mode(zoom=25)

works to produce a PDF that opens at a scale of 25%...

Minimal code
Please include some minimal Python code reproducing your issue:

from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_display_mode(zoom=50)
pdf.output('test_zoom.pdf')

If you don't know how to build a minimal reproducible example, please check this tutorial: https://stackoverflow.com/help/minimal-reproducible-example

Environment
Please provide the following information:

  • Operating System: Mac OSX
  • Python version: Python 3.9.18
  • fpdf2 version used: 2.7.5

Proposed fix
If I'm not mistaken...

In output.py > _finalize_catalog() after :

 # zoom_mode is a number, not one of the allowed strings:
 zoom_config = ["/XYZ", "null", "null", str(fpdf.zoom_mode / 100)]

add :

    zoom_config = [
        pdf_ref(first_page_obj.id),
        *zoom_config]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions