enter image description here – Original position of image
enter image description here- Zoom in image
How can I make text and words readable, clear, good quality image?
Source code:
private Pane createPagePane(int pageIndex, PDDocument document, PDFRenderer renderer, AnchorPane anchorPane) throws IOException {
PDPage page = document.getPage(pageIndex);
PDRectangle pageSize = page.getMediaBox();
boolean isLandscape = pageSize.getWidth() > pageSize.getHeight();
double widthToFit = anchorPane.getPrefWidth();
double heightToFit = anchorPane.getPrefHeight();
double scaleFactor = isLandscape ? Math.min(widthToFit / pageSize.getWidth(), heightToFit / pageSize.getHeight())
: Math.min(heightToFit / pageSize.getWidth(), widthToFit / pageSize.getHeight());
int targetWidth = (int) (pageSize.getWidth() * scaleFactor);
int targetHeight = (int) (pageSize.getHeight() * scaleFactor);
BufferedImage bufferedImage = renderer.renderImage(pageIndex, (float) scaleFactor, ImageType.RGB);
BufferedImage backgroundImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = backgroundImage.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setColor(java.awt.Color.WHITE);
g2d.fillRect(0, 0, targetWidth, targetHeight);
g2d.drawImage(bufferedImage, 0, 0, targetWidth, targetHeight, null);
g2d.dispose();
Image fxImage = SwingFXUtils.toFXImage(backgroundImage, null);
ImageView imageView = new ImageView(fxImage);
imageView.setFitWidth(targetWidth);
imageView.setFitHeight(targetHeight);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
Pane pagePane = new Pane(imageView);
pagePane.setPrefSize(targetWidth, targetHeight);
pagePane.setOnMouseClicked(event -> {
pagePane.getStyleClass().add("selected-pane");
});
rectMouseInteraction(pagePane, document, pageIndex, scaleFactor);
return pagePane;
}
What I am expecting is like this outcome:
enter image description here – This was also converted and created via Buffered image.
I want mine to be like this quality even I zoom in the image.
New contributor
Weslie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.