PDFBox 使文本不可见 [英] PDFBox make text invisible

查看:63
本文介绍了PDFBox 使文本不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

        PDPage page = document.getPage(pgNo);
        PDFont font = PDType1Font.TIMES_ROMAN;
        PDPageContentStream contentStream = new PDPageContentStream(document, page, true, false);
        contentStream.beginText();
        contentStream.drawString("Helo World");
        contentStream.endText();
        contentStream.close();
        document.save(new File(target));
        document.close();

然后在文档中打印Hello World"这个词.但我需要让它不可见.如何更改上面的代码示例以使其不可见?

Then word "Hello World" is printed in the document. But I need to make it invisible. How can I change above code sample to make it invisible?

推荐答案

在调用 beginText 后插入这一行

After the call to beginText, insert this line

contentStream.appendRawCommands("3 Tr ");

这实际上将文本渲染模式设置为 RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT,这将使文本不可见.

This essentially sets the text rendering mode to RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT which will render the text invisible.

http://pdfbox.apache.org/docs/1.8.6/javadocs/org/apache/pdfbox/pdmodel/text/PDTextState.html#RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT

这篇关于PDFBox 使文本不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆