我已经尝试弄清楚如何翻转 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.*,您需要将其添加到页面内容流之前。可以选择保存和恢复图形状态,这对于进一步修改很有用。 (一切基于此answer)
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();
}
关于java - 使用 pdfbox 翻转 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51299800/