Skip to content

Commit 27217a2

Browse files
committed
PDFBOX-6191: fix transform, by Valery Bokov
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1933108 13f79535-47bb-0310-9956-ffa450edef68
1 parent 29e5d98 commit 27217a2

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,15 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
270270
}
271271
}
272272

273+
AffineTransform printerBorderTransform = printerGraphics.getTransform();
274+
double borderScale = scale;
275+
273276
// rasterize to bitmap (optional)
274277
BufferedImage image = null;
275278
if (rasterDpi > 0)
276279
{
277-
LOG.debug("dpi set to {}", rasterDpi);
278280
float dpiScale = rasterDpi / 72;
281+
LOG.info("rasterDpi: {}, dpiScale: {}", rasterDpi, dpiScale);
279282
image = new BufferedImage((int)(imageableWidth * dpiScale / scale),
280283
(int)(imageableHeight * dpiScale / scale),
281284
BufferedImage.TYPE_INT_ARGB);
@@ -288,23 +291,11 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
288291
}
289292

290293
// draw to graphics using PDFRender
291-
AffineTransform transform = graphics2D.getTransform();
292294
graphics2D.setBackground(Color.WHITE);
293295
renderer.setSubsamplingAllowed(subsamplingAllowed);
294296
renderer.setRenderingHints(renderingHints);
295297
renderer.renderPageToGraphics(pageIndex, graphics2D, (float) scale, (float) scale, RenderDestination.PRINT);
296298

297-
// draw crop box
298-
if (showPageBorder)
299-
{
300-
graphics2D.setTransform(transform);
301-
graphics2D.setClip(0, 0, (int)imageableWidth, (int)imageableHeight);
302-
graphics2D.scale(scale, scale);
303-
graphics2D.setColor(Color.GRAY);
304-
graphics2D.setStroke(new BasicStroke(0.5f));
305-
graphics2D.drawRect(0, 0, (int)cropBox.getWidth(), (int)cropBox.getHeight());
306-
}
307-
308299
// draw rasterized bitmap (optional)
309300
if (image != null)
310301
{
@@ -313,6 +304,18 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
313304
printerGraphics.drawImage(image, 0, 0, null);
314305
}
315306

307+
// draw crop box on the printer graphics (always, whether rasterizing or not).
308+
// Drawing after the blit avoids losing the thin stroke during raster scale-down.
309+
if (showPageBorder)
310+
{
311+
printerGraphics.setTransform(printerBorderTransform);
312+
printerGraphics.setClip(0, 0, (int) imageableWidth, (int) imageableHeight);
313+
printerGraphics.scale(borderScale, borderScale);
314+
printerGraphics.setColor(Color.GRAY);
315+
printerGraphics.setStroke(new BasicStroke(0.5f));
316+
printerGraphics.drawRect(0, 0, (int) cropBox.getWidth(), (int) cropBox.getHeight());
317+
}
318+
316319
return PAGE_EXISTS;
317320
}
318321
catch (IOException e)

0 commit comments

Comments
 (0)