How to merge two pdf documents into a single report in JasperReports?

前端 未结 5 1772
无人共我
无人共我 2020-12-15 00:38

I am new to JasperReports. I can create a simple PDF document with Javabean datasource. In my project I have created two separate pdf document with separate javabean datasou

5条回答
  •  旧巷少年郎
    2020-12-15 01:15

    Multiple Pages in one JasperPrint

    Sample Code:

    DefaultTableModel dtm = new DefaultTableModel(new Object[0][3], new String[]{"Id","Name","Family"});
    String[] fields= new String[3];    
    boolean firstFlag=true;
    JasperPrint jp1 =null;
    JasperPrint jp2 =null;
    for (int i=0 ; i<=pagesCount ; i++)
    {
       fields[0]= "id";
       fields[1]= "name";
       fields[2]= "family";
       dtm.insertRow(0, fields); 
       try
       {
          Map params = new HashMap();                
          if (firstFlag)
          {
             jp1 = JasperFillManager.fillReport(getClass().getResourceAsStream(reportsource), params, new JRTableModelDataSource(dtm));                
             firstFlag=false;                            
          }else
          {
             jp2 = JasperFillManager.fillReport(getClass().getResourceAsStream(reportsource), params, new JRTableModelDataSource(dtm));
             jp1.addPage(jp2.getPages().get(0));
          }     
       }catch (Exception e) 
       {
          System.out.println(e.fillInStackTrace().getMessage());
       }
    }
    JasperViewer.viewReport(jp1,false);
    

提交回复
热议问题