Using com.aspose.pdf.Image with version 11.6.0.jar

Hi, I have this snippet in my program and it throws an error message like:

Error message:

Exception in thread “main” java.lang.Error: Unresolved compilation problems:
The constructor Image(Section) is undefined
The method add(Paragraph) in the type Paragraphs is not applicable for the arguments (Image)
The method getImageInfo() is undefined for the type Image
The method getImageInfo() is undefined for the type Image

My snippet:
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create an image object in the section
com.aspose.pdf.Image img1 = new com.aspose.pdf.Image(sec1);
// Add image object into the Paragraphs collection of the section
sec1.getParagraphs().add(img1);
// Set the path of image file
img1.getImageInfo().setFile(strBarCodeImageSave);
img1.getImageInfo().setTitle(“JPEG image”);
// Save the Pdf
FileOutputStream out = new FileOutputStream(new File(strPdfDoc));
pdf1.save(out);


Why is it happening? Sorry my dumb post. I’m a total newbie at aspose.pdf

We have a license for aspose.Total
carloymoriones:
Hi, I have this snippet in my program and it throws an error message like:

Error message:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor Image(Section) is undefined
The method add(Paragraph) in the type Paragraphs is not applicable for the arguments (Image)
The method getImageInfo() is undefined for the type Image
The method getImageInfo() is undefined for the type Image

My snippet:
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create an image object in the section
com.aspose.pdf.Image img1 = new com.aspose.pdf.Image(sec1);
// Add image object into the Paragraphs collection of the section
sec1.getParagraphs().add(img1);
// Set the path of image file
img1.getImageInfo().setFile(strBarCodeImageSave);
img1.getImageInfo().setTitle("JPEG image");
// Save the Pdf
FileOutputStream out = new FileOutputStream(new File(strPdfDoc));
pdf1.save(out);


Why is it happening? Sorry my dumb post. I'm a total newbie at aspose.pdf

We have a license for aspose.Total

Hi,
Any replies?

Hi Carlo,


Thanks for your inquiry. You are trying to pass com.aspose.pdf.Image object to aspose.pdf.section object. Please note aspose.pdf package is old generator package and com.aspose.pdf is new generator. You can only pass aspose.pdf.PDF object to com.aspose.pdf.Document() obejct, otherwise both packages has their own classes and enumerations. In your above code change com.aspose.pdf.Image with aspose.pdf.Image then it will work as expected.

Furthermore, it is recommend to use new generator(com.aspose.pdf) as it is more improved and efficient. Old generator will be obsolete in near future and in latest release(Aspose.Pdf for Java 11.9.0) we have moved aspose.pdf(old generator) to a separate jar. Please check documentation link of new generator for image to PDF conversion. Hopefully it will help you to accomplish the task.

Please feel free to contract us for any further assistance.

Best Regards,