Package com.lowagie.text

Examples of com.lowagie.text.Table


    }

    public static Table newTable(final String topic,
                                 Collection<String> items) throws BadElementException,
                                                          DocumentException {
        Table table = newTable();

        Cell headerCell = newHeaderCell( topic,
                                         CATEGORIES_TEXT );
        table.addCell( headerCell );

        if ( items.isEmpty() ) {
            table.addCell( newCell( " - " ) );
        } else {
            for ( String s : items ) {
                table.addCell( newCell( s ) );
            }
        }

        return table;
    }
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;
                LwgCell cell;
                while (true) {
                    LwgElement element = (LwgElement) stack.pop();
                    if (element.type() == LwgElement.CELL) {
                        cell = (LwgCell) 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 = (LwgCell) 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];
                            cellNulls[j] = false;
                        } 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

                writeEnd(HtmlTags.ROW);
                return;
            }
            case LwgElement.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() != LwgRectangle.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
                LwgRow row;
                for (Iterator iterator = table.iterator(); iterator.hasNext(); ) {
                    row = (LwgRow) iterator.next();
                    write(row, indent + 1);
                }
                // end tag
                addTabs(indent);
View Full Code Here

                document.add(new Paragraph("Line " + i));
            }
           
            document.add(new RtfTOCEntry("Cell border demonstration"));

            Table table = new Table(3);

            RtfCell cellDotted = new RtfCell("Dotted border");
            cellDotted.setBorders(new RtfBorderGroup(LwgRectangle.BOX, RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
            RtfCell cellEmbossed = new RtfCell("Embossed border");
            cellEmbossed.setBorders(new RtfBorderGroup(LwgRectangle.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);
           
            document.add(table);
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
View Full Code Here

            PdfWriter.getInstance(document,
                    new GfrFileOutputStream("com.lowagie.examples.objects.tables.alternatives.SpecificCells.pdf"));
            // step 3: we open the document
            document.open();
            // step 4: we create a table and add it to the document
            Table aTable;
           
            aTable = new Table(4,4);    // 4 rows, 4 columns
            aTable.setAlignment(LwgElement.ALIGN_RIGHT);
            aTable.addCell("2.2", new Point(2,2));
            aTable.addCell("3.3", new Point(3,3));
            aTable.addCell("2.1", new Point(2,1));
            aTable.addCell("1.3", new Point(1,3));
            document.add(aTable);
      document.add(new Paragraph("converted to PdfPTable:"));
      aTable.setConvert2pdfptable(true);
      document.add(aTable);
            document.newPage();    
            aTable = new Table(4,4);    // 4 rows, 4 columns
            aTable.setAlignment(LwgElement.ALIGN_CENTER);
            aTable.addCell("2.2", new Point(2,2));
            aTable.addCell("3.3", new Point(3,3));
            aTable.addCell("2.1", new Point(2,1));
            aTable.addCell("1.3", new Point(1,3));
            aTable.addCell("5.2", new Point(5,2));
            aTable.addCell("6.1", new Point(6,1));
            aTable.addCell("5.0", new Point(5,0))
            document.add(aTable);
      document.add(new Paragraph("converted to PdfPTable:"));
      aTable.setConvert2pdfptable(true);
      document.add(aTable);
            document.newPage();
            aTable = new Table(2,2);    // 2 rows, 2 columns
            aTable.setAlignment(LwgElement.ALIGN_LEFT);
            aTable.setAutoFillEmptyCells(true);
            aTable.addCell("0.0");
            aTable.addCell("0.1");
            aTable.addCell("1.0");
            aTable.addCell("1.1");
            aTable.addColumns(2);
            float[] f = {1f, 1f, 1f, 1f};
            aTable.setWidths(f);
            aTable.addCell("2.2", new Point(2,2));
            aTable.addCell("3.3", new Point(3,3));
            aTable.addCell("2.1", new Point(2,1));
            aTable.addCell("1.3", new Point(1,3));
            aTable.addCell("5.2", new Point(5,2));
            aTable.addCell("6.1", new Point(6,1));
            aTable.addCell("5.0", new Point(5,0));
            document.add(aTable);
      document.add(new Paragraph("converted to PdfPTable:"));
      aTable.setConvert2pdfptable(true);
      document.add(aTable);
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
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 LwgPhrase(
                                    "This is the footer on the title page")),
                            com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_FIRST_PAGE);
            footer
                    .setHeaderFooter(
                            new RtfHeaderFooter(new LwgPhrase(
                                    "This is a left side page")),
                            com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_LEFT_PAGES);
            footer
                    .setHeaderFooter(
                            new RtfHeaderFooter(new LwgPhrase(
                                    "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(LwgElement.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);

            LwgImage img = LwgImage.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(LwgElement.ALIGN_LEFT);
            table.setSpacing(2);

            LwgCell emptyCell = new LwgCell("");

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

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

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

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

            LwgCell cellSpanHorizVert = new LwgCell(
                    "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(LwgRectangle.BOX,
                    RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
            RtfCell cellEmbossed = new RtfCell("Embossed border");
            cellEmbossed.setBorders(new RtfBorderGroup(LwgRectangle.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

           
            // Set the header
            document.setHeader(header);

            // Create the table that will be used as the footer
            Table footer = new Table(2);
            footer.setBorder(0);
            footer.getDefaultCell().setBorder(0);
            footer.setWidth(100);
            footer.addCell(new LwgCell("(c) Mark Hall"));
            Paragraph pageNumber = new Paragraph("Page ");
           
            // The RtfPageNumber is an RTF specific element that adds a page number field
            pageNumber.add(new RtfPageNumber());
            pageNumber.setAlignment(Paragraph.ALIGN_RIGHT);
            footer.addCell(new LwgCell(pageNumber));
           
            // Create the RtfHeaderFooter and set it as the footer to use
            document.setFooter(new RtfHeaderFooter(footer));
           
            document.open();
View Full Code Here

            PdfWriter.getInstance(document,
                    new GfrFileOutputStream("com.lowagie.examples.objects.tables.alternatives.PaddingBorders.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(10);
            LwgCell cell = new LwgCell("header");
            cell.setHeader(true);
            cell.setColspan(3);
            table.addCell(cell);
            table.addCell("1.1");
            table.addCell("2.1");
            table.addCell("3.1");
            table.addCell("1.2");
            table.addCell("2.2");
            table.addCell("3.2");
            document.add(table);
            table.setConvert2pdfptable(true);
      document.add(new Paragraph("converted to PdfPTable:"));
            document.add(table);
           
            table = new Table(3);
            table.setBorderWidth(3);
            table.setBorderColor(new Color(255, 0, 0));
            table.setPadding(0);
            cell = new LwgCell("header");
            cell.setHeader(true);
            cell.setBorderColorBottom(new Color(0, 0, 255));
            cell.setColspan(3);
            table.addCell(cell);
            table.addCell("1.1");
            cell = new LwgCell("2.1");
            cell.setBorderWidthLeft(4);
            cell.setBorderWidthRight(8);
            cell.setBorderWidthTop(2);
            cell.setBorderWidthBottom(10);
            cell.setUseBorderPadding(true);
            cell.setBorderColorBottom(new Color(0, 255, 0));
            table.addCell(cell);
            table.addCell("3.1");
            table.addCell("1.2");
            table.addCell("2.2");
            table.addCell("3.2");
            document.add(table);
            table.setConvert2pdfptable(true);
      document.add(new Paragraph("converted to PdfPTable:"));
            document.add(table);
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
View Full Code Here

         PdfWriter.getInstance(document,
                 new GfrFileOutputStream("com.lowagie.examples.objects.tables.alternatives.LargeCell.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.setCellsFitPage(true);
         String text = "long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text";
         table.addCell("text");
         table.addCell("text");
         table.addCell("text");
         table.addCell(text);
         table.addCell(text + text);
         table.addCell(text);
         table.addCell("text");
         table.addCell("text");
         table.addCell("text");
         document.add(table);
      }
      catch (DocumentException de)
      {
         System.err.println(de.getMessage());
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.