【问题标题】:How to export a jasper report in pdf generating tool tip's on anchor's?如何在锚点上的 pdf 生成工具提示中导出碧玉报告?
【发布时间】:2016-01-04 11:30:23
【问题描述】:

在 jasper 报告中,我使用 anchor'shyperlinkTooltipExpression

示例代码:

 <textField hyperlinkType="LocalAnchor">
            <reportElement x="267" y="94" width="100" height="30" uuid="8fa9ce3d-015c-4d13-a677-3b9dbea4c222"/>
            <textFieldExpression><![CDATA["Anchor Target"]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA["expert"]]></hyperlinkAnchorExpression>
            <hyperlinkTooltipExpression><![CDATA["expert"]]></hyperlinkTooltipExpression>
        </textField>

这在 IDE 预览中有效,但如果导出为 PDF,工具提示不会显示在 Adob​​e Reader 中,在文档查看器 (linux) 中会显示但带有 es。 “转到第 x 页”

【问题讨论】:

  • 文档查看器是另一个在 Linux 环境中用于查看 PDF 文件的应用程序。
  • 文档查看器是否显示 textFieldExpression 或 hyperlinkAnchorExpression? (不能显示超链接TooltipExpression)
  • 在文档查看器中显示“转到第 x 页”。
  • 答案解决了你的问题吗?

标签: java pdf jasper-reports itext


【解决方案1】:

在 jasper 报告中,我找不到任何支持在超链接上生成工具提示,JasperReport source code

但是,您可以覆盖JRPdfExporter 上的setHyperlinkInfo,手动生成注释。

关于如何在LocalAnchor 上生成工具提示的示例:

JRPdfExporter exporter = new JRPdfExporter() {
    @Override
    protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link) {
        if (link!=null && link.getHyperlinkTooltip() != null && HyperlinkTypeEnum.LOCAL_ANCHOR.equals(link.getHyperlinkTypeValue())) {
            PdfFormField pushButton = PdfFormField.createPushButton(pdfWriter);
            pushButton.setFieldName(String.format("tt%s", chunk.hashCode()));//Need's unique name if multiple
            Rectangle rect = new Rectangle(0, 0, 0, 0);
            pushButton.setWidget(rect, PdfAnnotation.HIGHLIGHT_NONE);
            pushButton.put(PdfName.TU, new PdfString(link.getHyperlinkTooltip(), PdfObject.TEXT_UNICODE));
            chunk.setAnnotation(pushButton);
            if (link.getHyperlinkAnchor() != null){                         
               pushButton.setAction(PdfAction.gotoLocalPage(link.getHyperlinkAnchor(), false));
            }
            return;         
        }
        super.setHyperlinkInfo(chunk, link);
    }
};

要在其他类型的hyperlinkType(参考、远程 ecc)上生成工具提示,请继续执行类似的操作。

【讨论】:

  • 抱歉回复晚了。是的,此代码在 PDF 上生成工具提示。但我也有一些问题,工具提示可以正常工作,但现在超链接是在图表之外创建的。我试图改变 Rectangle 上 Rectangle 的参数 rect = new Rectangle(0, 0, 0, 0);但它不会反映在图表上。
  • 我认为最好的方法是使用 iText 代码和图形图像、所需结果的图像创建一个新问题..,我只在文本字符串上测试了代码(矩形表示它从相对于块的注释中的 0,0,0,0 开始...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多