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

Free Support Forum - aspose.com

PDF - ImagePlacementAbsorber order not same as getResources().getImages()

Hi,

Does ImagePlacementAbsorber has images in same order as that of page.getResources().getImages() ?

We are using below code to delete image from a rectangle, but it looks sometimes the image indexes (ps and ps2) differ.

Images not getting correctly delete based on index from ImagePlacementAbsorber. Also the image objects differes in both collections.

Can you please let us know how can we get the Rectangle of XImage using getImages() ?

or to delete image using ImagePlacementAbsorber? ip.getImage().delete(); --this is not working.


Code Using ImagePlacementAbsorber :

ImagePlacementAbsorber ipa = new ImagePlacementAbsorber();
pdfDoc.getPages().accept(ipa);
ImagePlacementCollection ipc = ipa.getImagePlacements();
int ips = ipc.size();
LOGGER.info(“ips count:”+ ips);
HashMap<Integer,XImage> imgMap = new ArrayList<Integer,XImage>();

int imgInd=0;
int prevPageInd=0;
int thisPageInd=0;
int imgInPageInd=0;

for(int ps=1;ps<=ips;ps++)
{
ImagePlacement ip = ipc.get_Item(ps);
Rectangle r = ip.getRectangle();
XImage img= ip.getImage();
String name = img.getName();
imgMap.put(ps,ip.getImage());
thisPageInd = ip.getPage().getNumber() ;
if( thisPageInd != prevPageInd )
{
imgInPageInd=0;
}
imgInPageInd= imgInPageInd+1;
if(deleteThisImage)
{
imgInd = imgInPageInd;
}
}

Code Using getImages() :
int ps2=0;
HashMap<Integer,XImage> imgMap2 = new ArrayList<Integer,XImage>();
for (int p = 1; p <= numPages; p++)
{

ArrayList imgIndxs = new ArrayList();
int noOfImages = pdfDoc.getPages().get_Item§.getResources().getImages().size();
String [] str = pdfDoc.getPages().get_Item§.getResources().getImages().getNames();

for (int k = 1; k <= noOfImages; k++)
{
XImage img2 = pdfDoc.getPages().get_Item§.getResources().getImages().get_Item(k);
String name2 = img.getName();
imgMap2.put(ps2,ip.getImage());
ps2++;
}
}

Delete image:
pdfDoc.getPages().get_Item(1).getResources().getImages().delete(imgInd); //say delete one image from page 1.

Thanks.
-Sonali

Hi Sonali,


Thanks for contacting support.

We are working over this query and will get back to you soon.
sonaliag1:
or to delete image using ImagePlacementAbsorber? ip.getImage().delete(); --this is not working.
Hi Sonali,

I have tested the scenario using Aspose.Pdf for Java 4.5.1 and I am able to notice the same problem that images are not getting removed using ImagePlacement.getImage().delete();. For the sake of correction, I have logged this problem as PDFNEWJAVA-34041 in our issue tracking system.

sonaliag1:
Does ImagePlacementAbsorber has images in same order as that of page.getResources().getImages() ?

We are using below code to delete image from a rectangle, but it looks sometimes the image indexes (ps and ps2) differ.

Images not getting correctly delete based on index from ImagePlacementAbsorber. Also the image objects differes in both collections.
Can you please share some details which can help us in understanding the above requirement/issue. We are sorry for your inconvenience.

The issues you have found earlier (filed as PDFNEWJAVA-34041) have been fixed in Aspose.Pdf for Java 11.4.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.