0

I'm drawing black boxes in a pdf and it draws them perfectly but when I generate the pdf, and I open it with Acrobat Pro the boxes can be modified. How can I make the box layer merge with the pdf?

PDPage page = document.getPage(i-1);
PDPageContentStream contentStream = new PDPageContentStream(document,page, true, true, true);
contentStream.setStrokingColor(Color.BLACK);
contentStream.addRect(dto.getLeft(), dto.getTop() - factY, dto.getWidth(), dto.getHeight());
contentStream.fill();
contentStream.close();
.
.
.
document.save(os);
document.close();
PereZix
  • 41
  • 4
  • 1
    I don't have Acrobat Pro, but from your text I assume that this software can modify PDFs. The solution would rather be to set permissions to prevent changes. (empty user password, non empty owner password). Btw if you are making a redaction tool - it doesn't work that way. The original content is still there. – Tilman Hausherr Aug 17 '20 at 13:06
  • Your code doesn't create "layers", it's just another content stream. One could concatenate it with the existing ones, but I doubt that this would change anything. – Tilman Hausherr Aug 17 '20 at 13:37
  • And how i can flatten these rectangles in the final pdf? – PereZix Aug 17 '20 at 14:15
  • You can't. There is "flattening" in PDF but this means that acroform fields are turned into ordinary content. Another thing would be converting to image and then creating a new PDF with these images. But this has drawbacks, e.g. loss of quality and loss of text. – Tilman Hausherr Aug 17 '20 at 14:32
  • 1
    The only way to do this that can't be circumvented easily is to remove the redacted text and substitute it with your black rectangles. You could also - as stated by Tilman - add your rectangles and then convert the whole page to an image, but that's going to destroy legibility (and search ability) of all text. – David van Driessche Aug 17 '20 at 19:01
  • 2
    By the way, why do you set stroke color to black and then use "fill"? That doesn't make much sense does it? – David van Driessche Aug 17 '20 at 19:02

0 Answers0