views:

98

answers:

5

I've been asked to write a program which generates reports in the form of PDF files. There are two main dynamic features which have been asked for, which I'm not sure are even possible:

1) The report contains a table with several columns. Users should be able to click on the column header to sort the table rows by the values in that column.

I've never seen a PDF file that users can click on to re-sort table results, but I'm told that this is possible.

2) The report should have a dropdown box which users can select to toggle which rows of the table are displayed or hidden.

I'm fairly sure that this isn't possible to do in a PDF file, though I've been told otherwise.

So my question is, which of these things are even possible, and what library should I use for generating PDF files? (The library can be in any programming language.)

+1  A: 

I would look at Acrobat. There is a JavaScript implementation for it.

http://www.adobe.com/devnet/acrobat/javascript.html

Daniel A. White
Thanks, the other options were good, but the customer is never going to install any PDF reader not from Adobe, so this answer was the most helpful one to me since it showed me where to delve into the docs and see what exactly is and isn't possible.
Eli Courtwright
+1  A: 

Hi Eli,

I've never seen such functionality inside the pdf itself.

Our PDF renderer (fourpdf.com) can cope with dropdowns and the like. If you render a URL with a form in it, (eg this one from Wufoo: http://examples.wufoo.com/forms/employment-application/ ) , the dropdowns and radio buttons are workable inside the form, but I don't think you could link CSS/javascript events to the selections in order to show or hide content.

Another, more complicated approach would be to build a flash object. If you can encapsulate the entire functionality in an object, you can embed the object in the PDF - we've used this for distributing rich media inside a PDF. But it does need to be self-contained, rather than making calls out to external objects for the content.

J.

Jake Liddell
+1  A: 

Don't use PDF as a substitute for html/CSS/JavaScript/etc. PDF is best when it's used as an immutable document format, not as a poor man's web page. Sure, you can put your foot in a box and call it a shoe, but it's really just a box.

Derek Clegg
I totally agree, and in fact there's no good reason why I should be doing this in PDF, but it's a hard requirement from the customer, so I'm just trying to figure out which of the things they've demanded are even possible.
Eli Courtwright
+1  A: 

Hi Eli,

Yes, all of those dynamic features are possible with an XFA PDF form (created in LiveCycle Designer) and scripting ( JavaScript). We have examples of sorting rows in tables and hiding and showing sub-forms at www.pdfscripting.com , but you must be a member to access them (not free). You may be able to find free sample files doing an internet search for XFA PDFs or LiveCycle Designer PDFs- not sure but it is possible at any rate.

Dimitri WindJack Solutions www.windjack.com www.pdfscripting.com

Dimitri
+1  A: 

For Java there are the following tools / libraries that are very good and stable: JasperReports - you design your report in a graphical designer and then populate it with data programatically.

The other is iText. It works on the lower lavel (actualy JasperReports is built on top of it for the PDF part), so it might support the requested sorting options.

Bozho