How to add a header that is always at the bottom layer?

I have a set of documents that I need to add a header into, the header is going to be a band whose background is white and inside of it it has content (left, center and/or right). Not matter the zindex I set to it, I can never get it to be the first text found when I open the PDF (Ctrl + F).

Below a sample code:

var doc = new Document("empty2.pdf");
var page = doc.getPages().get_Item(0);
var table = new Table();
var row = table.addRow();
var cell = row.getCells().add("test");
page.getParagraphs().insert(0, table);
doc.save("test.pdf");

I’ve tried to set zindex to the table, cell and textFragment that goes into the cell, nothing seems to work. Are there any other options?empty2.pdf (9.9 KB)

IMPORTANT: Even if the page background color is black, I need the band to be white. That’s the reason why TextStamp.setBackground(true) doesn’t work.

@samuelmartinucci

Would you please also share an expected output PDF as well so that we can try to understand better your requirement and share our feedback with you accordingly?

@asad.ali, it should look like the one attached, everything should be on the same layer (or header being the bottom-most) and being searchable in the order they appear.empty4.pdf (29.4 KB)

@samuelmartinucci

Have you tried using the FloatingBox? You can set background of floating box and place it anywhere on the page (in your case at the top of the page) and add content inside it e.g. stamps, paragraphs, text, table. For example, you can check below code example:

@asad.ali yes, I tried. The problem seems to be that the content that is part of the document being decorated is in a layer that is unreachable, anything that I add to the document is a layer above it (even if I set the Zindex to Integer.MIN_VALUE).

Some of the things that I tried:

  1. Crop the top margin of the document and then prepend to the page a header (no lucky prepending content to a page though, I’ve read all the Javadocs and the closest I could get was PDFEditor classes, which doesn’t seem to allow such operation).
  2. Floating box and/or table with zIndex negative.
  3. Apply margin to the document in order to eliminate the content into the section, so that I could stamp afterwards.
  4. Rebuild the document in memory using Absorbers. This is sounded super risky, so I didn’t insist too much.

Long story short, the main question is, how do I manipulate the layer containing the data that is currently part of the document? As long as this is possible, it should be a matter of setting the zindex, right?

@samuelmartinucci

We are checking it and will get back to you shortly.

@samuelmartinucci

We used your file i.e. example4.pdf to test the scenario and tried to add text in it using floating box. We observed that nothing was appeared on the output PDF. Therefore, we would like to have confirmation about two issues that we noticed:

1- Any text being added to the PDF is not appearing at the top-most layer
2- If it appears somehow, you want it to be selected first while searching in the Adobe Reader

Please confirm as we will be logging these issues in our issue management system for the sake of further investigation and rectification.

Your statement is partially correct. I want that the text being added before the actual content (i.e.: a header) appears as the first search result, while if it’s the footer, I want it to be the last element.

Long story short, I want to be able to manipulate the content layer and add content (or at least be able to add a floating box a layer below the content, since as of now, the only thing that goes behind the content is the stamp with background set to true).

@samuelmartinucci

A task as PDFJAVA-41969 has been logged in our issue tracking system to further investigate this scenario. We will look into its details and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.