问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/24848053/pdfbox-make-text-invisible