PDF框的坐标是相对的还是绝对的? [英] Are PDF box coordinates relative or absolute?

查看:77
本文介绍了PDF框的坐标是相对的还是绝对的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式使用pyPDF编辑PDF.目前,我正在努力解释各种PDF框(TrimBox,MediaBox等)的尺寸.每个盒子都有四个维度,每个维度存储为一个四元组,例如:

I want to programmatically edit a PDF using pyPDF. Currently, I'm struggling with interpreting the various PDF boxes' (TrimBox, MediaBox etc.) dimensions. Each box has four dimensions stored as a four-tuple, e.g.:

TrimBox:           56.69    56.69  1040.31   751.18

根据PDF规范,它们应该描述一个矩形,当然(56.69,  56.69)确定该矩形的左上角.但是,(1040.31,  751.18)是要解释为该矩形的右下角,还是相对于左上角的向量?

According to the PDF specification, these are supposed to describe a rectangle, and certainly (56.69, 56.69) determines the upper left corner of this rectangle. However, is (1040.31, 751.18) to be interpreted as the lower right corner of this rectangle, or as a vector relative to the upper left corner?

显然,在排字机中答案是众所周知的,以至于我找不到到目前为止我在任何地方都可以清楚看到的答案.

Apparently the answer is so well-known among typesetters that I couldn't find it explicitly spelt out anywhere I looked so far.

推荐答案

经过一番修补后,我实际上找到了我的问题的两个答案.就pyPDF源而言,四个框的坐标应读为(x1,y1,x2,y2),其中前两个代表左下角,后两个代表右上角.

After some additional tinkering, I actually found two answers to my question. As far as the pyPDF sources are concerned, the four box coordinates should be read as (x1, y1, x2, y2), where the first two represent the lower left corner and the latter two represent the upper right corner.

但是,当我将坐标解释为(x,y,w,h),其中(x,y)是左上角,而(w,h)的宽度和高度时,PDF的TrimBox内的绘制效果很好源自该矩形的矩形.

However, drawing inside the PDF's TrimBox worked perfectly well when I interpreted the coordinates as (x, y, w, h), where (x, y) is the upper left corner and (w, h) the width and height of the rectangle that originates from there.

因此,我可能会误解第一个解释,但至少第二个解释对我有用.

So, I might have gotten the first interpretation wrong, but at least the second one works for me.

这篇关于PDF框的坐标是相对的还是绝对的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆