We are getting error when converting attached JPG images to PDF.
original Image files size is 4.8MB:
Figure 2.jpg (184.0 KB)
Note: But the size of image is compressed to 184.KB after attached here.
com.aspose.words.Document document = new com.aspose.words.Document();
DocumentBuilder builder = new DocumentBuilder(document);
builder.getPageSetup().setPaperSize(PaperSize.A4);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
BufferedImage bf = null;
try
{
// We try it with ImageIO
bf = ImageIO.read(inputStream);
}
catch (CMMException ex)
{
// If we failed...
// We reset the inputStream (start from the beginning)
inputStream.reset();
// And use JAI
bf = JAI.create("stream", SeekableStream.wrapInputStream(inputStream, true)).getAsBufferedImage();
}
Shape shape = builder.insertImage(bf);
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setHorizontalAlignment(HorizontalAlignment.Center.getValue());
shape.setVerticalAlignment(VerticalAlignment.Center.getValue());
document.save(directoryPath + PATH_SEPARATOR + outputFileName, com.aspose.words.SaveFormat.PDF);
LOGGER.info(MessageConstants.CONVERTED_IMAGE_TO_PDF);
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-total</artifactId>
<version>23.8</version>
<type>pom</type>
</dependency>