使用iText将文本添加到pdf的特定页面

我需要创建一个为pdf文件每隔一页添加超链接的工具。


我遵循了iText文档,并设法在第一页上添加了超链接。


我的代码:


public void manipulatePdf(String src, String dest) throws IOException, DocumentException {


        Font bold = new Font(FontFamily.HELVETICA, 30, Font.BOLD);


        PdfReader reader = new PdfReader(src);


        int count = reader.getNumberOfPages();

        Utils.logInfoMessage("Number of pages: " + count, mLogList);

        if(count < 1) {

            Utils.logErrorMessage("file : " + src + " has no pages", mLogList);

            return;

        }


        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));


        PdfContentByte canvas = stamper.getOverContent(1);

        PdfGState gState = new PdfGState();

        gState.setFillOpacity(0.1f);

        canvas.setGState(gState);


        Chunk chunk = new Chunk("www.google.com", bold);

        chunk.setAnchor("https://www.google.ro/");


        Phrase phrase = new Phrase("");

        phrase.add(chunk);


        ColumnText ct = new ColumnText(canvas);

        ct.setSimpleColumn(36, 700, 559, 750);

        ct.addText(phrase);

        ct.go();


        stamper.close();

        reader.close();

    }

有什么想法如何仅在特定页面上添加超链接/文本?


慕妹3242003
浏览 529回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java