Package com.lowagie.text

Examples of com.lowagie.text.Table


         document.open();
         // step 4: we create a table and add it to the document

         // example 1

         Table secondTable = new Table(2);
         secondTable.addCell("2nd table 0.0");
         secondTable.addCell("2nd table 0.1");
         secondTable.addCell("2nd table 1.0");
         secondTable.addCell("2nd table 1.1");

         Table aTable = new Table(4, 4);    // 4 rows, 4 columns
         aTable.setAutoFillEmptyCells(true);
         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.insertTable(secondTable, new Point(1, 3));
         document.add(aTable);
         document.add(new Paragraph("converted to PdfPTable:"));
         aTable.setConvert2pdfptable(true);
         document.add(aTable);
         document.newPage();

         // example 2

         Table thirdTable = new Table(2);
         thirdTable.addCell("3rd table 0.0");
         thirdTable.addCell("3rd table 0.1");
         thirdTable.addCell("3rd table 1.0");
         thirdTable.addCell("3rd table 1.1");

         aTable = new Table(5, 5);
         aTable.setAutoFillEmptyCells(true);
         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.insertTable(secondTable, new Point(1, 3));
         aTable.insertTable(thirdTable, new Point(6, 2));
         document.add(aTable);
         document.add(new Paragraph("converted to PdfPTable:"));
         aTable.setConvert2pdfptable(true);
         document.add(aTable);
         document.newPage();

         // example 3
         aTable = new Table(3);
         float[] widths =
         {
            1, 2, 1
         };
         aTable.setWidths(widths);
         aTable.addCell("1.1");
         aTable.addCell("1.2");
         aTable.addCell("1.3");
         // nested
         Table t2 = new Table(2);
         t2.addCell("2.1");
         t2.addCell("2.2");

         // now insert the nested
         aTable.insertTable(t2);
         aTable.addCell("new cell");
         document.add(aTable);
         document.add(new Paragraph("converted to PdfPTable:"));
         aTable.setConvert2pdfptable(true);
         document.add(aTable);
         document.newPage();

         // relative column widths are preserved

         Table a = new Table(2);
         a.setWidths(new float[]
                 {
                    85, 15
                 });
         a.addCell("a-1");
         a.addCell("a-2");

         Table b = new Table(5);
         b.setWidths(new float[]
                 {
                    15, 7, 7, 7, 7
                 });
         b.addCell("b-1");
         b.addCell("b-2");
         b.addCell("b-3");
         b.addCell("b-4");
         b.addCell("b-5");

         // now, insert these 2 tables into a third for layout purposes
         Table c = new Table(3, 1);
         c.setWidth(100.0f);
         c.setWidths(new float[]
                 {
                    20, 2, 78
                 });
         c.insertTable(a, new Point(0, 0));
         c.insertTable(b, new Point(0, 2));

         document.add(c);
         document.add(new Paragraph("converted to PdfPTable:"));
         c.setConvert2pdfptable(true);
         document.add(c);

      }
      catch (DocumentException de)
      {
View Full Code Here


            LwgDocument document = new LwgDocument();
            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(LwgRectangle.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(LwgRectangle.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(LwgRectangle.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(LwgRectangle.RIGHT,
                    RtfBorder.BORDER_DOUBLE_WAVY, 2, Color.GREEN);
            mixedBorders.addBorder(LwgRectangle.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

   * @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

     * 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.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
        tablePDF.setCellsFitPage(true);
        tablePDF.setWidth(100);

        tablePDF.setPadding(2);
View Full Code Here

    theDocument.open();

    theDocument.add(new Phrase(itsTitle, FontFactory.getFont(
        FontFactory.HELVETICA, 24, Font.BOLD)));

    Table aTable = new Table(aWidths.length);
    aTable.setPadding(4);
    aTable.setSpacing(0);
    aTable.setWidths(aWidths);
    aTable.setWidth(100);

    if (itsHeaders != null) {
      aTable.setDefaultRowspan(aWidths.length);
      for (int i = 0 + theSkipLeadingCols; i < itsCols; i++) {
        aTable.addCell(itsHeaders[i].toPDF());
      }
      aTable.endHeaders();
    }

    if (itsData != null || itsDataList != null) {
      aTable.setDefaultCellBorderWidth(0);
      aTable.setDefaultRowspan(1);
      aTable.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
      Iterator aIterator = null;
      if (itsHasList) {
        aIterator = itsDataList.iterator();
      }
      for (int i = 0; i < itsRows; i++) {
        Connlon[] aConnlons = null;
        if (itsHasList) {
          aConnlons = (Connlon[]) aIterator.next();
        } else {
          aConnlons = itsData[i];
        }
        for (int j = 0 + theSkipLeadingCols; j < itsCols; j++) {
          aTable.addCell(aConnlons[j].toPDF());
        }
      }
    }
    theDocument.add(aTable);
    theDocument.close();
View Full Code Here

            RtfCell failedEndConditionC = new RtfCell(uc
                .getUseCaseFailedEndCondition());
            failedEndConditionC.setColspan(3);
            failedEndConditionC.setBorders(normal);

            Table table = new Table(4);
            table.addCell(useCaseID);
            table.addCell(useCaseIDC);
            table.addCell(useCaseName);
            table.addCell(useCaseNameC);
            table.addCell(useCaseDescription);
            table.addCell(useCaseDescriptionC);
            table.addCell(useCasePriority);
            table.addCell(useCasePriorityC);
           
            table.addCell(fireCondition);
            table.addCell(fireConditionC);
            table.addCell(preCondition);
            table.addCell(preConditionC);
            table.addCell(failedEndCondition);
            table.addCell(failedEndConditionC);
            table.addCell(postCondition);
            table.addCell(postConditionC);         
            table.addCell(specialRequirement);
            table.addCell(specialRequirementC);

            // 生成Use Case具体描述的标题

            RtfCell userOperation = new RtfCell("用户操作");
            userOperation.setBorders(normal);

            RtfCell systemOperation = new RtfCell("系统操作");
            systemOperation.setBorders(normal);

            RtfCell systemOutput = new RtfCell("系统输出");
            systemOutput.setBorders(normal);

            Table table2 = new Table(3);
            table2.addCell(userOperation);
            table2.addCell(systemOperation);
            table2.addCell(systemOutput);

            // 生成Use Case具体描述的内容
            ArrayList ucis = new ArrayList();

            UseCaseInteraction uci = new UseCaseInteraction();
            uci.setUseCaseId(uc.getUseCaseId());
            OrderRule orderule = new OrderRule();
            orderule.setOrderColumn("sequence");
            orderule.setOrderDirection(OrderDirection.ASC);
            OrderRule[] orderRules = { orderule };
            String temp;
            ucis = cdp.query(uci, orderRules);
            if (ucis.size() > 0) {
              for (int k = 0; k < ucis.size(); k++) {
                temp = ((UseCaseInteraction) ucis.get(k))
                    .getOperatorAction();
                temp = removeHtml(temp);
                RtfCell userOperationC = new RtfCell(temp);
                userOperationC.setBorders(normal);

                temp = ((UseCaseInteraction) ucis.get(k))
                    .getSystemAction();
                temp = removeHtml(temp);
                RtfCell systemOperationC = new RtfCell(temp);
                systemOperationC.setBorders(normal);

                temp = ((UseCaseInteraction) ucis.get(k))
                    .getSystemOutput();
                temp = removeHtml(temp);
                RtfCell systemOutputC = new RtfCell(temp);
                systemOutputC.setBorders(normal);
                table2.addCell(userOperationC);
                table2.addCell(systemOperationC);
                table2.addCell(systemOutputC);
              }

            } else {

            }
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

            break;
          }
          images.add(png);
        }

        Table table = new Table(images.size());
        for(int i = 0; i < images.size(); i++)
        {
          Image png = (Image)images.get(i);
          if(HORIZONTAL_ORIENTATION.equalsIgnoreCase(orientation))
          {
            Cell pngCell = new Cell(png);
            pngCell.setBorder(0);
            table.setBorder(0);
            table.addCell(pngCell);
          } else
          {
            png.setAlignment(5);
            pdfDocument.add(png);
          }
View Full Code Here

      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.alternatives.MyFirstTable.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("0.0");
      table.addCell("0.1");
      table.addCell("1.0");
      table.addCell("1.1");
      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.addAuthor("Alan Soukup");
            document.addSubject("This is the result of a Test.");
           
            document.open();
           
            Table datatable = new Table(10);
           
            int headerwidths[] = {10, 24, 12, 12, 7, 7, 7, 7, 7, 7};
            datatable.setWidths(headerwidths);
            datatable.setWidth(100);
            datatable.setPadding(3);
           
            // the first cell spans 10 columns
            LwgCell cell = new LwgCell(new LwgPhrase("Administration -System Users Report", FontFactory.getFont(FontFactory.HELVETICA, 24, LwgFont.BOLD)));
            cell.setHorizontalAlignment(LwgElement.ALIGN_CENTER);
            cell.setLeading(30);
            cell.setColspan(10);
            cell.setBorder(LwgRectangle.NO_BORDER);
            cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
            datatable.addCell(cell);
           
            // These cells span 2 rows
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(1);
            datatable.addCell("User Id");
            datatable.addCell("Name\nAddress");
            datatable.addCell("Company");
            datatable.addCell("Department");
            datatable.addCell("Admin");
            datatable.addCell("Data");
            datatable.addCell("Expl");
            datatable.addCell("Prod");
            datatable.addCell("Proj");
            datatable.addCell("Online");
           
            // this is the end of the table header
            datatable.endHeaders();
           
            datatable.getDefaultCell().setBorderWidth(1);
           
            for (int i = 1; i < 30; i++) {
               
                datatable.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_LEFT);
               
                datatable.addCell("myUserId");
                datatable.addCell("Somebody with a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long long name");
                datatable.addCell("No Name Company");
                datatable.addCell("D" + i);
               
                datatable.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_CENTER);
                datatable.addCell("No");
                datatable.addCell("Yes");
                datatable.addCell("No");
                datatable.addCell("Yes");
                datatable.addCell("No");
                datatable.addCell("Yes");
               
            }
            document.add(new Paragraph("com.lowagie.text.Table - Cells split"));
            document.add(datatable);
            document.newPage();
            document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells split\n\n"));
            datatable.setConvert2pdfptable(true);
            document.add(datatable);
            document.newPage();
            document.add(new Paragraph("com.lowagie.text.Table - Cells kept together"));
            datatable.setConvert2pdfptable(false);
            datatable.setCellsFitPage(true);
            document.add(datatable);
            document.newPage();
            document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells kept together\n\n"));
            datatable.setConvert2pdfptable(true);
            document.add(datatable);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
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.