Skip to content

Commit

Permalink
Merge pull request #552 from sbplat/main
Browse files Browse the repository at this point in the history
fix: use JPEGFactory for jpeg
  • Loading branch information
Frooodle authored Dec 24, 2023
2 parents c681f48 + 344d116 commit 914dd0a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/stirling/software/SPDF/utils/PdfUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ public static byte[] imageToPdf(MultipartFile[] files, String fitOption, boolean
} else {
BufferedImage image = ImageIO.read(file.getInputStream());
BufferedImage convertedImage = ImageProcessingUtils.convertColorType(image, colorType);
PDImageXObject pdImage = LosslessFactory.createFromImage(doc, convertedImage);
// Use JPEGFactory if it's JPEG since JPEG is lossy
PDImageXObject pdImage = (contentType != null && contentType.equals("image/jpeg"))
? JPEGFactory.createFromImage(doc, convertedImage)
: LosslessFactory.createFromImage(doc, convertedImage);
addImageToDocument(doc, pdImage, fitOption, autoRotate);
}
}
Expand Down

0 comments on commit 914dd0a

Please sign in to comment.