如果循环次数太多不能显示.
如果内容太多也不能显示.

解决方案 »

  1.   

    我现在是用iText来产生报表.
    但是利用循环产生表的行时如果循环次数多的话输出的pdf文档就没有内容.
    如果只是做一二十次循环就没有问题. 
    还有个问题是这样的:如果一行的文字很多的话也是这样.
      

  2.   

    你是直接通过JSP页面生成还是通过Servlet生成,建议采用后者方法
      

  3.   

    我是通过servlet生成。
    而且在这种情况下它会自动换页。
    PdfPTable t1 = new PdfPTable(1);
    t1.addCell("title");
    PdfPTable t2 = new PdfPTable(2);
    t2.addCell("a");
    t2.addCell("b");
    t1.addCell(t2);
    document.add(t1);
    这时title会在第一页,而t2会在第二页。
      

  4.   

    不会吧
    private static void parseBody(Element root, Document document) {
    NodeList body = root.getElementsByTagName("body");
    System.out.print("----------BODY----------");
    for (int z = 0; z < body.getLength(); z++) {
    Element bodyNode = (Element) body.item(z);
    Node bodyChildNode = bodyNode.getFirstChild();
    // String bodyString = "";
    while (bodyChildNode != null) {
    String bodyChildName = bodyChildNode.getNodeName();

    if ("BLOCK".equals(bodyChildName)) {
    ArrayList blockValList = new ArrayList();
    Node blockChildNode = bodyChildNode.getFirstChild();
    //NodeList blockChildNode = bodyNode.getChildNodes();
    String blockString = "";
    while (blockChildNode != null) {
    String blockChildName = blockChildNode.getNodeName();
    System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"+blockChildName);
    if("#text".equals(blockChildName)){
    System.out.println(blockChildNode.getNodeValue());
    blockString += blockChildNode.getNodeValue();
    }
    else if ("BR".equals(blockChildName)) {
    blockString += "\n";
    }  else if ("VAR".equals(blockChildName)) {
    if (blockChildNode.getFirstChild() != null) {
    System.out.println(blockChildNode.getFirstChild().getNodeValue());
    blockString += blockChildNode.getFirstChild().getNodeValue();
    }
    }
    else if ("I".equals(blockChildName)){
    if(blockChildNode.getFirstChild() != null){
    System.out.println(blockChildNode.getFirstChild().getNodeValue());
    blockString += blockChildNode.getFirstChild().getNodeName();
    }
    }
    blockChildNode = blockChildNode.getNextSibling();
    }

    blockValList.add(blockString);
    // iText画PDF
    try {
    BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
    Font fontText = new Font(bfChinese, 8, Font.NORMAL);
    Table iTextTable = new Table(blockValList.size());
    iTextTable
    .setDefaultVerticalAlignment(Element.ATTRIBUTE_NODE);
    iTextTable.setBorder(Rectangle.NO_BORDER);
    iTextTable.setWidth(100);
    iTextTable.setAutoFillEmptyCells(false);
    iTextTable.setDefaultColspan(1);
    Iterator it = blockValList.iterator();
    while (it.hasNext()) {
    iTextTable.addCell(new Phrase ((String) it.next(),fontText)); }
    document.add(iTextTable);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    else if ("TABLE".equals(bodyChildName)) {
    Node tableChildNode = bodyChildNode.getFirstChild();
    ArrayList tableValList = new ArrayList();
    while(tableChildNode != null){
    String tableChildName = tableChildNode.getNodeName();
    System.out.println("########################################"+tableChildName);
    if("CELL".equals(tableChildName)){
    Node cellChildNode = tableChildNode.getFirstChild();
    String cellString = "";
    while(cellChildNode != null){
    String cellChildName = cellChildNode.getNodeName();
    if ("BR".equals(cellChildName)) {
    cellString += "\n";

    else if("B".equals(cellChildName)) {
    Node bChildNode = cellChildNode.getFirstChild();
    while(bChildNode != null){
    String bChildNane =  bChildNode.getNodeName();
    if("VAR".equals(bChildNane)){
    if(bChildNode.getFirstChild() != null){
    System.out.println(bChildNode.getFirstChild().getNodeValue());
    cellString += bChildNode.getFirstChild().getNodeValue();
    }
    }
    bChildNode = bChildNode.getNextSibling();
    }
    }
    else if ("VAR".equals(cellChildName)) {
    if (cellChildNode.getFirstChild() != null) {
    System.out.println(cellChildNode.getFirstChild().getNodeValue());
    cellString += cellChildNode.getFirstChild().getNodeValue();
    }
    }
    cellChildNode = cellChildNode.getNextSibling();
    }
    tableValList.add(cellString); }
    tableChildNode = tableChildNode.getNextSibling();
    }
    //iText画PDF
    try{
    BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
    if (tableValList.size() > 0 ){
    Table iTextTable = new Table(tableValList.size());
    iTextTable.setDefaultVerticalAlignment(Element.ENTITY_NODE);
    iTextTable.setBorder(Rectangle.NO_BORDER);
    iTextTable.setWidth(100);
    iTextTable.setAutoFillEmptyCells(false);
    iTextTable.setDefaultColspan(1);
    Iterator it = tableValList.iterator();
    //for (int m = 0 ; m < cellValList.size() ; m ++)
    while(it.hasNext())
    {
    //表头信息
    Cell cell = new Cell(new Phrase((String)it.next(), new Font(bfChinese, 10, Font.BOLD, new Color(0, 0, 255))));
    cell.setHorizontalAlignment(Element.ENTITY_NODE);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    iTextTable.addCell(cell);
    }
    document.add(iTextTable);
    }
    }catch(Exception e){
    e.printStackTrace();
    }

    }
    bodyChildNode = bodyChildNode.getNextSibling();
    }
    }
    }