【问题标题】:Create PDF in Struts from data on screen从屏幕上的数据在 Struts 中创建 PDF
【发布时间】:2009-12-01 20:13:09
【问题描述】:

我能够在 struts 动作类中使用 iText api 创建一个简单的 pdf。
应该传递到 pdf 中的数据是根据用户搜索参数在屏幕上生成的。
我想知道的是如何将数据传递到 struts 动作中,以便它可以显示在 pdf 中?

提前致谢。

【问题讨论】:

    标签: struts


    【解决方案1】:

    Similar question 已经在这里了。您只需要将页面上的所有内容转移到 struts 操作。我会这样做:

    JSP:

    <div id="content">
      wrap everything generated in here
    </div>
    <html:hidden styleId="hiddenHtml" name="hiddenHtml"/>
    <html:submit onclick="setContentAsParam();">Export PDF</html:submit>
    

    JS:

    function setContentAsParam() {
        document.getElementById('hiddenHtml').value = document.getElementById('content').innerHTML
    }
    

    这会将所有 HTML 设置为动作类属性 hiddenHtml。如果任何事情都不起作用,请回来,我没有测试就写了这个:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2014-04-11
      • 2012-09-25
      相关资源
      最近更新 更多