Skip to content

Why are the page sizes obtained from reading a document different from those obtained from creating a new document? #4296

@HelloKitty2022

Description

@HelloKitty2022

Description of the bug

import fitz

def compare_page_matrices():
# 打开原始PDF
doc1 = fitz.open("input.pdf")
page1 = doc1[0]

# 创建新的PDF
doc2 = fitz.open()
page2 = doc2.new_page(width=595.32, height=841.92)

# 在两个页面上绘制相同的测试图形
def draw_test_pattern(page, label):
    shape = page.new_shape()
    
    # 画边框
    shape.draw_rect(page.rect)
    shape.finish(width=2, color=(0, 0, 0))
    
    # 画四个角的圆圈
    for x, y, color in [
        (0, 0, (1, 0, 0)),           # 左下 - 红
        (0, page.rect.height, (0, 1, 0)),     # 左上 - 绿
        (page.rect.width, 0, (0, 0, 1)),      # 右下 - 蓝
        (page.rect.width, page.rect.height, (1, 1, 0))  # 右上 - 黄
    ]:
        shape.draw_circle((x, y), 20)
        shape.finish(fill=color)
        shape.insert_text(
            (x + 25, y + 25),
            f"{label} ({x:.0f}, {y:.0f})",
            fontsize=12,
            color=color
        )
    
    shape.commit()

# 在两个页面上绘制
draw_test_pattern(page1, "原PDF")
draw_test_pattern(page2, "新PDF")

# 保存结果
doc1.save("test_original.pdf")
doc2.save("test_new.pdf")

# 关闭文档
doc1.close()
doc2.close()

print("测试文件已保存为 'test_original.pdf' 和 'test_new.pdf'")

if name == "main":
compare_page_matrices()

How to reproduce the bug

Why are the page sizes obtained from reading a document different from those obtained from creating a new document?

PyMuPDF version

1.25.3

Operating system

Windows

Python version

3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    not a bugnot a bug / user error / unable to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions