Skip to content

Commit

Permalink
Merge pull request #2503 from omar-ahmed42/fix-page-resize-in-redact-…
Browse files Browse the repository at this point in the history
…img-conversion

Fix: Draw image with the original PDF page dimensions
  • Loading branch information
Frooodle authored Dec 19, 2024
2 parents 95a9e10 + 167c792 commit 2d82c5f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/stirling/software/SPDF/utils/PdfUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,17 @@ public static PDDocument convertPdfToPdfImage(PDDocument document) throws IOExce
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;
Expand Down

0 comments on commit 2d82c5f

Please sign in to comment.