使用 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屋!