0

アプリケーションのユーザーがボタンをクリックした後に生成した PDF を印刷できるようにする簡単な方法を探しています。ボタンの「onClick」では、何らかの操作を行ってから、このようにメソッドを呼び出します

Map<String,Object> m = new TreeMap<String,Object>();
m.put("paper", paperObject);
Template t = getConfiguration().getTemplate(TEMPLATE_NAME_CONSTANT);
String html = FreeMarkerTemplateUtils.processTemplateIntoString(t,m);
ByteArrayOutputStream os = HtmlToPdfRenderer.print(html);
return os.toByteArray();

元のページを離れたくありません。

ありがとう。

4

1 に答える 1

0

Use a ResourceLink instead of a button. Pass it a custom subclass of ByteArrayResource like this:

new ResourceLink("id", new ByteArrayResource("application/pdf", null, filename) {
    @Override byte[] getData(Attributes att) {
        // generate your PDF here
        return byteArray;
    }
}

Clicking on this link will generate the PDF and send it to the browser.

Alternatively, create a subclass of AbstractResource instead of ByteArrayResource, since AbstractResource is a bit more flexible.

于 2012-10-12T14:52:21.890 に答える