Merge pull request #552 from sbplat/main

fix: use JPEGFactory for jpeg
This commit is contained in:
Anthony Stirling 2023-12-24 18:02:12 +00:00 committed by GitHub
commit 914dd0a21a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -266,7 +266,10 @@ public class PdfUtils {
} else { } else {
BufferedImage image = ImageIO.read(file.getInputStream()); BufferedImage image = ImageIO.read(file.getInputStream());
BufferedImage convertedImage = ImageProcessingUtils.convertColorType(image, colorType); 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); addImageToDocument(doc, pdImage, fitOption, autoRotate);
} }
} }