Merge pull request #2503 from omar-ahmed42/fix-page-resize-in-redact-img-conversion

Fix: Draw image with the original PDF page dimensions
This commit is contained in:
Anthony Stirling 2024-12-19 11:49:18 +00:00 committed by GitHub
commit 2d82c5fa77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -352,12 +352,17 @@ public class PdfUtils {
pdfRenderer.setSubsamplingAllowed(true);
for (int page = 0; page < document.getNumberOfPages(); ++page) {
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
PDPage newPage = new PDPage(new PDRectangle(bim.getWidth(), bim.getHeight()));
PDPage originalPage = document.getPage(page);
float width = originalPage.getMediaBox().getWidth();
float height = originalPage.getMediaBox().getHeight();
PDPage newPage = new PDPage(new PDRectangle(width, height));
imageDocument.addPage(newPage);
PDImageXObject pdImage = LosslessFactory.createFromImage(imageDocument, bim);
PDPageContentStream contentStream =
new PDPageContentStream(imageDocument, newPage, AppendMode.APPEND, true, true);
contentStream.drawImage(pdImage, 0, 0);
contentStream.drawImage(pdImage, 0, 0, width, height);
contentStream.close();
}
return imageDocument;