Java iText避免在页面跳转时剪切表格

Java iText避免在页面跳转时剪切表格,java,itext,Java,Itext,我正在使用一个显示许多表格的pdf。当一张表与页面的其余部分不匹配时,单击“下一步”剪切该表并在下一页设置其余部分 我想,如果一个表不适合页面的其余部分,那么将其放在新页面上 我怎样才能做到这一点?有不同的方法可以做到这一点;这有三个选择: 计算表的高度,将其与剩余空间进行比较。在将表添加到文档之前计算表的高度时,高度始终为0,除非使用setTotalWidth()和setLockedWidth()定义表的宽度。您可以使用getVerticalPosition()方法(在PdfWriter中)在

我正在使用一个显示许多表格的pdf。当一张表与页面的其余部分不匹配时,单击“下一步”剪切该表并在下一页设置其余部分

我想,如果一个表不适合页面的其余部分,那么将其放在新页面上


我怎样才能做到这一点?

有不同的方法可以做到这一点;这有三个选择:

  • 计算表的高度,将其与剩余空间进行比较。在将表添加到文档之前计算表的高度时,高度始终为0,除非使用setTotalWidth()和setLockedWidth()定义表的宽度。您可以使用getVerticalPosition()方法(在PdfWriter中)在页面上找到当前Y位置
  • 将表格添加到ColumnText对象,并将ColumnText对象添加到一个矩形中,该矩形定义了模拟模式下页面上剩余的空间。如果ColumnText对象的内容无法完全呈现,请在添加表之前触发一个新页面
  • 如果您从SourceForge上的主干(版本5.3.3-SNAPSHOT)获取最新(尚未发布)版本,则可以使用table.keepRowsTogether(0)避免中断;其中0是表中第一行的索引
  • cb.endText();
    cb.restoreState();
    document.add(Chunk.NEWLINE);
    表.设置总宽度(555.0f);
    int sNo=1;
    float tableHeight1=table.getTotalHeight();
    系统输出打印LN(表高1);
    int rowCount=2;
    int-yAxis=570;
    int newPageYAxis=0;
    
    虽然(我非常感谢布鲁诺,这对我帮助很大:)附言:我刚刚意识到你写了这本iText书,非常荣幸:Dtable.keepRowsTogether非常有用!代码不完整,也没有解释代码的作用。你能改进一下吗?
    public class XX_RPT_D84_AR_Invoice_Printing_GBS extends PdfPageEventHelper{
            public void onEndPage(PdfWriter writer, Document document) {
                Rectangle rect = writer.getBoxSize("art");
                ColumnText.showTextAligned(writer.getDirectContent(),
                        Element.ALIGN_CENTER, new Phrase(String.format("page %d", 1)),
                        (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);
            }
            public static void main(String[] args) {
                try {
                    OutputStream file = new FileOutputStream(new File("D:\\PDF1.pdf"));
                    Document document = new Document();
                    PdfWriter writer = PdfWriter.getInstance(document, file);
                    BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                    BaseColor color = BaseColor.BLACK;
                    PdfContentByte cb = null; 
                    Phrase[] header = new Phrase[3];
                    header [0] = new Phrase("Genpact India");
                    header [1] = new Phrase("(A Private Company with Unlimited Liability)");
                    header [2] = new Phrase("Registered Office: Delhi Information Technology Park, Shastri Park, Delhi-110053, India");                
                    Font font = new Font(BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED),
                             9, Font.NORMAL);
                    boolean isPrinted = false;
    
                       Image image = Image.getInstance ("src/Logo/logo.png");
                       image.scaleAbsolute(120f, 31f);//image width,height   
                       image.setDpi(-10, -5);
                       image.setSpacingBefore(-15);
    
                       Image sign = Image.getInstance ("src/Logo/sign.png");
                       sign.scaleAbsolute(100f, 50f);//image width,height 
                       sign.setIndentationLeft(10);
                       PdfPTable table = new PdfPTable(new float[]{0.8f,5,1.5f,1.3f,2,2});
                       PdfPCell s_No = new PdfPCell(new Phrase("S No", font));
                       s_No.setBorder(Rectangle.BOX);
                       s_No.setPaddingTop(2);
                       PdfPCell description = new PdfPCell(new Phrase("Description", font));
                       description.setBorder(Rectangle.BOX);
                       description.setPaddingTop(2);
                       PdfPCell ratePerUnit = new PdfPCell(new Phrase("Rate Per Unit", font));
                       ratePerUnit.setBorder(Rectangle.BOX);
                       ratePerUnit.setPaddingTop(2);
                       PdfPCell quantity = new PdfPCell(new Phrase("Quantity", font));
                       quantity.setBorder(Rectangle.BOX);
                       quantity.setPaddingTop(2);
                       PdfPCell inrReferenceAmount = new PdfPCell(new Phrase("INR Reference Amount", font));
                       inrReferenceAmount.setBorder(Rectangle.BOX);
                       inrReferenceAmount.setPaddingTop(2);
                       PdfPCell amountINR = new PdfPCell(new Phrase("Amount INR", font));
                       amountINR.setBorder(Rectangle.BOX);
                       amountINR.setPaddingTop(2);
                       table.addCell(s_No);
                       table.addCell(description);
                       table.addCell(ratePerUnit);
                       table.addCell(quantity);
                       table.addCell(inrReferenceAmount);
                       table.addCell(amountINR);
                       int i = 1;
                       String value = "123";
                       PdfPCell cell = null;
                       int referenceAmount = 0;
                       int amount = 0;
                       PdfPCell staticData1 = new PdfPCell(new Phrase("Please remit funds via telex transfer/SWIFT as follows to HSBC BANK Limited (Bank address:"+
                               "JMD Regent Square Ist Floor, DLF Phase II, MG Road, Gurgaon 122002, Haryana, India) with the following"+
                               "Instructions:", font));
                       staticData1.setPaddingTop(20);
                       staticData1.setColspan(6);
                       staticData1.setBorder(Rectangle.NO_BORDER);
                       PdfPCell staticData2 = new PdfPCell(new Phrase("Ultimate Beneficiary: Genpact India", font));
                       staticData2.setColspan(6);
                       staticData2.setBorder(Rectangle.NO_BORDER);
    
                       PdfPCell staticData3 = new PdfPCell(new Phrase("A)For Inward remittances from out side India : Remit by SWIFT MT103 for further credit to Genpact"+
                                "India, Acct no - 054 021365 001 with HSBC India (SWIFT - HSBCINBB) through HSBC Mumbai's account"+
                                "no.000-04417-2, with HSBC Bank, New York, USA having CHIPS code 302755, SWIFT- MRMDUS33 & ABA Routing"+
                                "No. 021-001-088.", font));
                       staticData3.setColspan(6);
                       staticData3.setBorder(Rectangle.NO_BORDER);
    
                       PdfPCell staticData4 = new PdfPCell(new Phrase("B)For remittance from within India: Remit to Genpact India HSBC Account No. 054 021365 001, IFSC Code"+
                                "- HSBC0110005.", font));
                       staticData4.setColspan(6);
                       staticData4.setBorder(Rectangle.NO_BORDER);
    
                       PdfPCell staticData5 = new PdfPCell(new Phrase("You are requested to send the remittances as per the Payment Term mentioned above."+
                                "Please send the payment notification to :collections.helpdesk@genpact.com"+
                                "Incase of any queries contact : genpactbilling.helpdesk@genpact.com", font));
                       staticData5.setColspan(6);
                       staticData5.setBorder(Rectangle.NO_BORDER);
                       PdfPCell staticData6 = new PdfPCell(new Phrase("FOR & ON BEHALF OF", font));
                       staticData6.setPaddingTop(25);
                       staticData6.setColspan(6);
                       staticData6.setBorder(Rectangle.NO_BORDER);
                       PdfPCell staticData7 = new PdfPCell(new Phrase("Genpact India", font));
                       staticData7.setColspan(6);
                       staticData7.setBorder(Rectangle.NO_BORDER);
                       PdfPCell staticData8 = new PdfPCell(new Phrase("(Private Company with Unlimited liability)", font));
                       staticData8.setColspan(6);
                       staticData8.setBorder(Rectangle.NO_BORDER);
                       PdfPCell staticData9 = new PdfPCell(sign);
                       staticData9.setColspan(6);
                       staticData9.setBorder(Rectangle.NO_BORDER);
                       PdfPCell staticData10 = new PdfPCell(new Phrase("Vidut Aggarwal", font));
                       staticData10.setColspan(6);
                       staticData10.setBorder(Rectangle.NO_BORDER);                
                       PdfPCell staticData11 = new PdfPCell(new Phrase("This is a system generated Invoice and does not require physical signature.", font));
                       staticData11.setColspan(6);
                       staticData11.setBorder(Rectangle.NO_BORDER);
    
                             Chunk chunk0 = new Chunk("                               ");
                          Chunk chunk = new Chunk("                                                                                                                            ");
                          chunk.setUnderline(+1f,-2f);//1st co-ordinate is for line width,2nd is space between  
                          document.open();
                          cb = writer.getDirectContent(); 
                          cb.setLineWidth(1);
                          MyPageEventListener mpel = new MyPageEventListener();
                          mpel.onEndPage(writer, document);
                          image.setAbsolutePosition(20, 795);
                          document.add(image);
                          document.add(chunk0);
                          document.add(chunk);
                          document.add(Chunk.NEWLINE);
                          cb.saveState();
                          cb.beginText();
                          cb.moveText(280, 810);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("INVOICE");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(20, 775);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Service Tax No : " + "d_ServiceTaxNo");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(320, 788);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Genpact India");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(316, 775);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("(Private Company with unlimited liability)");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(20, 750);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("PAN : " + "d_PAN");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(318, 760);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("d_AddressLine1");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(20, 725);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Category of services: ");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(318, 746);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("d_AddressLine2");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(318, 732);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("d_AddressLine3");
                          cb.endText();
                          cb.setColorStroke(color);
                          cb.rectangle(20,715,245,-100);
                          cb.stroke();
                          cb.beginText();
                          cb.moveText(25, 700);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("d_cust_name");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(25, 670);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("d_cust_address");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(318, 715);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("d_pin");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(318, 699);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Tele : " + "d_Telephone");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(318, 685);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Fax : " + "d_Fax");
                          cb.endText();
                          cb.setColorStroke(color);
                          cb.rectangle(275,680,300,-80);
                          cb.stroke();
                          cb.setColorStroke(color);
                          cb.rectangle(10,90,575,742);
                          cb.stroke();
                          cb.setColorStroke(color);
                          cb.rectangle(275,680,300,-80);
                          cb.stroke();
                          cb.setColorStroke(color);
                          cb.rectangle(20,610,245,-30);
                          cb.stroke();
                          cb.beginText();
                          cb.moveText(280, 660);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Invoice Number:  " + "d_Invoice_no.");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(280, 645);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Invoice Date:  " + "d_Invoice_date");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(280, 626);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Currency  :   " + "d_Currency");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(280, 605);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Payment Term : " + "d_Payment_term");
                          cb.endText();
                          cb.beginText();
                          cb.moveText(25, 590);
                          cb.setFontAndSize(bf, 10);
                          cb.showText("Attention :  " + "Finance Dept");
    
    cb.endText();
                          cb.restoreState();
                          document.add(Chunk.NEWLINE);
                          table.setTotalWidth(555.0f);
                          int sNo = 1;
                          float tableHeight1  =  table.getTotalHeight();
                          System.out.println(tableHeight1);
                          int rowCount = 2;
                          int yAxis = 570;
                          int newPageYAxis = 0;
                          while (i <= 10){
                              for (int l=1;l<=6;l++){
                                  if(l==1){
                                      cell = new PdfPCell(new Phrase(String.valueOf(sNo), font));
                                      cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT);
                                      cell.setPaddingTop(4); 
                                      sNo++;
                                  }else{
                                      cell = new PdfPCell(new Phrase(value, font));
                                      cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT);
                                      cell.setPaddingTop(4);
                                  }
                                  if(i==10 && l==5){
                                      cell = new PdfPCell(new Phrase(value, font));
                                      cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
                                      cell.setPaddingTop(4);
                                  }
                                  if(i==10 && l==6){
                                      cell = new PdfPCell(new Phrase(value, font));
                                      cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
                                      cell.setPaddingTop(4);
                                  }
                                  if(l==5){
                                      referenceAmount = referenceAmount + Integer.parseInt(value);
                                  }
                                  if(l==5){
                                      amount = amount + Integer.parseInt(value);
                                  }
                                  System.out.println(table.getTotalHeight());
                                  if(table.getTotalHeight()<=450){
                                      table.addCell(cell);
                                      table.writeSelectedRows(0, 6, rowCount, -1, 20, yAxis, cb);
                                      yAxis = yAxis - 15;
                                  }
                                  else {
                                      document.newPage();
                                      table.addCell(cell);
                                      table.writeSelectedRows(0, 6, rowCount, -1, 20, yAxis, cb);
                                      newPageYAxis = newPageYAxis + 15;
                                  }
                              }
                              i++;
                              rowCount++;
                          }
                          System.out.println(rowCount);
                          PdfPCell cell1 = new PdfPCell(new Phrase("", font));
                          cell1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
                          cell1.setPaddingTop(4);
                          PdfPCell cell2 = new PdfPCell(new Phrase("Total", font));
                          cell2.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
                          cell2.setPaddingTop(4);
                          PdfPCell cell3 = new PdfPCell(new Phrase("", font));
                          cell3.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
                          cell3.setPaddingTop(4);
                          PdfPCell cell4 = new PdfPCell(new Phrase("", font));
                          cell4.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
                          cell4.setPaddingTop(4);
                          PdfPCell cell5 = new PdfPCell(new Phrase(String.valueOf(referenceAmount), font));
                          cell5.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
                          cell5.setPaddingTop(4);
                          PdfPCell cell6 = new PdfPCell(new Phrase(String.valueOf(amount), font));
                          cell6.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
                          cell6.setPaddingTop(4);
                          System.out.println(table.getLastCompletedRowIndex());
                          if(table.getTotalHeight()<=450){
                              table.addCell(cell1);
                              table.addCell(cell2);
                              table.addCell(cell3);
                              table.addCell(cell4);
                              table.addCell(cell5);
                              table.addCell(cell6);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb);
                              System.out.println("IF: " + table.getTotalHeight());
                              rowCount++;
                          } else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(cell1);
                              table.addCell(cell2);
                              table.addCell(cell3);
                              table.addCell(cell4);
                              table.addCell(cell5);
                              table.addCell(cell6);
                              table.addCell(staticData1);
                              table.addCell(staticData2);
                              table.addCell(staticData3);
                              table.addCell(staticData4);
                              table.addCell(staticData5);
                              table.addCell(staticData6);
                              table.addCell(staticData7);
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb);
                              System.out.println("ELSE: " + table.getTotalHeight());
                              rowCount++;
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData1);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb); 
                              rowCount++;
                          } else if (isPrinted==false) {
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData1);
                              table.addCell(staticData2);
                              table.addCell(staticData3);
                              table.addCell(staticData4);
                              table.addCell(staticData5);
                              table.addCell(staticData6);
                              table.addCell(staticData7);
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData2);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb);  
                              rowCount++;
                          }else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData2);
                              table.addCell(staticData3);
                              table.addCell(staticData4);
                              table.addCell(staticData5);
                              table.addCell(staticData6);
                              table.addCell(staticData7);
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }  
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData3);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb);  
                              rowCount++;
                          } else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData3);
                              table.addCell(staticData4);
                              table.addCell(staticData5);
                              table.addCell(staticData6);
                              table.addCell(staticData7);
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData4);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb); 
                              rowCount++;
                          } else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData4);
                              table.addCell(staticData5);
                              table.addCell(staticData6);
                              table.addCell(staticData7);
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData5);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb);  
                              rowCount++;
                          } else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData5);
                              table.addCell(staticData6);
                              table.addCell(staticData7);
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData6);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb);  
                              rowCount++;
                          } else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData6);
                              table.addCell(staticData7);
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                               table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb);
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData7);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb);  
                              rowCount++;
                          } else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData7);
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData8);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb);  
                              rowCount++;
                          }
                          else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData8);
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                               table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb);
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              System.out.println("staticData9");
                              table.addCell(staticData9);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb); 
                              rowCount++;
                          } else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData9);
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                               table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              System.out.println("staticData10");
                              table.addCell(staticData10);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb); 
                              rowCount++;
                          }else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              System.out.println("else staticData10");
                              table.addCell(staticData10);
                              table.addCell(staticData11);
                               table.writeSelectedRows(0, 6, rowCount-1, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }
                          if (table.getTotalHeight() <= 450){
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, 0, rowCount, 20, 570, cb); 
                              rowCount++;
                          } else if (isPrinted==false){
                              document.newPage();
                              cb.setColorStroke(color);
                              cb.rectangle(10,90,575,742);
                              cb.stroke();
                              table.addCell(staticData11);
                              table.writeSelectedRows(0, 6, rowCount, -1, 20, (790-newPageYAxis), cb); 
                              isPrinted = true;
                          }
                          System.out.println("Column Index at last " + table.getLastCompletedRowIndex());
                          System.out.println(table.getTotalHeight());           
                             document.close();
                          file.close();
                  System.out.println("Pdf created successfully..");
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
        }