[
https://issues.apache.org/jira/browse/PDFBOX-6191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18073821#comment-18073821
]
valery commented on PDFBOX-6191:
--------------------------------
Another approach.
The gist of the fix (PDFPrintable.print):
1. Save the printerGraphics transform and scale before the rasterizer modifies
them.
2. Transfer the border drawing (showPageBorder) to the printer after blitting
the raster.
3. Draw the border on printerGraphics (not on the graphics2D raster), using the
saved transform and scale.
The lines 273-319:
{code:java}
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;
image = new BufferedImage((int)(imageableWidth * dpiScale /
scale),
(int)(imageableHeight * dpiScale /
scale),
BufferedImage.TYPE_INT_ARGB);
graphics2D = image.createGraphics();
// rescale
printerGraphics.scale(scale / dpiScale, scale / dpiScale);
scale = dpiScale;
}
// draw to graphics using PDFRender
graphics2D.setBackground(Color.WHITE);
renderer.setSubsamplingAllowed(subsamplingAllowed);
renderer.setRenderingHints(renderingHints);
renderer.renderPageToGraphics(
pageIndex, graphics2D, (float) scale, (float) scale,
RenderDestination.PRINT);
// draw rasterized bitmap (optional)
if (image != null)
{
printerGraphics.setBackground(Color.WHITE);
printerGraphics.clearRect(0, 0, image.getWidth(),
image.getHeight());
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;
{code}
> Print border doesn't work if using rastering
> --------------------------------------------
>
> Key: PDFBOX-6191
> URL: https://issues.apache.org/jira/browse/PDFBOX-6191
> Project: PDFBox
> Issue Type: Bug
> Components: Rendering
> Affects Versions: 2.0.36, 3.0.7 PDFBox
> Reporter: Tilman Hausherr
> Priority: Major
> Attachments: Paulmann-70919_V01-MaxLED-Universal-Verbinder.pdf,
> image-2026-04-15-06-35-11-685.png, printout-300dpi.pdf
>
>
> As discovered by [~vbokov] in PR440
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]