UPDATE:
The question below is actually very similar to this question on SO which has been perfectly answered by mkl. Short answer: Either live with a bottom-left origin or translate your coordinates to these. There is a workaround but that's a mess.
ORIGINAL QUESTION:
I want to create a PDF with coordinates 0,0 in the upper left and 210, 297 in the bottom right. Approaches with calculations like y = 297 - y seem to be a bit messy.
This question is similar to this question on SO but refers to PdfBox 2 where the the provided solution doesn't work.
The docs say I should use a Matrix to transform the coordinatesystem. I tried this approach:
PDRectangle currentPageRectangle = new PDRectangle(210 * POINTS_PER_MM, 297 * POINTS_PER_MM);
PDPage currentPage = new PDPage(currentPageRectangle);
currentDocument.addPage(currentPage);
contentStream = new PDPageContentStream(currentDocument, currentPage);
AffineTransform a = new AffineTransform(1, 0, 0, -1, 210 * POINTS_PER_MM, 297 * POINTS_PER_MM);
Matrix m = new Matrix(a);
contentStream.transform(m);
Unfortunately the page stays blank. Any clues?