Java 使用pdfbox翻转PDF

Java 使用pdfbox翻转PDF,java,pdf,pdfbox,flip,Java,Pdf,Pdfbox,Flip,我一直想弄清楚如何翻转pdf有一段时间了,但还没有弄清楚。 我只找到了如何使用Graphics2D翻转图像: // Flip the image vertically AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -image.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransfor

我一直想弄清楚如何翻转pdf有一段时间了,但还没有弄清楚。 我只找到了如何使用Graphics2D翻转图像:

// Flip the image vertically
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -image.getHeight(null));
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
image = op.filter(image, null);
你能帮我用PDFbox拿吗


谢谢

使用PDFBox 2.*时,需要将其预先添加到页面内容流中。可选择保存和恢复图形状态,对进一步修改有用。(全部基于此)


嗨,你知道如何在中间翻转吗?因为我不希望我的位置会改变,但它确实会围绕(垂直)中心翻转。出什么事了?你是对的。。我发现了我的问题,再次谢谢你!
PDPage page = doc.getPage(0);
try (PDPageContentStream cs = new PDPageContentStream(doc, page, PDPageContentStream.AppendMode.PREPEND, true))
{
    cs.saveGraphicsState();
    cs.transform(Matrix.getScaleInstance(1, -1));
    cs.transform(Matrix.getTranslateInstance(0, -page.getCropBox().getHeight()));
    cs.saveGraphicsState();
}
try (PDPageContentStream cs = new PDPageContentStream(doc, page, PDPageContentStream.AppendMode.APPEND, true))
{
    cs.restoreGraphicsState();
    cs.restoreGraphicsState();
}