求一份Java 动态生成 pdf文件的示例,与数据库结合的就更好,如果核心代码能多点注释就.....最好
至于需要的两个组件包我自己有,谢谢各位友人帮忙了... 另外问下哪位达人有spring的中文pdf,不胜感激.

解决方案 »

  1.   

    http://download.csdn.net/source/989301Java生成PDF完整示例,并解决中文乱码问题,不要资源分!快去下呀!
      

  2.   

    哪位有的话,请发送至[email protected]我的邮箱,期待....
      

  3.   

    推荐用ECSIDE,自动生成XSL,WORK,PDF等,可以映射数据库
      

  4.   

    //课程管理PDF
    public ActionForward courcemanagePDF(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) { Document document = new Document();
    document.setPageSize(PageSize.A4);

    try {
    ByteArrayOutputStream ops = new ByteArrayOutputStream();

    PdfWriter.getInstance(document,ops);
    document.open();
    BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

    Font headFont1 = new Font(bfChinese, 14, Font.BOLD);
    Font headFont2 = new Font(bfChinese, 12, Font.BOLD);
    Font headFont3 = new Font(bfChinese, 10, Font.NORMAL);

    float[] widths = {200,200f,300f};
    PdfPTable table = new PdfPTable(widths);

    table.setSpacingBefore(130f);
    table.setTotalWidth(535);
    table.setLockedWidth(true);
    table.getDefaultCell().setBorder(0);

    PdfPCell cell = new PdfPCell(new Paragraph("BEST人力资源公司",headFont1));
    cell.setBorder(0);
    cell.setColspan(3);
    table.addCell(cell);

    //PDF标题
    cell = new PdfPCell(new Paragraph("课程管理", headFont1));
    // cell.setBorder(0);
    cell.setFixedHeight(40);
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    //列标题
    String cloumTitle[]=new String[]{"课程名称","使用教材","描述"};
    int i=0,n=cloumTitle.length;
    while(i<n){
    cell = new PdfPCell(new Paragraph(cloumTitle[i], headFont2));
    cell.setFixedHeight(20);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    i++;
    }
            
    //报表数据
    CourcemanageDAO courcedao=new CourcemanageDAO();
    List ctli=courcedao.findAll();//课程管理所有信息
    if(ctli.size()>0)
    for(int k=0;k<ctli.size();k++){
    Courcemanage ctf=(Courcemanage)ctli.get(k);
    //列数据
    cell = new PdfPCell(new Paragraph(ctf.getCourcename(),headFont2));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph(ctf.getBookname(),headFont2));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph(ctf.getTmemo(),headFont2));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    }

        String tempNOWtime=new Date().toLocaleString();
        tempNOWtime=tempNOWtime.split(" ")[0];
        
    cell = new PdfPCell(new Paragraph(tempNOWtime,headFont3));
    cell.setFixedHeight(30);
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell); document.add(table);
    document.close();

    response.setContentType("application/pdf");
    response.setContentLength(ops.size());
    ServletOutputStream out = response.getOutputStream();
    ops.writeTo(out);
    out.flush();

    } catch (DocumentException de) {
    System.err.println(de.getMessage());
    } catch (IOException ioe) {
    System.err.println(ioe.getMessage());
    }

    return null;
    }详细查看:http://hi.baidu.com/cqdyblog/blog/item/a966aadf1c61195395ee374a.html