Author: tilman
Date: Thu Apr 16 14:02:18 2026
New Revision: 1933108

Log:
PDFBOX-6191: fix transform, by Valery Bokov

Modified:
   
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java  
    Thu Apr 16 14:02:15 2026        (r1933107)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java  
    Thu Apr 16 14:02:18 2026        (r1933108)
@@ -270,12 +270,15 @@ public final class PDFPrintable implemen
                 }
             }
 
+            AffineTransform printerBorderTransform = 
printerGraphics.getTransform();
+            double borderScale = scale;
+
             // rasterize to bitmap (optional)
             BufferedImage image = null;
             if (rasterDpi > 0)
             {
-                LOG.debug("dpi set to {}", rasterDpi);
                 float dpiScale = rasterDpi / 72;
+                LOG.info("rasterDpi: {}, dpiScale: {}", rasterDpi, dpiScale);
                 image = new BufferedImage((int)(imageableWidth * dpiScale / 
scale),
                                           (int)(imageableHeight * dpiScale / 
scale),
                                           BufferedImage.TYPE_INT_ARGB);
@@ -288,23 +291,11 @@ public final class PDFPrintable implemen
             }
 
             // draw to graphics using PDFRender
-            AffineTransform transform = graphics2D.getTransform();
             graphics2D.setBackground(Color.WHITE);
             renderer.setSubsamplingAllowed(subsamplingAllowed);
             renderer.setRenderingHints(renderingHints);
             renderer.renderPageToGraphics(pageIndex, graphics2D, (float) 
scale, (float) scale, RenderDestination.PRINT);
 
-            // draw crop box
-            if (showPageBorder)
-            {
-                graphics2D.setTransform(transform);
-                graphics2D.setClip(0, 0, (int)imageableWidth, 
(int)imageableHeight);
-                graphics2D.scale(scale, scale);
-                graphics2D.setColor(Color.GRAY);
-                graphics2D.setStroke(new BasicStroke(0.5f));
-                graphics2D.drawRect(0, 0, (int)cropBox.getWidth(), 
(int)cropBox.getHeight());
-            }
-
             // draw rasterized bitmap (optional)
             if (image != null)
             {
@@ -313,6 +304,18 @@ public final class PDFPrintable implemen
                 printerGraphics.drawImage(image, 0, 0, null);
             }
 
+            // draw crop box on the printer graphics (always, whether 
rasterizing or not).
+            // Drawing after the blit avoids losing the thin stroke during 
raster scale-down.
+            if (showPageBorder)
+            {
+                printerGraphics.setTransform(printerBorderTransform);
+                printerGraphics.setClip(0, 0, (int) imageableWidth, (int) 
imageableHeight);
+                printerGraphics.scale(borderScale, borderScale);
+                printerGraphics.setColor(Color.GRAY);
+                printerGraphics.setStroke(new BasicStroke(0.5f));
+                printerGraphics.drawRect(0, 0, (int) cropBox.getWidth(), (int) 
cropBox.getHeight());
+            }
+
             return PAGE_EXISTS;
         }
         catch (IOException e)

Reply via email to