Page Content not Erasing with Rectangle fill in pdfbox

Viewed 37

I am working on a requirement that , I need to mask the certain content based on Keys. With the PDF Rectangle fill i am able to mask well. But the user still able to get the content from masked region by selecting the text. How can i get rid of it.

 PDDocument document = new PDDocument();
      for (int i=0; i<1; i++) {
         PDPage blankPage = new PDPage();
         document.addPage( blankPage );
         PDPageContentStream contentStream = new PDPageContentStream(document, document.getPage(0));
         contentStream.beginText(); 
         contentStream.setFont(PDType1Font.TIMES_ROMAN, 12);
         contentStream.newLineAtOffset(25, 500);
         String text = "This is the sample document and we are adding content to it.";
         contentStream.showText(text);
         contentStream.endText();
         contentStream.setNonStrokingColor(Color.RED);
         contentStream.addRect(25, 500, 100, 100);
         contentStream.fill();
         contentStream.close();
      } 
      document.save("C:/PdfBox_Examples/my_doc.pdf");
      System.out.println("PDF created");
      document.close();
0 Answers
Related