Arrangement of PDF page stamps

Hello,

There is a case when we are replacing an image in PDF with an EPS image by using PDF stamps. And PDF stamps are always applied on top of the content:

Before:
image.jpg (118.9 KB)

After:
image.jpg (112.7 KB)

Here is the code example:

    Document document = new Document(new FileInputStream("before stamp.pdf"));

    Page page = document.getPages().get_Item(1);

    ImagePlacementAbsorber pageImages = new ImagePlacementAbsorber();
    page.accept(pageImages);

    ImagePlacement imagePlacement = pageImages.getImagePlacements().get_Item(1);

    PsDocument vectorDocument = new PsDocument(new FileInputStream("tiger.eps"));
    ByteArrayOutputStream vectorOutputStream = new ByteArrayOutputStream();
    vectorDocument.save(new PdfDevice(vectorOutputStream), new PdfSaveOptions());

    ByteArrayInputStream vectorInputStream = new 
    ByteArrayInputStream(vectorOutputStream.toByteArray());
    PdfPageStamp stamp = new PdfPageStamp(vectorInputStream, 1);
    Rectangle imageRectangle = imagePlacement.getRectangle();
    stamp.setHeight(imageRectangle.getHeight());
    stamp.setWidth(imageRectangle.getWidth());

    stamp.setXIndent(imageRectangle.getLLX());
    stamp.setYIndent(imageRectangle.getLLY());

    imagePlacement.getPage().addStamp(stamp);
    imagePlacement.getImage().delete();

    FileOutputStream pdfOutputStream = new FileOutputStream("after stamp.pdf");
    document.save(pdfOutputStream);

The question is - is there any possibility to apply a PDF page stamp in a way that it would be applied in a place of existing image placement - not on top of existing content, but behind another image, as in the “before” example? It would be great to replace an image with EPS without changing the image order.

Here are document examples:
eps in pdf.zip (3.9 MB)

@ANDREA.FARRIS

We need to further investigate the feasibility of your requirements. Therefore, we have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-43724

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.