Java iText PDF内部链接

时间:2015-03-05 15:21:09

标签: java itext

我使用命名目的地创建了内部链接。在Foxit PhantomPDF中查看PDF而不是Adobe Reader XI时,链接按预期工作。为什么呢?

不幸的是,我无法向您展示PDF文件,因为它与防御有关。

我能够通过在gotoLocalPage()方法中将isName参数从true更改为false,使链接在Adobe Reader中按预期工作。

请参阅下面的代码段。

public class MyCellEvent implements PdfPCellEvent {

    private String tableTitle;

    public void setTableTitle( String tableTitle ) {
        this.tableTitle = tableTitle;
    }    // end of method setTableTitle()

    public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
        PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
        boolean isName;
        float llx;
        float lly;
        float urx;
        float ury;
        PdfAction action = null;
        String destination;

        llx = rect.getLeft();
        lly = rect.getBottom();
        urx = rect.getRight();
        ury = rect.getTop();

        tableTitle = tableTitle.replace("_", " ");
        tableTitle = tableTitle.toUpperCase();

        destination =     "[" + LinkCreator.drawingNumber + "]_" + 
                "[COMPONENT]_" +
                "[" + tableTitle + "]_" +
                cell.getPhrase().toString();

        action = new PdfAction();
        isName = true;
        isName = false;
        action = PdfAction.gotoLocalPage(destination, isName);    // key method call
        cb.setAction(action, llx, lly, urx, ury);    // key method call

    }    // end of method cellLayout()

}    // end of class MyCellEvent}

0 个答案:

没有答案