From ccdd4200fda452871d0e727cfca81690bcaf4833 Mon Sep 17 00:00:00 2001 From: Tilman Hausherr Date: Fri, 29 Nov 2024 04:27:09 +0000 Subject: [PATCH] PDFBOX-5911: -1 dpi for automatic calculation git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922212 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/pdfbox/printing/PDFPrintable.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java b/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java index 9a8f8d45ece..b2c9b512dc2 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java @@ -253,9 +253,18 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) // rasterize to bitmap (optional) Graphics2D printerGraphics = null; BufferedImage image = null; - if (dpi > 0) + if (dpi > 0 || dpi == -1) { - float dpiScale = dpi / 72; + float dpiScale; + if (dpi == -1) + { + dpiScale = (float) graphics2D.getTransform().getScaleX(); + LOG.debug("dpi set to " + Math.round(graphics2D.getTransform().getScaleX() * 72)); + } + else + { + dpiScale = dpi / 72; + } image = new BufferedImage((int)(imageableWidth * dpiScale / scale), (int)(imageableHeight * dpiScale / scale), BufferedImage.TYPE_INT_ARGB);