Reputation: 8586
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
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.
Upvotes: 4