开发者

Create PDF in Struts from data on screen

I am able to create a simple pdf using iText api inside a struts action class.

The data that should be passed into the pdf is generated on screen based on user search p开发者_如何转开发arameters.

What I am wondering is how I can pass the data into the struts action so it can be displayed in the pdf?

Thanks in advance.


Similar question is already here. You just need to transfer everything that is on the page to struts action. I would do it like so:

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
}

This will set all the HTML to a action class property hiddenHtml. Get back if anything won't work, I wrote this out of my head without a test :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜