To generate a PDF from an HTML source in Java, you can use the iText HTMLWorker module (it is now deprecated, the new project is XMLWorker, but it depends on the version of iText you are using).
You can emulate the table you use on the JSP page in a String Action variable, say CreatePDFAction ;
Then, from the JSP, call CreatePDFAction with the submit button (if you want to open pdf on a new page).
In Struts.xml, declare the CreatePDFAction result as a stream result type with the corresponding contentType ( application/pdf ), and the desired contentDisposition to specify the file name and behavior: upload it ( attachment ) or open it in a browser ( inline ).
Inside the CreatePDFAction action CreatePDFAction you get a String, create a new document and a new HTMLWorker, feed it with a string containing your HTML, then extract the bytes from the resulting PDF and put it into the InputStream, getter action.
source share