Dimuthu
Dimuthu

Reputation: 8586

PDFBox make text invisible

I'm writing some text to an existing PDF file using

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

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?

Upvotes: 1

Views: 1776

Answers (1)

JamesB
JamesB

Reputation: 7894

After the call to beginText, insert this line

contentStream.appendRawCommands("3 Tr ");

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

Upvotes: 4

Related Questions