tags:

views:

44

answers:

3

I want to create a pdf according to Incoming Value From Mysql DB using Struts.Could Anyone help me by point any tool or how to process?

A: 

You can use iText - a mature open source library for creating PDF documents. The following example is Struts 1 based, but may help you:

public class PDF extends Action {
    public ActionForward perform(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    try {

        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();
        document.add(new Paragraph("Hello World"));
        //
        // add your data here ...
        //
        document.close();

        response.setContentType("application/pdf");
        response.setContentLength(baos.size());
        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();
    } catch (Exception e2) {
        System.out.println("Error in " + getClass().getName() + "\n" + e2);
    }
    return null;
    }
}
David Rabinowitz
A: 

In addition to iText, you can use JasperResports - it is built ontop of iText, but provides a GUI designer for your report (which can be then exported to pdf, excel, printer, etc.).

But either way you will have to read and learn a lot ;)

Bozho
Hi,Thanks for your reply.Could you tell me that "Is it possible to create pdf with complex UI using jasperrepots"?
Palani
it is possible to create rather complex PDFs with JasperReports. But UI isn't an appropriate word for read-only document :)
Bozho
A: 

Docmosis will let you create the basis of your document in Doc or ODT format as a template. You can then use your mysql data to control what you want to do to the template (insert data, remove data, pick a different template etc) before you render the PDF. I'm not sure what your "pdf with complex UI" means. Docmosis lets you template fairly sophistocated documents (thanks to OpenOffice), but Jasper lets you code pretty much any output result you could need.

jowierun