Get Page images

Hello,

I am trying to get the current page images. But it seems that the image list in the resources of the current page holds the images of the whole document and not of the current page.
In the following code, for the attached document, any page will have the same images even one that does not contain any image.
Page page = pdf.getPages().get_Item(pageNb);
for (int i = 1 ; i <= page.getResources().getImages().size() ; i += 1 ) {
FileOutputStream os = new FileOutputStream("/tmp/PDFTests/im" + i + “.jpg”);
XImage img = page.getResources().getImages().get_Item(i);
img.save(os);
}
thanks,

Camille.

Hi Camille,

Thanks for your inquiry. I have tested your scenario with your shared document using Aspose.Pdf for Java 10.1.0 and managed to observe the reported issue. For further investigation, I have logged an issue in our issue tracking system as PDFNEWJAVA-34767 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

Please feel free to contact us for any further assistance.

Best Regards

Hi Camille,


Thanks for your patience. We have further investigated the issue and found it is not a bug, because all the resources are connected. You may use one of the following two solutions, it will help you to accomplish the task.

Option 1:

Document doc = new Document(myDir+“100PagesWithTOC.pdf”);<o:p></o:p>

Page page = doc.getPages().get_Item(50);

ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

page.accept(abs);

int count = abs.getImagePlacements().size();

System.out.println("Images count = "+count);

for (int i = 1 ; i <= count ; i++ )

{

abs.getImagePlacements().get_Item(i).getImage().save(new FileOutputStream(myDir+"Image" + i + ".jpg"));

}


Option 2:

// Open document

Document doc = new Document(myDir+"100PagesWithTOC.pdf");

Page page = doc.getPages().get_Item(50);

//Separate page from the document

Document doc2 = new Document();

doc2.getPages().add(page);

doc2.optimizeResources();

page = doc2.getPages().get_Item(1);

for (int i = 1 ; i <= page.getResources().getImages().size() ; i += 1 ) {

FileOutputStream os = new FileOutputStream(myDir+"Image" + i + ".jpg");

XImage img = page.getResources().getImages().get_Item(i);

img.save(os);

}


Please feel free to contact us for any further assistance.


Best Regards,