且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过itext pdf库进行图像旋转

更新时间:2023-11-21 17:40:40

使用 setRotationDegrees()方法,使用图像的左下角作为旋转点旋转图像。如果您想要另一个旋转点,则需要使用低级功能来更改CTM。请参阅 addImage()方法rel =nofollow> PdfContentByte class 了解更多信息:

When you set a rotation using the setRotationDegrees() method, the image is rotated using the lower-left corner of the image as its rotation point. If you want another rotation point, you'll need to work with low-level functionality to change the CTM. See the different addImage() methods in the PdfContentByte class for more info:


  • addImage(图像,AffineTransform转换)使用 Image c> com.itextpdf.awt.geom.AffineTransform class。

  • addImage(Image image,float a,float b,float c ,float d,float e,float f)使用由值 a Image / code>, b c d e f 这是3乘3矩阵的元素。例如。 e f 定义翻译。

  • addImage(Image image, AffineTransform transform) adds an Image with the given transformation defined using the com.itextpdf.awt.geom.AffineTransform class.
  • addImage(Image image, float a, float b, float c, float d, float e, float f) adds an Image using a CTM that is defined by the values a, b, c, d, e and f which are elements of a 3 by 3 matrix. E.g. e and f define the translation.

有关坐标系和转换矩阵的更多详细信息,请参阅带有iText的PDF的ABC 一>。这本书还没有完成,但它是免费的,你需要的部分已经存在。

For more detailed info on the coordinate system and the transformation matrices, please read The ABC of PDF with iText. The book isn't finished yet, but it's free and the part you need is already there.

如果你想自己定义旋转,你需要理解两个非常PDF中的重要概念:

If you want to define the rotation yourself, you need to understand two very important concepts in PDF:


  • 坐标系的原点由MediaBox定义。如果媒体框定义如下 [0 0 595 842] (这是一个A4页面)并且没有裁剪框,​​那么坐标系的原点将是较低的页面的左上角。右上角将具有坐标(x = 595; y = 842)。

  • 在PDF中,您不旋转对象。而是旋转坐标系。将对象添加到旋转坐标系时,看起来好像旋转了对象。

  • The origin of the coordinate system is defined by the MediaBox. If the mediabox is defined like this [0 0 595 842] (which is an A4 page) and there is no cropbox, then the origin of the coordinate system will be the lower-left corner of your page. The upper-right corner will have the coordinate (x = 595; y = 842).
  • In PDF, you don't rotate objects. Instead you rotate the coordinate system. When you add an object to a rotated coordinate system, it looks as if the objects are rotated.

所有这些都在ISO中解释-32000-1和ABC书中我开始写作。

All of this is explained in ISO-32000-1 and in the ABC book I started writing.