To generate a PDF
from an HTML
source in Java, you can use iText's HTMLWorker module (now deprecated, the new project is XMLWorker, but this depends on the iText version you're using).
You can emulate the table you have on JSP page in an String variable of an Action, let's say CreatePDFAction
;
Then, from the JSP, call CreatePDFAction
with a submit button (opening the pdf on a new page, if you want).
In Struts.xml, declare CreatePDFAction
result as stream result type, with the appropriate contentType
(application/pdf
), and the desired contentDisposition
for specifying the filename, and the behavior: download it (attachment
) or open it in browser (inline
).
Inside the CreatePDFAction
action, you receive the String, instantiate a new document and a new HTMLWorker, feed it with the string containing your HTML, then extract the bytes from the resulting PDF and put it in an InputStream exposed through a getter by the action.