-5

I have a list and I want to create a pdf report. User can ask to generate and download the pdf report by clicking a button. I use wicket framework. What should I do?

abozar
  • 175
  • 6
  • 14
  • 4
    Show us your code .What have you tried? This is not a University class where you are asking teacher a question. – Makky Jul 09 '13 at 15:00
  • 1
    Well, you should start by finding and using a library of some kind to build PDF files. iText is a pretty good one, for example. Then you create a button in your interface which executes that functionality and returns the generated file to the user. That's pretty much all. – David Jul 09 '13 at 15:05
  • Look at this: http://api.itextpdf.com/itext/com/itextpdf/text/package-summary.html – TroyAndAbed Jul 09 '13 at 15:05
  • You could start taking a look [here](http://stackoverflow.com/q/7646270/851811) and [here](http://stackoverflow.com/q/7851913/851811) for the Wicket part. For the PDF generation part, take a look at pdf generation libraries such as [iText](http://itextpdf.com/). – Xavi López Jul 09 '13 at 15:08

1 Answers1

0

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:

Community
  • 1
  • 1
Xavi López
  • 27,550
  • 11
  • 97
  • 161