Package com.lowagie.text

Examples of com.lowagie.text.Table


      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.alternatives.TableWithImage.pdf"));
      // step 3: we open the document
      document.open();
      // step 4: we create a table and add it to the document
      Table table = new Table(2, 2); // 2 rows, 2 columns
      table.addCell(new LwgCell(LwgImage.getInstance("otsoe.jpg")));
      table.addCell(new LwgCell(LwgImage.getInstance("iText.gif")));
      LwgCell c1 = new LwgCell();
      c1.add(LwgImage.getInstance("iText.gif"));
      table.addCell(c1);
      LwgCell c2 = new LwgCell();
      c2.add(LwgImage.getInstance("otsoe.jpg"));
      table.addCell(c2);
      document.add(table);
      document.add(new Paragraph("converted to PdfPTable:"));
      table.setConvert2pdfptable(true);
      document.add(table);
    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
View Full Code Here


            PdfWriter.getInstance(document,
                    new GfrFileOutputStream("com.lowagie.examples.objects.tables.alternatives.OldTable.pdf"));
            // step 3: we open the document
            document.open();
            // step 4: we create a table and add it to the document
            Table table = new Table(3);
            table.setBorderWidth(1);
            table.setBorderColor(new Color(0, 0, 255));
            table.setPadding(5);
            table.setSpacing(5);
            LwgCell cell = new LwgCell("header");
            cell.setHeader(true);
            cell.setColspan(3);
            table.addCell(cell);
            cell = new LwgCell("example cell with colspan 1 and rowspan 2");
            cell.setRowspan(2);
            cell.setBorderColor(new Color(255, 0, 0));
            table.addCell(cell);
            table.addCell("1.1");
            table.addCell("2.1");
            table.addCell("1.2");
            table.addCell("2.2");
            table.addCell("cell test1");
            cell = new LwgCell("big cell");
            cell.setRowspan(2);
            cell.setColspan(2);
            cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
            table.addCell(cell);
            table.addCell("cell test2");
            document.add(table);
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
View Full Code Here

     * Initialize the main info holder table.
     * @throws BadElementException for errors during table initialization
     */
    protected void initTable() throws BadElementException
    {
        tablePDF = new Table(this.model.getNumberOfColumns());
        tablePDF.setDefaultVerticalAlignment(Element.ALIGN_TOP);
        tablePDF.setCellsFitPage(true);
        tablePDF.setWidth(100);

        tablePDF.setPadding(2);
View Full Code Here

        try
        {
            Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40);
            this.initItextWriter(document, out);
            document.open();
            Table table = new Table(this.model.getNumberOfColumns());
            ItextTableWriter writer = new ItextTableWriter(table, document);
            writer.writeTable(this.model, "-1");
            document.add(table);
            document.close();
        }
View Full Code Here

       
        p = new Paragraph(slt.getTitle(), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16));
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);
       
        Table t = new Table(4);
        t.setWidths(new int[]{10,5, 50, 35});
        t.setPadding(2.0f);
        t.setWidth(100.0f);
       
        t.addCell(createHeaderCell(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("TIME")));
        t.addCell(createHeaderCell(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("MIN")));
        t.addCell(createHeaderCell(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("TITLE")));
        t.addCell(createHeaderCell(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("NOTES")));
       
       
        for (int i=0; i<slt.getRowCount(); i++){
           
            ServiceItem si = (ServiceItem) slt.getServiceItem(i);
            Cell c;

            // Start time
            c = new Cell(si.getStartTime());
            c.setMaxLines(1);
            c.setVerticalAlignment(Cell.ALIGN_MIDDLE);
            c.setHorizontalAlignment(Cell.ALIGN_CENTER);
            t.addCell(c);
           
            // Duration
            c = new Cell(Integer.toString(si.getDuration()));
            c.setMaxLines(1);
            c.setVerticalAlignment(Cell.ALIGN_MIDDLE);
            c.setHorizontalAlignment(Cell.ALIGN_RIGHT);
            t.addCell(c);
           
            // Title
            c = new Cell(si.getTitle());
            c.setVerticalAlignment(Cell.ALIGN_MIDDLE);
            t.addCell(c);

            // Notes
            c = new Cell(si.getNotes());
            c.setVerticalAlignment(Cell.ALIGN_MIDDLE);
            t.addCell(c);

        }
       
        document.add(t);
       
View Full Code Here

                writeEnd(HtmlTags.ROW);
                return;
            }
            case Element.TABLE:
            {
              Table table;
              try {
                table = (Table) element;
              }
              catch(ClassCastException cce) {
                try {
            table = ((SimpleTable)element).createTable();
          } catch (BadElementException e) {
            throw new ExceptionConverter(e);
          }
              }
                table.complete();
                // start tag
                addTabs(indent);
                writeStart(HtmlTags.TABLE);
                writeMarkupAttributes(markup);
                os.write(SPACE);
                write(HtmlTags.WIDTH);
                os.write(EQUALS);
                os.write(QUOTE);
                write(String.valueOf(table.getWidth()));
                if (!table.isLocked()){
                    write("%");
                }
                os.write(QUOTE);
                String alignment = HtmlEncoder.getAlignment(table.getAlignment());
                if (!"".equals(alignment)) {
                    write(HtmlTags.ALIGN, alignment);
                }
                write(HtmlTags.CELLPADDING, String.valueOf(table.getPadding()));
                write(HtmlTags.CELLSPACING, String.valueOf(table.getSpacing()));
                if (table.getBorderWidth() != Rectangle.UNDEFINED) {
                    write(HtmlTags.BORDERWIDTH, String.valueOf(table.getBorderWidth()));
                }
                if (table.getBorderColor() != null) {
                    write(HtmlTags.BORDERCOLOR, HtmlEncoder.encode(table.getBorderColor()));
                }
                if (table.getBackgroundColor() != null) {
                    write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(table.getBackgroundColor()));
                }
                os.write(GT);
                // contents
                Row row;
                for (Iterator iterator = table.iterator(); iterator.hasNext(); ) {
                    row = (Row) iterator.next();
                    write(row, indent + 1);
                }
                // end tag
                addTabs(indent);
View Full Code Here

            return;
        }

        // tables
        if (ElementTags.TABLE.equals(name)) {
            Table table = ElementFactory.getTable(attributes);
            float widths[] = table.getProportionalWidths();
            for (int i = 0; i < widths.length; i++) {
                if (widths[i] == 0) {
                    widths[i] = 100.0f / widths.length;
                }
            }
            try {
                table.setWidths(widths);
            } catch (BadElementException bee) {
                // this shouldn't happen
                throw new ExceptionConverter(bee);
            }
            stack.push(table);
View Full Code Here

                stack.push(list);
            }

            // tables
            if (ElementTags.TABLE.equals(name)) {
                Table table = (Table) stack.pop();
                try {
                    TextElementArray previous = (TextElementArray) stack.pop();
                    previous.add(table);
                    stack.push(previous);
                } catch (EmptyStackException ese) {
                    document.add(table);
                }
                return;
            }

            // rows
            if (ElementTags.ROW.equals(name)) {
                ArrayList cells = new ArrayList();
                int columns = 0;
                Table table;
                Cell cell;
                while (true) {
                    Element element = (Element) stack.pop();
                    if (element.type() == Element.CELL) {
                        cell = (Cell) element;
                        columns += cell.getColspan();
                        cells.add(cell);
                    } else {
                        table = (Table) element;
                        break;
                    }
                }
                if (table.getColumns() < columns) {
                    table.addColumns(columns - table.getColumns());
                }
                Collections.reverse(cells);
                String width;
                float[] cellWidths = new float[columns];
                boolean[] cellNulls = new boolean[columns];
                for (int i = 0; i < columns; i++) {
                    cellWidths[i] = 0;
                    cellNulls[i] = true;
                }
                float total = 0;
                int j = 0;
                for (Iterator i = cells.iterator(); i.hasNext();) {
                    cell = (Cell) i.next();
                    width = cell.getWidthAsString();
                    if (cell.getWidth() == 0) {
                        if (cell.getColspan() == 1 && cellWidths[j] == 0) {
                            try {
                                cellWidths[j] = 100f / columns;
                                total += cellWidths[j];
                            } catch (Exception e) {
                                // empty on purpose
                            }
                        } else if (cell.getColspan() == 1) {
                            cellNulls[j] = false;
                        }
                    } else if (cell.getColspan() == 1 && width.endsWith("%")) {
                        try {
                            cellWidths[j] = Float.parseFloat(
                                    width.substring(0, width.length() - 1)
                                            + "f");
                            total += cellWidths[j];
                        } catch (Exception e) {
                            // empty on purpose
                        }
                    }
                    j += cell.getColspan();
                    table.addCell(cell);
                }
                float widths[] = table.getProportionalWidths();
                if (widths.length == columns) {
                    float left = 0.0f;
                    for (int i = 0; i < columns; i++) {
                        if (cellNulls[i] && widths[i] != 0) {
                            left += widths[i];
                            cellWidths[i] = widths[i];
                        }
                    }
                    if (100.0 >= total) {
                        for (int i = 0; i < widths.length; i++) {
                            if (cellWidths[i] == 0 && widths[i] != 0) {
                                cellWidths[i] = (widths[i] / left)
                                        * (100.0f - total);
                            }
                        }
                    }
                    table.setWidths(cellWidths);
                }
                stack.push(table);
            }

            // cells
View Full Code Here

      int actorsNumber = data.getColumns().size();
      // columns
      int optionsNumber = options.size();

      Iterator<ColumnData> iActors = data.getColumns().iterator();
      Table table = new Table(optionsNumber+1, actorsNumber+1);
      table.setWidth(100);
      table.setBorderWidth(1);
      //table.setBorderColor(new Color(0, 0, 255));
      table.setPadding(4);
      table.setSpacing(0);

      // first cell has to be void
      table.addCell(new Cell("Options/\r\nWedges"),0,0);

      int row = 1;
      while (iActors.hasNext()){
    Cell app = new Cell(iActors.next().getTitle());
    //app.setNoWrap(true);
    app.setHorizontalAlignment(Element.ALIGN_CENTER);
    app.setVerticalAlignment(Element.ALIGN_CENTER);
    table.addCell(app,row++,0);
      }

      row = 1;
      int column = 1;

      while (iOptions.hasNext()){
    // working with a single option
    OptionData o = iOptions.next();

    String optionName = o.getTitle();
    if ((optionName==null)||(optionName.length()==0)) optionName = "No (Option) name provided.";
    //Paragraph optionNamePar = new Paragraph(optionName, fntRomanOptionTitle);
    Paragraph optionNamePar = new Paragraph(optionName, fntRomanOptionTitle);
    ListItem item = new ListItem(optionNamePar);

    String optionDescription = o.getDescription();
    if ((optionDescription!=null)&&(optionDescription.length()!=0)) {
        //Paragraph optionDescriptionPar = new Paragraph("\r\n" + optionDescription, fntRomanOptionDescription);
        Paragraph optionDescriptionPar = new Paragraph("\r\n" + optionDescription, fntRomanOptionDescription);
        optionDescriptionPar.setSpacingAfter(12);
        //optionDescriptionPar.setSpacingBefore(0);
        item.add(optionDescriptionPar);
    }

    itemize.add(item);

    // prepare the table
    iActors = data.getColumns().iterator();
    row = 0;
    //System.out.println("option: " + o.getTitle());
    Cell optionNameHeader = new Cell(o.getTitle());
    //optionNameHeader.rotate();
    optionNameHeader.setHeader(true);
    //cell.setColspan(3);
    table.addCell(optionNameHeader,row++,column);
    table.endHeaders();
    //table.addCell(new Cell(o.getTitle()),row++,column);
    while ((iActors.hasNext())) {
        ColumnData cd = iActors.next();
        WedgeData wd = cd.getWedge(o);
        Cell c;
        if(wd == null) {
      //c = new Cell("-");
      c = new Cell();
        } else {
      double coeff = wd.getCoefficient();
      c = new Cell(new Phrase(Double.toString(coeff),fntRomanTableAllFields));
        }
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        c.setVerticalAlignment(Element.ALIGN_CENTER);
        /*
        System.out.println("table: " + table.columns());
        System.out.println("x,y: " + row + " " + column);
        System.out.println("cell: " + c);
         */
        table.addCell(c,row++,column);
    }
    column++;

      }
      // areaSec.add(itemize);
      doc.add(itemize);

      // postprocess on table: to remove at next release...

      Iterator iRow = table.iterator();
      while (iRow.hasNext()) {
    Row r = (Row)iRow.next();
    Cell c = (Cell)r.getCell(1);
    if (c.isEmpty()) iRow.remove();
      }

      // deny row split
      table.setCellsFitPage(true);
      doc.add(table);

      /*
      // now I have finished with properties
      // start with the actor/option table with votes
View Full Code Here

   * @param attributes
   * @return a Table
   */
  public static Table getTable(Properties attributes) {
    String value;
    Table table;
    try {

      value = attributes.getProperty(ElementTags.WIDTHS);
      if (value != null) {
        StringTokenizer widthTokens = new StringTokenizer(value, ";");
        ArrayList values = new ArrayList();
        while (widthTokens.hasMoreTokens()) {
          values.add(widthTokens.nextToken());
        }
        table = new Table(values.size());
        float[] widths = new float[table.getColumns()];
        for (int i = 0; i < values.size(); i++) {
          value = (String) values.get(i);
          widths[i] = Float.parseFloat(value + "f");
        }
        table.setWidths(widths);
      } else {
        value = attributes.getProperty(ElementTags.COLUMNS);
        try {
          table = new Table(Integer.parseInt(value));
        } catch (Exception e) {
          table = new Table(1);
        }
      }

      table.setBorder(Table.BOX);
      table.setBorderWidth(1);
      table.getDefaultCell().setBorder(Table.BOX);

      value = attributes.getProperty(ElementTags.LASTHEADERROW);
      if (value != null) {
        table.setLastHeaderRow(Integer.parseInt(value));
      }
      value = attributes.getProperty(ElementTags.ALIGN);
      if (value != null) {
        table.setAlignment(value);
      }
      value = attributes.getProperty(ElementTags.CELLSPACING);
      if (value != null) {
        table.setSpacing(Float.parseFloat(value + "f"));
      }
      value = attributes.getProperty(ElementTags.CELLPADDING);
      if (value != null) {
        table.setPadding(Float.parseFloat(value + "f"));
      }
      value = attributes.getProperty(ElementTags.OFFSET);
      if (value != null) {
        table.setOffset(Float.parseFloat(value + "f"));
      }
      value = attributes.getProperty(ElementTags.WIDTH);
      if (value != null) {
        if (value.endsWith("%"))
          table.setWidth(Float.parseFloat(value.substring(0, value
              .length() - 1)
              + "f"));
        else {
          table.setWidth(Float.parseFloat(value + "f"));
          table.setLocked(true);
        }
      }
      table.setTableFitsPage(Utilities.checkTrueOrFalse(attributes,
          ElementTags.TABLEFITSPAGE));
      table.setCellsFitPage(Utilities.checkTrueOrFalse(attributes,
          ElementTags.CELLSFITPAGE));
      table.setConvert2pdfptable(Utilities.checkTrueOrFalse(attributes,
          ElementTags.CONVERT2PDFP));

      setRectangleProperties(table, attributes);
      return table;
    } catch (BadElementException e) {
View Full Code Here

TOP

Related Classes of com.lowagie.text.Table

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.