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

Free Support Forum - aspose.com

Replace images in PDF - Get Name and raw properties of images using Aspose.PDF for Java


Below is the code im using to replace images in PDF.

PdfContentEditor editor = new PdfContentEditor();


editor.replaceImage(1, 1,"test.JPG");


For this code to work, we need to find the index of the image and page number where it is present. But this indexing doesnot remain consistent with pdfs created from different softwares. Hence the replace image in PDF gets messed up causing a different image to replaced than the actual one.

Is there any other way to find and replace the image inside pdf? Also this function accepts only filename for the image to be replaced. Is there any other interface to pass byte array of image or image object and replace the image?

Thanks in advance.



Hi Pradyumna,

I’m sorry to inform you that both of these features are currently not supported. However, we’re planning to provide support for a feature to get image information i.e. image name, image index and page number. You’ll be able to get a list of this information and then find the index of the image based on the image name. After that, you’ll be able to replace image by index. Will that work in your scenario?

Moreover, please share whether the InputStream as parameter for replaceText will be helpful in answering your second question.

Kindly share your thoughts, so we could move forward accordingly.


We would like to share with you that now you can get Name of the embedded images in a PDF file as well as its raw properties like Type, Filter, Height, Width, etc. using Aspose.PDF for Java.