Imaging - Image files to PDF file

I’m using the Aspose Java Imaging library to convert image files to pdf documents.

When trying to save the image as a PDF I get the following exception;

class com.aspose.imaging.internal.aU.f: Cannot save to the specified format as it is not supported at the moment.
Parameter name: optionsBase
com.aspose.imaging.Image.saveInternal(Unknown Source)
com.aspose.imaging.Image.save(Unknown Source)
com.c.contentservice.converter.document.ImageConverterActor.convertDocument(ImageConverterActor.java:75)
com.c.contentservice.converter.document.ImageConverterActor.onReceive(ImageConverterActor.java:60)
akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167)
akka.actor.Actor$class.aroundReceive(Actor.scala:465)
akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97)
akka.actor.ActorCell.receiveMessage(ActorCell.scala:491)
akka.actor.ActorCell.invoke(ActorCell.scala:462)
akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
akka.dispatch.Mailbox.run(Mailbox.scala:220)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
at com.aspose.imaging.Image.saveInternal(Unknown Source)
at com.aspose.imaging.Image.save(Unknown Source)
at com.c.contentservice.converter.document.ImageConverterActor.convertDocument(ImageConverterActor.java:75)
at com.c.contentservice.converter.document.ImageConverterActor.onReceive(ImageConverterActor.java:60)
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167)
at akka.actor.Actor$class.aroundReceive(Actor.scala:465)
at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:491)
at akka.actor.ActorCell.invoke(ActorCell.scala:462)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
at akka.dispatch.Mailbox.run(Mailbox.scala:220)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
com.aspose.imaging.exceptions.ImageSaveException: Image export failed.
at com.aspose.imaging.Image.saveInternal(Unknown Source)
at com.aspose.imaging.Image.save(Unknown Source)
at com.c.contentservice.converter.document.ImageConverterActor.convertDocument(ImageConverterActor.java:75)
at com.c.contentservice.converter.document.ImageConverterActor.onReceive(ImageConverterActor.java:60)
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167)
at akka.actor.Actor$class.aroundReceive(Actor.scala:465)
at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:491)
at akka.actor.ActorCell.invoke(ActorCell.scala:462)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
at akka.dispatch.Mailbox.run(Mailbox.scala:220)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: class com.aspose.imaging.internal.aU.f: Cannot save to the specified format as it is not supported at the moment.
Parameter name: optionsBase
com.aspose.imaging.Image.saveInternal(Unknown Source)
com.aspose.imaging.Image.save(Unknown Source)
com.c.contentservice.converter.document.ImageConverterActor.convertDocument(ImageConverterActor.java:75)
com.c.contentservice.converter.document.ImageConverterActor.onReceive(ImageConverterActor.java:60)
akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167)
akka.actor.Actor$class.aroundReceive(Actor.scala:465)
akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97)
akka.actor.ActorCell.receiveMessage(ActorCell.scala:491)
akka.actor.ActorCell.invoke(ActorCell.scala:462)
akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
akka.dispatch.Mailbox.run(Mailbox.scala:220)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
… 14 more

The code I have looks like this;

import aspose.pdf.ImageFileType;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.PdfOptions;

final String id = “tempImgConvert” + UUID.randomUUID();

PdfOptions pdfOpts = new PdfOptions();
pdfOpts.setCenterDrawing(true);

Image img = Image.load(is);
img.save(id, pdfOpts);

The image that I’m trying to convert into a PDF is attached. Its just a JPG.

Hi Nathan,

Thank you for considering Aspose products.

I am afraid, the current implementation of Aspose.Imaging APIs does not provide means to convert images to PDF file format. The PdfOptions class that you have referenced in your code is used for the conversion of DXF file format to PDF only. Please note, the Aspose.Imaging API is built in such way that ImageOptions may be used for both conversion (conversion from one file format to another) and to save image changes to stream/disk in the same format because export and save operations are very similar.

I would request you to please use Aspose.PDF for Java API for your requirement as it does support the requested conversion as stated in below linked technical article.
http://www.aspose.com/docs/display/pdfjava/How+to+Convert+an+Image+to+PDF

In case you still insist on having the requested feature implemented in Aspose.Imaging APIs, we surely can log an a ticket and investigate the feasibility on our end.

FYI: Your web site functionality tree shows this to be a valid conversion under the Supported File Formats: C# .NET Cross-platform Image Library API | products.aspose.com

Hi Nathan,

Thank you for writing us back.

Please visit the link Aspose.Imaging - Key Features and view details under section Support For Different File Formats, it is clearly mentioned that export to PDF feature is only available for AutoCAD drawings and DjVu format.

Hope the above information helps. Feel free to contact us in case of any query or comments.