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 に答える