问题描述
我正在尝试使用Apache PDFBox库旋转矩形,但是我已经对其进行了谷歌搜索,但没有显示任何内容。这里是一些代码:
PDPage page = document.getPage(i-1);
PDPageContentStream contentStream = new PDPageContentStream(document,page,true,false,false);
contentStream.setNonStrokingColor(Color.BLACK);
contentStream.addRect(dto.getLeft(),dto.getTop() - factY,dto.getWidth(),dto.getHeight());
contentStream.fill();
contentStream.close();
解决方法
这是PDFBox 2.0。*的答案,它绘制了一个围绕其左下角原点旋转的框:
// draw a filled box with rect x=200,y=500,w=200,h=100
contents.saveGraphicsState();
contents.transform(Matrix.getRotateInstance(Math.toRadians(105),200,500));
contents.addRect(0,100);
contents.fill();
contents.restoreGraphicsState();
现在将Math.toRadians(105)
更改为所需的角度,即可旋转矩形。
您似乎正在使用旧版本的PDFBox。我强烈建议改用2.0。*。