0

我正在尝试通过使用 PDFBox 应用“文本呈现模式不可见”。我编写了这段代码,但我不知道如何继续,甚至如何调用进程函数以将文本设置在文档中不可见。任何回复表示赞赏。

    public class Test1 extends OperatorProcessor{
    private static final String src="...";
    private static PDFStreamEngine pp;
    private static PDPageContentStream content;
    private static PDType1Font font; 
    public static void CreatePdf(String src) throws IOException, COSVisitorException{
    PDRectangle rec= new PDRectangle(400,400);
    PDDocument document= null;
    document = new PDDocument();
    PDPage page = new PDPage(rec);
    document.addPage(page);
    PDDocumentInformation info=document.getDocumentInformation();
    info.setAuthor("PdfBox");
    info.setCreator("Pdf");
    info.setSubject("Stéganographie");
    info.setTitle("Stéganographie dans les documents PDF");
    info.setKeywords("Stéganographie, pdf");
    content= new PDPageContentStream(document, page);
    pp=new PDFStreamEngine();
    font= PDType1Font.HELVETICA;
    String texte="hello";
    content.beginText();
    content.setFont(font, 12);
    content.moveTextPositionByAmount(15, 385);           
    content.drawString(texte);
    content.endText();
    content.close();
    document.save("doc.pdf");
    document.close();       
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException, COSVisitorException {
        // TODO code application logic here   
        Test1 tes= new Test1();
        tes.CreatePdf(src);
    }
    @Override
    public void process(PDFOperator pdfo, List<COSBase> list) throws IOException {
             COSNumber mode = (COSNumber)list.get(0);
            pp.getGraphicsState().getTextState().setRenderingMode(mode.intValue());
    }
}

最好的问候,李斯特。

4

1 回答 1

1

在浏览http://pdfbox.apache.org/apidocs/上的 PDPageContentStream 文档时,我觉得没有明确的方法(我可能错了,因为我不熟悉这个产品)。

有一个 appendRawCommands 通过,这似乎是一个很好的逃避。我希望你会做这样的事情(未经测试):

content.beginText();
content.setFont(font, 12);
content.moveTextPositionByAmount(15, 385);           
content.appendRawCommands("3 Tr ");
content.drawString(texte);
content.endText();
于 2013-07-22T13:44:44.687 回答