Image rotation with PDFBox

痞子三分冷 提交于 2019-12-23 20:31:16

问题


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!

Best Regards


回答1:


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);
 }

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: this is a subtopic of geometry. To get an introduction, read the java description here.



来源:https://stackoverflow.com/questions/23867451/image-rotation-with-pdfbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!