In my PdfLink.java I do the follow:
public class PdfLink extends Link {
private static final long serialVersionUID = 1L;
public PdfLink(String id) {
super(id);
}
public void onClick() {
try {
IResourceStream resourceStream = new ByteArrayResourceStream(
((ByteArrayOutputStream) generatePdf()).toByteArray(),
"application/pdf");
getRequestCycle().setRequestTarget(new
ResourceStreamRequestTarget(resourceStream) {
@Override
public String getFileName() {
return ("export.pdf");
}
});
} catch (Exception ex) {
error("Error while creating the PDF file!");
ex.printStackTrace();
}
}
private OutputStream generatePdf() throws DocumentException,
IOException {
Document document = new Document(PageSize.A4);
final OutputStream os = new ByteArrayOutputStream();
PdfWriter pdfWriter = PdfWriter.getInstance(document, os);
document.open();
document.add(new Paragraph("some sample text"));
document.add(Image.getInstance(new URL("some.URL.to.pic")));
document.close();
return os;
}
}
I'm using iText for generating Pdf, this is only a PoC code, Later I
will add a business object to the class, so I can provide custom datas
for the pdf generating part. You can also see, that this code will
generate the pdf on-demand.
Thanks for the link anyway, I'm looking into it.
Regards,
Peter
2009-08-08 12:58 keltezéssel, Martin Makundi írta:
Hi!
Maybe this might help:
http://cwiki.apache.org/WICKET/showing-a-remote-image-on-wicket-site.html
? It's about fetching a remote image.. I did not quite figure out how
you provide your pdf, as stream or otherwise.
**
Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]