Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.LwgPdfPTable


        return rows;
    }
   
    public LwgPdfPTable buildTable() {
        if (rows.isEmpty())
            return new LwgPdfPTable(1);
        int ncol = 0;
        ArrayList c0 = (ArrayList)rows.get(0);
        for (int k = 0; k < c0.size(); ++k) {
            ncol += ((LwgPdfPCell)c0.get(k)).getColspan();
        }
        LwgPdfPTable table = new LwgPdfPTable(ncol);
        String width = (String)props.get("width");
        if (width == null)
            table.setWidthPercentage(100);
        else {
            if (width.endsWith("%"))
                table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1)));
            else {
                table.setTotalWidth(Float.parseFloat(width));
                table.setLockedWidth(true);
            }
        }
        for (int row = 0; row < rows.size(); ++row) {
            ArrayList col = (ArrayList)rows.get(row);
            for (int k = 0; k < col.size(); ++k) {
                table.add((LwgPdfPCell)col.get(k));
            }
        }
        return table;
    }
View Full Code Here


      if (tag.equals("table")) {
        if (pendingTR)
          endElement("tr");
        cprops.removeChain("table");
        IncTable table = (IncTable) stack.pop();
        LwgPdfPTable tb = table.buildTable();
        tb.setSplitRows(true);
        if (stack.empty())
          document.add(tb);
        else
          ((TextElementArray) stack.peek()).add(tb);
        boolean state[] = (boolean[]) tableState.pop();
View Full Code Here

      cell = (SimpleCell)i.next();
      columns += cell.getColspan();
    }
    float[] widths = new float[columns];
    float[] widthpercentages = new float[columns];
    LwgPdfPTable table = new LwgPdfPTable(columns);
    table.setTableEvent(this);
    table.setHorizontalAlignment(alignment);
    int pos;
    for (Iterator rows = content.iterator(); rows.hasNext(); ) {
      row = (SimpleCell)rows.next();
      pos = 0;
      for (Iterator cells = row.getContent().iterator(); cells.hasNext(); ) {
        cell = (SimpleCell)cells.next();
        if (Float.isNaN(cell.getSpacing_left()))  {
          cell.setSpacing_left(cellspacing / 2f);
        }
        if (Float.isNaN(cell.getSpacing_right()))  {
          cell.setSpacing_right(cellspacing / 2f);
        }
        if (Float.isNaN(cell.getSpacing_top()))  {
          cell.setSpacing_top(cellspacing / 2f);
        }
        if (Float.isNaN(cell.getSpacing_bottom()))  {
          cell.setSpacing_bottom(cellspacing / 2f);
        }
        cell.setPadding(cellpadding);
        table.add(cell.createPdfPCell(row));
        if (cell.getColspan() == 1) {
          if (cell.getWidth() > 0) widths[pos] = cell.getWidth();
          if (cell.getWidthpercentage() > 0) widthpercentages[pos] = cell.getWidthpercentage();
        }
        pos += cell.getColspan();
      }
    }
    float sumWidths = 0f;
    for(int i = 0; i < columns; i++) {
      if (widths[i] == 0) {
        sumWidths = 0;
        break;
      }
      sumWidths += widths[i];
    }
    if (sumWidths > 0) {
      table.setTotalWidth(sumWidths);
      table.setWidths(widths);
    }
    else {
      for(int i = 0; i < columns; i++) {
        if (widthpercentages[i] == 0) {
          sumWidths = 0;
          break;
        }
        sumWidths += widthpercentages[i];
      }
      if (sumWidths > 0) {
        table.setWidths(widthpercentages);
      }
    }
    if (width > 0) {
      table.setTotalWidth(width);
    }
    if (widthpercentage > 0) {
      table.setWidthPercentage(widthpercentage);
    }
    return table;
  }
View Full Code Here

      if (!convert2pdfptable) {
        throw new BadElementException(MessageLocalization.getComposedMessage("no.error.just.an.old.style.table"));
      }
        setAutoFillEmptyCells(true);
      complete();
      LwgPdfPTable pdfptable = new LwgPdfPTable(widths);
      pdfptable.setComplete(complete);
      if (isNotAddedYet())
        pdfptable.setSkipFirstHeader(true);
      SimpleTable t_evt = new SimpleTable();
    t_evt.cloneNonPositionParameters(this);
    t_evt.setCellspacing(cellspacing);
      pdfptable.setTableEvent(t_evt);
      pdfptable.setHeaderRows(lastHeaderRow + 1);
      pdfptable.setSplitLate(cellsFitPage);
      pdfptable.setKeepTogether(tableFitsPage);
      if (!Float.isNaN(offset)) {
        pdfptable.setSpacingBefore(offset);
      }
      pdfptable.setHorizontalAlignment(alignment);
      if (locked) {
        pdfptable.setTotalWidth(width);
        pdfptable.setLockedWidth(true);
      }
      else {
        pdfptable.setWidthPercentage(width);
      }
      LwgRow row;
        for (Iterator iterator = iterator(); iterator.hasNext(); ) {
            row = (LwgRow) iterator.next();
            LwgElement cell;
            LwgPdfPCell pcell;
            for (int i = 0; i < row.getColumns(); i++) {
                if ((cell = (LwgElement)row.getCell(i)) != null) {
                  if (cell instanceof Table) {
                    pcell = new LwgPdfPCell(((Table)cell).createPdfPTable());
                  }
                  else if (cell instanceof LwgCell) {
                    pcell = ((LwgCell)cell).createPdfPCell();
                    pcell.setPadding(cellpadding + cellspacing / 2f);
                    SimpleCell c_evt = new SimpleCell(SimpleCell.CELL);
                    c_evt.cloneNonPositionParameters((LwgCell)cell);
                    c_evt.setSpacing(cellspacing * 2f);
                        pcell.setCellEvent(c_evt);
                  }
                  else {
                    pcell = new LwgPdfPCell();
                  }
                  pdfptable.add(pcell);
                }
            }
        }
      return pdfptable;
    }
View Full Code Here

     */
    public void onOpenDocument(PdfWriter writer, LwgDocument document) {
        try {
          // initialization of the header table
            headerImage = LwgImage.getInstance("logo.gif");
            table = new LwgPdfPTable(2);
            LwgPhrase p = new LwgPhrase();
            Chunk ck = new Chunk("lowagie.com\n", new LwgFont(LwgFont.TIMES_ROMAN, 16, LwgFont.BOLDITALIC, Color.blue));
            p.add(ck);
            ck = new Chunk("Ghent\nBelgium", new LwgFont(LwgFont.HELVETICA, 12, LwgFont.NORMAL, Color.darkGray));
            p.add(ck);
View Full Code Here

     * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
     */
    public void onEndPage(PdfWriter writer, LwgDocument document) {
        try {
            LwgRectangle page = document.getPageSize();
            LwgPdfPTable head = new LwgPdfPTable(3);
            for (int k = 1; k <= 6; ++k)
                head.add("head " + k);
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(),
                writer.getDirectContent());
            LwgPdfPTable foot = new LwgPdfPTable(3);
            for (int k = 1; k <= 6; ++k)
                foot.add("foot " + k);
            foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
        }
        catch (Exception e) {
            throw new ExceptionConverter(e);
        }
View Full Code Here

      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellPaddingLeading.pdf"));
      // step3
      document.open();
      // step4
      LwgPdfPTable table = new LwgPdfPTable(2);
      LwgPdfPCell cell;
      Paragraph p = new Paragraph("Quick brown fox jumps over the lazy dog. Quick brown fox jumps over the lazy dog.");
      table.add("default");
      table.add(p);
      table.add("padding 10");
      cell = new LwgPdfPCell(p);
      cell.setPadding(10f);
      table.add(cell);
      table.add("no padding at all");
      cell = new LwgPdfPCell(p);
      cell.setPadding(0f);
      table.add(cell);
      table.add("no padding at the top; large padding at the left");
      cell = new LwgPdfPCell(p);
      cell.setPaddingTop(0f);
      cell.setPaddingLeft(20f);
      table.add(cell);
      document.add(table);
     
      document.newPage();
      table = new LwgPdfPTable(2);
      table.add("no leading at all");
      table.getDefaultCell().setLeading(0f, 0f);
      table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
      table.getDefaultCell().setLeading(14f, 0f);
      table.add("fixed leading of 14pt");
      table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
      table.add("relative leading of 1.0 times the fontsize");
      table.getDefaultCell().setLeading(0f, 1.0f);
      table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
View Full Code Here

      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.NestedTables.pdf"));
      // step3
      document.open();
      // step4
            LwgPdfPTable table = new LwgPdfPTable(4);
            LwgPdfPTable nested1 = new LwgPdfPTable(2);
            nested1.add("1.1");
            nested1.add("1.2");
            LwgPdfPTable nested2 = new LwgPdfPTable(1);
            nested2.add("2.1");
            nested2.add("2.2");
            for (int k = 0; k < 24; ++k) {
                if (k == 1) {
                    table.add(nested1);
                }
                else if (k == 20) {
View Full Code Here

      document2.open();
      document3.open();
      // step4
      String text = "Quick brown fox jumps over the lazy dog. ";
      for (int i = 0; i < 5; i++) text += text;
      LwgPdfPTable table = new LwgPdfPTable(2);
      LwgPdfPCell largeCell;
      LwgPhrase phrase;
      for (int i = 0; i < 10; i++) {
        phrase = new LwgPhrase(text);
        for (int j = 0; j < i; j++) {
          phrase.add(new LwgPhrase(text));
        }
        if (i == 7) phrase = new LwgPhrase(text);
        table.add(String.valueOf(i));
        largeCell = new LwgPdfPCell(phrase);
        table.add(largeCell);
      }
      document1.add(table);
      table.setSplitLate(false);
      document2.add(table);
      table.setSplitRows(false);
      document3.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
View Full Code Here

          new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellWidths.pdf"));
      // step3
      document.open();
      // step4
      float[] widths = {0.1f, 0.1f, 0.05f, 0.75f};
      LwgPdfPTable table = new LwgPdfPTable(widths);
      table.add("10%");
      table.add("10%");
      table.add("5%");
      table.add("75%");
      table.add("aa");
      table.add("aa");
      table.add("a");
      table.add("aaaaaaaaaaaaaaa");
      table.add("bb");
      table.add("bb");
      table.add("b");
      table.add("bbbbbbbbbbbbbbb");
      table.add("cc");
      table.add("cc");
      table.add("c");
      table.add("ccccccccccccccc");
      document.add(table);
      document.add(new Paragraph("We change the percentages:\n\n"));
      widths[0] = 20f;
      widths[1] = 20f;
      widths[2] = 10f;
      widths[3] = 50f;
      table.setWidths(widths);
      document.add(table);
      widths[0] = 40f;
      widths[1] = 40f;
      widths[2] = 20f;
      widths[3] = 300f;
      LwgRectangle r = new LwgRectangle(LwgPageSize.A4.getRight(72), LwgPageSize.A4.getTop(72));
      table.setWidthPercentage(widths, r);
      document.add(new Paragraph("We change the percentage using absolute widths:\n\n"));
      document.add(table);
      document.add(new Paragraph("We use a locked width:\n\n"));
      table.setTotalWidth(300);
      table.setLockedWidth(true);
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.LwgPdfPTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.