PDF页面的Origin(x,y)在哪里? [英] Where is the Origin (x,y) of a PDF page?

查看:141
本文介绍了PDF页面的Origin(x,y)在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iText创建我的PDF文件。我想使用我在这里找到的方法将文本放在文档中的某个特定位置。但是,我无法弄清楚在哪里可以找到页面坐标系的原点。 左下角?,右上角右下角?,左上角?这个来源在哪里?

I am using iText to create my PDF files. I want to position text at some specific place in the document using the method I found here. However, I cannot figure out where to find the origin of the coordinate system of the page. bottom left corner?,top right corner?bottom right corner?,top left corner? Where is this origin?

推荐答案

页面的维度(也就是页面边界)是在页面字典中定义的:

The dimensions of a page (aka the page boundaries) are defined in a page dictionary:


  • / MediaBox :物理媒体(页面)的边界。此值是必填项,因此您可以在每个PDF中找到它。

  • / CropBox :显示时可见的区域或打印。 / CropBox 等于或小于 / MediaBox 。该值是可选的;如果它丢失了, / CropBox 等于 / MediaBox

  • 其他可能的值是 / BleedBox / TrimBox / ArtBox 。这些已经被定义用于特定目的,但是它们不再被使用。如果它们丢失,则默认为 / CropBox 。这些值都不会超出 / CropBox

  • /MediaBox: the boundaries of the physical medium (the page). This value is mandatory, so you'll find it in every PDF.
  • /CropBox: the region that is visible when displayed or printed. The /CropBox is equal to or smaller than the /MediaBox. This value is optional; if it's missing, the /CropBox is equal to the /MediaBox.
  • Other possible values are the /BleedBox, /TrimBox and /ArtBox. These have been defined for specific purposes, but they aren't used that often anymore. If they are missing, they default to the /CropBox. None of these values can outsize the /CropBox.

创建时使用iText的文档,您可以显式或隐式定义 / MediaBox

When you create a document with iText, you define the /MediaBox either explicitly or implicitly.

明确地:

Rectangle rect = new Rectangle(20, 20, 300, 600);
Document document = new Document(rect);

隐含地:

Document document = new Document();

此单行相当于:

Rectangle rect = new Rectangle(0, 0, 595, 842);
Document document = new Document(rect);

传递给 Rectangle 构造函数的四个参数( llx lly urx ury )使用左下角和右上角的x和y坐标定义一个矩形。

The four parameters passed to the Rectangle constructor (llx, lly, urx, ury) define a rectangle using the x and y coordinates of the lower-left and the upper-right corner.

如果是 new Rectangle(0,0,595,842),页面的左下角与坐标系的原点(0, 0)。页面的右上角与坐标(595,842)重合。

In case of new Rectangle(0, 0, 595, 842), the lower-left corner of the page coincides with the origin of the coordinate system (0, 0). The upper-right corner of the page coincides with the coordinate (595, 842).

所有测量都已定义在用户单位中,默认情况下,用户单位大致与印刷点对应:1个用户单位= 1个点。

All measurements are defined in user units, and by default, the user units roughly corresponds with the typographic point: 1 user unit = 1 point.

注意单词粗略:我们使用点进行计算,但在ISO标准中,我们非常谨慎,不使用point作为用户单元的同义词。例如:一个A4页面用892个用户单位测量595,但是如果你用点计算精确值,则会有一点点差异(点后的一些数字)。

Note the word roughly: we use points to do calculations, but in the ISO standard, we are very cautious not to use point as a synonym for user unit. For instance: an A4 page measures 595 by 842 user units, but if you'd calculate the exact value in points, there would be a slight difference (some numbers after the point).

页面的左下角并不总是坐标系的原点。如果我们使用 Rectangle(20,20,300,600)定义页面,则原点是下方20个用户单位,左下角左侧是20个用户单位。也可以使用负值来定义页面大小。

The lower-left corner of the page isn't always the origin of the coordinate system. If we define a page using Rectangle(20, 20, 300, 600), the origin is 20 user units below and 20 user units to the left of the lower-left corner. It's also possible to use negative values to define a page size.

例如:假设您要创建一个包含4个A4页面的A2文档,而不是您可以定义的页面大小如下:

For instance: suppose that you want to create an A2 document consisting of 4 A4 pages, than you could define the page sizes like this:

Rectangle(-595, 0, 0, 842)   Rectangle(0, 0, 595, 842)
Rectangle(-595, -842, 0, 0)  Rectangle(0, -842, 595, 0);

通过这样定义媒体框,您还可以传递有关不同相对位置的信息页面。如果您将4个A4页面视为一个单位,坐标系的原点就是A2页面的确切中心。

By defining the media box like this, you also pass information with respect to the relative position of the different pages. If you look at the 4 A4 pages as a unit, the origin of the coordinate system is the exact center of the A2 page.

重要:

以上所有假设您没有引入任何坐标转换,例如使用 concatCTM() transform()方法。这些方法允许您更改坐标系,例如将x轴和y轴之间的角度从90度(默认值)更改为另一个角度。您还可以缩放轴以获得不同的宽高比。虽然这样做很有趣,但它需要相当多的数学。

All of the above assumes that you didn't introduce any coordinate transformations, e.g. using the concatCTM() or transform() method. These methods allow you to change the coordinate system, for instance change the angle between the x and y axis from 90 degrees (the default) to another angle. You can also scale an axis to get a different aspect ratio. While it's certainly fun to do this, it requires quite some Math.

这篇关于PDF页面的Origin(x,y)在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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