We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

EML to PDF conversion throws javax.imageio.IIOException using Java

Hi Team,
I am facing issue in JPEG image conversion into PDF.

Aspose version 18.5
server : windows 2016
I need reason of failing conversion
IMG_20200706_204657.jpg (3.0 MB)

I am getting below exception in logs
09:22:33.002 [http-nio-8080-exec-6] ERROR c.g.p.b.impl.AsposeDocumentProvider : Conversion failed
javax.imageio.IIOException: Not a JPEG file: starts with 0xff 0xe1

input file : IMG_20200706_204657.jpg
code:
Document imageDocument = new Document();
DocumentBuilder builder = new DocumentBuilder(imageDocument);

// Load images from the disk using the approriate reader.
// The file formats that can be loaded depends on the image readers available on
// the machine.
ImageInputStream iis = ImageIO.createImageInputStream(docInputStream);
ImageReader reader = ImageIO.getImageReaders(iis).next();
reader.setInput(iis, false);
// Get the number of frames in the image.
int framesCount = reader.getNumImages(true);

// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++) {
// Insert a section break before each new page, in case of a multi-frame image.
if (frameIdx != 0)
					builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);

// Select active frame.
BufferedImage image = reader.read(frameIdx);

// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.getPageSetup();

ps.setPageWidth(ConvertUtil.pixelToPoint(image.getWidth()));
ps.setPageHeight(ConvertUtil.pixelToPoint(image.getHeight()));

// Insert the image into the document and position it at the top left corner of
// the page.
builder.insertImage(image, RelativeHorizontalPosition.PAGE, 0, RelativeVerticalPosition.PAGE, 0,ps.getPageWidth(), ps.getPageHeight(), WrapType.NONE);

imageDocument.save(output, com.aspose.words.SaveFormat.PDF);

regards
Tarun

@genpact,

Your issue seems related to Aspose.Words rather Aspose.Imaging. I suggest you to please try using latest Aspose.Words version on your end. In case there is still an issue please share the feedback with us.