Reputation: 71
I'm trying to rotate a rectangle with the Apache PDFBOX Library but I've googled it and nothing shows up. Here's some of the code:
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();
Upvotes: 1
Views: 843
Reputation: 18851
Here's an answer for PDFBox 2.0.* which draws a box rotated around its bottom left origin:
// 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, 0, 200, 100);
contents.fill();
contents.restoreGraphicsState();
Now change Math.toRadians(105)
to the desired angle and you have your rotated rectangle.
You seem to be using an older version of PDFBox. I strongly recommend to use 2.0.* instead.
Upvotes: 1