使用PDFBox旋转图像 [英] Image rotation with PDFBox
问题描述
我不再使用PDFBox了。我需要的是将一个带旋转的图像添加到现有的PDF中!我知道如何添加图像,但我的问题是如何旋转图像!我已经看过一些关于AffineTransform和Matrix的东西,但我不知道它是什么以及它是如何工作的!
I am quit new to using PDFBox. What I need is to add an image with rotation to an exiting PDF! I know how to add the image, but my problem is how to rotate the image! I've seen somethign about AffineTransform and Matrix but I have no idea what is that and how it works!
我真的很感激传递一些示例代码,谢谢提前!
I'd really appreciate passing some sample code, and thank you in advance!
最好的问候
推荐答案
有助于了解简单图像显示方法的来源:
It helps to look at the source of the "simple" image display method:
public void drawXObject(PDXObject xobject, float x, float y, float width, float height)
{
AffineTransform transform = new AffineTransform(width, 0, 0, height, x, y);
drawXObject(xobject, transform);
}
所以这就是你用(200,200)显示图像的方法旋转45°:
so this is what you do to display an image at (200,200) with a rotation of 45°:
AffineTransform at = new AffineTransform(ximage.getWidth(), 0, 0, ximage.getHeight(), 200, 200);
at.rotate(Math.toRadians(45));
contentStream.drawXObject(ximage, at);
Re:AffineTransform:这是几何的子主题。要获得介绍,请阅读此处的Java说明。
Re: AffineTransform: this is a subtopic of geometry. To get an introduction, read the java description here.
这篇关于使用PDFBox旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!