Package com.lowagie.text

Examples of com.lowagie.text.Table


            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 / (float) 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

   * @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) {
      throw new ExceptionConverter(e);
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

        document.addTitle("Order :" + order.getId());
        document.add(new Paragraph("Order date: " + order.getOrderDate()));
        document.add(new Paragraph("Delivery date: " + order.getDeliveryDate()));

        Table orderDetails = new Table(4);
        orderDetails.addCell("Title");
        orderDetails.addCell("Price");
        orderDetails.addCell("#");
        orderDetails.addCell("Total");

        for (OrderDetail detail : order.getOrderDetails()) {
            orderDetails.addCell(detail.getBook().getTitle());
            orderDetails.addCell(detail.getBook().getPrice().toString());
            orderDetails.addCell(String.valueOf(detail.getQuantity()));
            orderDetails.addCell(detail.getPrice().toString());
        }

        document.add(orderDetails);

    }
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

                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

      PdfWriter.getInstance(document,
          new FileOutputStream("imageTable.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 Cell(Image.getInstance("otsoe.jpg")));
      table.addCell(new Cell(Image.getInstance("iText.gif")));
      Cell c1 = new Cell();
      c1.add(Image.getInstance("iText.gif"));
      table.addCell(c1);
      Cell c2 = new Cell();
      c2.add(Image.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

            Document document = new Document();
            RtfWriter2.getInstance(document, new FileOutputStream("ExtendedTableCell.rtf"));

            document.open();
           
            Table table = new Table(3);

            // Create a simple RtfCell with a dotted border.
            RtfCell cellDotted = new RtfCell("Dotted border");
            cellDotted.setBorders(new RtfBorderGroup(Rectangle.BOX,
                    RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
           
            // Create a simple RtfCell with an embossed border.
            RtfCell cellEmbossed = new RtfCell("Embossed border");
            cellEmbossed.setBorders(new RtfBorderGroup(Rectangle.BOX,
                    RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0)));
           
            // Create a simple RtfCell with no border.
            RtfCell cellNoBorder = new RtfCell("No border");
            cellNoBorder.setBorders(new RtfBorderGroup());
            cellNoBorder.setRowspan(2);
           
            // Create a simple RtfCell that only has a border
            // on the bottom side.
            RtfCell bottomBorder = new RtfCell("Bottom border");
            bottomBorder.setBorders(new RtfBorderGroup(Rectangle.BOTTOM,
                    RtfBorder.BORDER_SINGLE, 2, new Color(255, 0, 0)));
           
            // Create a simple RtfCell that has different borders
            // on the left and bottom sides.
            RtfCell mixedBorder = new RtfCell("Mixed border");
            RtfBorderGroup mixedBorders = new RtfBorderGroup();
            mixedBorders.addBorder(Rectangle.RIGHT,
                    RtfBorder.BORDER_DOUBLE_WAVY, 2, Color.GREEN);
            mixedBorders.addBorder(Rectangle.BOTTOM,
                    RtfBorder.BORDER_DOT_DASH, 1, Color.BLUE);
            mixedBorder.setBorders(mixedBorders);
           
            // Add the cells to the table
            table.addCell(cellDotted);
            table.addCell(cellEmbossed);
            table.addCell(cellNoBorder);
            table.addCell(bottomBorder);
            table.addCell(mixedBorder);
           
            document.add(table);

            document.close();
        } catch (FileNotFoundException fnfe) {
View Full Code Here

            RtfWriter2 writer2 = RtfWriter2.getInstance(doc,
                    new FileOutputStream("testNew.rtf"));

            writer2.setAutogenerateTOCEntries(true);

            Table headerTable = new Table(3);
            headerTable.addCell("Test Cell 1");
            headerTable.addCell("Test Cell 2");
            headerTable.addCell("Test Cell 3");
            HeaderFooter header = new RtfHeaderFooter(headerTable);
            RtfHeaderFooterGroup footer = new RtfHeaderFooterGroup();
            footer
                    .setHeaderFooter(
                            new RtfHeaderFooter(new Phrase(
                                    "This is the footer on the title page")),
                            com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_FIRST_PAGE);
            footer
                    .setHeaderFooter(
                            new RtfHeaderFooter(new Phrase(
                                    "This is a left side page")),
                            com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_LEFT_PAGES);
            footer
                    .setHeaderFooter(
                            new RtfHeaderFooter(new Phrase(
                                    "This is a right side page")),
                            com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_RIGHT_PAGES);

            doc.setHeader(header);
            doc.setFooter(footer);

            doc.open();

            Paragraph p = new Paragraph();
            p.add(new RtfTableOfContents("UPDATE ME!"));
            doc.add(p);

            p = new Paragraph("", new RtfFont("Staccato222 BT"));
            p.add(new Chunk("Hello! "));
            p.add(new Chunk("How do you do?"));
            doc.add(p);
            p.setAlignment(Element.ALIGN_RIGHT);
            doc.add(p);

            Anchor a = new Anchor("http://www.uni-klu.ac.at");
            a.setReference("http://www.uni-klu.ac.at");
            doc.add(a);

            Image img = Image.getInstance("pngnow.png");
            doc.add(new Chunk(img, 0, 0));
            doc.add(new Annotation("Mark", "This works!"));

            Chunk c = new Chunk("");
            c.setNewPage();
            doc.add(c);

            List subList = new List(true, 40);
            subList.add(new ListItem("Sub list 1"));
            subList.add(new ListItem("Sub list 2"));

            List list = new List(true, 20);
            list.add(new ListItem("Test line 1"));
            list
                    .add(new ListItem(
                            "Test line 2 - This is a really long test line to test that linebreaks are working the way they are supposed to work so a really really long line of drivel is required"));
            list.add(subList);
            list.add(new ListItem("Test line 3 - \t\u20ac\t 60,-"));
            doc.add(list);

            list = new List(false, 20);
            list.add(new ListItem("Bullet"));
            list.add(new ListItem("Another one"));
            doc.add(list);

            doc.newPage();

            Chapter chapter = new Chapter(new Paragraph("This is a Chapter"), 1);
            chapter.add(new Paragraph(
                    "This is some text that belongs to this chapter."));
            chapter.add(new Paragraph("A second paragraph. What a surprise."));

            Section section = chapter.addSection(new Paragraph(
                    "This is a subsection"));
            section.add(new Paragraph("Text in the subsection."));

            doc.add(chapter);

            com.lowagie.text.rtf.field.RtfTOCEntry rtfTOC = new com.lowagie.text.rtf.field.RtfTOCEntry(
                    "Table Test");
            doc.add(rtfTOC);

            Table table = new Table(3);
            table.setPadding(2);
            table.setAlignment(Element.ALIGN_LEFT);
            table.setSpacing(2);

            Cell emptyCell = new Cell("");

            Cell cellLeft = new Cell("Left Alignment");
            cellLeft.setHorizontalAlignment(Element.ALIGN_LEFT);
            Cell cellCenter = new Cell("Center Alignment");
            cellCenter.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cellRight = new Cell("Right Alignment");
            cellRight.setHorizontalAlignment(Element.ALIGN_RIGHT);

            table.addCell(cellLeft);
            table.addCell(cellCenter);
            table.addCell(cellRight);

            Cell cellSpanHoriz = new Cell("This Cell spans two columns");
            cellSpanHoriz.setColspan(2);
            table.addCell(cellSpanHoriz);
            table.addCell(emptyCell);

            Cell cellSpanVert = new Cell("This Cell spans two rows");
            cellSpanVert.setRowspan(2);
            table.addCell(emptyCell);
            table.addCell(cellSpanVert);
            table.addCell(emptyCell);
            table.addCell(emptyCell);
            table.addCell(emptyCell);

            Cell cellSpanHorizVert = new Cell(
                    "This Cell spans both two columns and two rows");
            cellSpanHorizVert.setColspan(2);
            cellSpanHorizVert.setRowspan(2);
            table.addCell(emptyCell);
            table.addCell(cellSpanHorizVert);
            table.addCell(emptyCell);

            RtfCell cellDotted = new RtfCell("Dotted border");
            cellDotted.setBorders(new RtfBorderGroup(Rectangle.BOX,
                    RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
            RtfCell cellEmbossed = new RtfCell("Embossed border");
            cellEmbossed.setBorders(new RtfBorderGroup(Rectangle.BOX,
                    RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0)));
            RtfCell cellNoBorder = new RtfCell("No border");
            cellNoBorder.setBorders(new RtfBorderGroup());

            table.addCell(cellDotted);
            table.addCell(cellEmbossed);
            table.addCell(cellNoBorder);

            doc.add(table);

            for (int i = 0; i < 300; i++) {
                doc.add(new Paragraph(
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.