Why not just use DownloadLink
with a Model
that will generate the file?
IModel fileModel = new LoadableDetachableModel (){
protected Object load() {
// A hello world PDF
File f = File.createTempFile("tempFile", null);
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(f));
document.open();
document.add(new Paragraph("Hello World!"));
document.close();
return f;
}
};
DownloadLink link = new DownloadLink(linkId, fileModel, "report.pdf");
// If you want to delete the file after it's been downloaded
link.setDeleteFileAfterDownload(true);
add(link);
Also take a look at:
- How to use Wicket’s DownloadLink with a file generated on the fly?
- Download a zip file through wicket
3
solved creating pdf file for download in java web [closed]