pdfbox 中的矩形填充无法擦除页面内容

发布于 2025-01-16 03:13:53 字数 974 浏览 1 评论 0原文

我正在处理一个要求,我需要根据键屏蔽某些内容。通过 PDF 矩形填充,我能够很好地进行遮罩。但用户仍然可以通过选择文本来从屏蔽区域获取内容。我怎样才能摆脱它。

 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();

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文