Fitz draw_rect 坐标

huangapple go评论65阅读模式
英文:

Fitz draw_rect coordination

问题

我在PDF文件中的名字字段与正方形的正确重叠坐标协调方面遇到了困难。这是我的PDF文件链接:

https://docdro.id/wiAwsH8

我想要实现这样的效果:

Fitz draw_rect 坐标

这是我的代码:

import fitz

page = fitz.open('ABCZ01S0112_Canon iR-ADV C256_1388_0012.pdf')

for p in page:
    # 对于每一页,在坐标(1,1)(100,100)上绘制一个矩形
    p.draw_rect([100, 0, 5, 500], color=(0, 0, 0), width=100)

# 保存PDF
page.save('name.pdf')

但我仍然无法找到正确的坐标。

英文:

I am struggling with right coordination of square to overlap the name field in pdf file.
This is my pdf file

https://docdro.id/wiAwsH8

I would like to get this

Fitz draw_rect 坐标

This is my code

import fitz
    page = fitz.open('ABCZ01S0112_Canon iR-ADV C256_1388_0012.pdf')
    for p in page:
        # For every page, draw a rectangle on coordinates (1,1)(100,100)
        p.draw_rect([100,0,5,500],  color = (0, 0, 0), width = 100)
    # Save pdf
    page.save('name.pdf')

But still I am not able to find right coordinations

答案1

得分: 1

我无法下载你的PDF文件,所以这只是一个猜测:尝试将 page.mediabox.y0 添加到你矩形的 y 坐标,例如:

p.draw_rect([100, 0 + p.mediabox.y0, 5, 500 + p.mediabox.y0], color=(0, 0, 0), width=100)
英文:

I can't download your PDF file so this is only a guess: try adding page.mediabox.y0 to your rectangle's y coordinates, for example:

    p.draw_rect([100, 0 + p.mediabox.y0, 5, 500 + p.mediabox.y0],  color = (0, 0, 0), width = 100)

huangapple
  • 本文由 发表于 2023年2月23日 22:24:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546121.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定