通过itext pdf库进行图像旋转 [英] Image rotation via itext pdf library

查看:777
本文介绍了通过itext pdf库进行图像旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过在java程序中使用itext pdf库从中心或任何固定点旋转图像。当我旋转图像时,它的x和y坐标会发生变化。请帮助我。

I am unable to rotate image from center or any fixed point by using itext pdf library in java program.When i rotate image it's x and y cordinate gets changed. Kindly help me in this regard.

   Image pdfImage=Image.getInstance("assets/product.png");
    pdfImage.setAlignment(Element.ALIGN_CENTER);
    pdfImage.setRotationDegrees(30);
    document.add(pdfImage);
   pdfImage.setRotationDegrees(140);
    document.add(pdfImage);

在上面的代码中,没有相同的点来判断旋转点。

In above code there is no same point by which I can judge the rotation point.

提前致谢

推荐答案

使用<$ c $设置轮换时c> 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转换)使用<$ c $定义的给定转换添加 Image c> com.itextpdf.awt.geom.AffineTransform class。

  • addImage(Image image,float a,float b,float c ,float d,float e,float f)使用由值 a <定义的CTM添加 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.

这篇关于通过itext pdf库进行图像旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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