Why are the page sizes obtained from reading a document different from those obtained from creating a new document? #4298
Answered
by
JorjMcKie
HelloKitty2022
asked this question in
Looking for help
-
Beta Was this translation helpful? Give feedback.
Answered by
JorjMcKie
Feb 16, 2025
Replies: 2 comments 3 replies
-
I don't understand what you are doing or even what you mean. You little function as such seems to do what you want - see following post. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This works fine: import pymupdf
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()
doc1 = pymupdf.open("normal.pdf")
draw_test_pattern(doc1[0], "Pattern")
doc1.save(doc1.name.replace(".pdf", "-new.pdf"))
doc2 = pymupdf.open("PrintPic.pdf")
draw_test_pattern(doc2[0], "Pattern")
doc2.save(doc2.name.replace(".pdf", "-new.pdf")) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My output is perfect:
Printpic.pdf: