Package com.itextpdf.text.pdf

Examples of com.itextpdf.text.pdf.PdfPTable


    @Override
    protected void buildPlot(BufferedImage image) throws BadElementException, DocumentException, IOException {

        if (image != null) {
            float[] widithPlot = {0.5f, 1.5f};
            PdfPTable tablePlot = new PdfPTable(widithPlot);
            tablePlot.setWidthPercentage(70);
            tablePlot.setHorizontalAlignment(Element.ALIGN_CENTER);
            Chunk plot = new Chunk(this.reportSettingsProperties.loadPlotTitle());
            plot.setFont(new Font(fontMapper.awtToPdf(this.reportSettingsProperties.loadPlotFont())));
            PdfPCell plotTitle = new PdfPCell(new Paragraph(plot));

            plotTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
            plotTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
            tablePlot.addCell(plotTitle);

            Image imagePdf = Image.getInstance(image, null);
            PdfPCell plotCell = new PdfPCell(imagePdf);
            plotCell.setFixedHeight(image.getHeight() + 20);
            plotCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            plotCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            tablePlot.addCell(plotCell);

            this.document.add(tablePlot);
            this.writeEmptyLine();
        }
        this.writeEmptyLine();
View Full Code Here


    private PdfPTable table;
    private String labelValueSeparator;

    public PDFTableWrapper(int noOfColumns) {
        this.table = new PdfPTable(noOfColumns);
        setLabelValueSeparator(LABEL_VAL_SEP);
    }
View Full Code Here

  private void addNotes(final Document document) throws DocumentException {
    progress.setValue(80);
   
    if (Config.getNotes().isEmpty()) return;
   
    final PdfPTable table = new PdfPTable(2);
      final Paragraph note = new Paragraph("Notes", getDefaultBoldFont());
      final Paragraph noteValue = new Paragraph(Config.getNotes(), getDefaultFont());
     
      // no border
      table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
      table.setWidths(new int[] {15, 100});
     
      table.addCell(note);
      table.addCell(noteValue);
     
      table.setHorizontalAlignment(Element.ALIGN_LEFT);
      document.add(new Paragraph("\n"));
      document.add(new LineSeparator(1f, 100f, BaseColor.BLACK, Element.ALIGN_CENTER, 0));
    document.add(table);
    document.add(new Paragraph("\n", getDefaultFont()));
  }
View Full Code Here

    }
  private void addTable(final Document document, final Boolean skipEmptyRecords) throws DocumentException {
    double progressValue = 20;
    progress.setValue((int)progressValue);
    // columns are: date, duration, rate, total, description
    final PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);
        table.setWidths(new int[] {30, 30, 30, 40, 150});
        table.addCell(new Paragraph("Date", getDefaultBoldFont()));
        table.addCell(new Paragraph("Duration (hr)", getDefaultBoldFont()));
        table.addCell(new Paragraph("Rate per Hour", getDefaultBoldFont()));
        table.addCell(new Paragraph("Total", getDefaultBoldFont()));
        table.addCell(new Paragraph("Description", getDefaultBoldFont()));
       
        final double increment = map.size() / 80d;
        double sumDuration=0;
        double sumTotal=0;
        for (final Date d : map.keySet()) {
          progressValue+=increment;
          progress.setValue((int)progressValue);
          if (skipEmptyRecords && map.get(d).isEmpty()) {
            continue;
          }
         
          final PdfPCell dateCell = new PdfPCell(new Paragraph(Util.ReportDateFormat.format(d), getDefaultFont()));
          dateCell.setHorizontalAlignment(Element.ALIGN_CENTER);
          if (!map.get(d).isEmpty()) {
            dateCell.setRowspan(map.get(d).size());
          }
          table.addCell(dateCell);
          double tempSumDuration=0;
          double tempSumTotal=0;
          for (final RecordEntity r : map.get(d)) {
            PdfPCell duration = new PdfPCell(new Paragraph(Util.DecimalFormat.format(r.getDuration()),getDefaultFont()));
            duration.setHorizontalAlignment(Element.ALIGN_RIGHT);
            PdfPCell rate = new PdfPCell(new Paragraph(Util.CurrencyFormat.format(r.getRate()),getDefaultFont()));
            rate.setHorizontalAlignment(Element.ALIGN_RIGHT);
            PdfPCell total = new PdfPCell(new Paragraph(Util.CurrencyFormat.format(r.getDuration()*r.getRate()),getDefaultFont()));
            total.setHorizontalAlignment(Element.ALIGN_RIGHT);
            PdfPCell desc = new PdfPCell(new Paragraph(r.getDescription(),getDefaultFont()));
            desc.setHorizontalAlignment(Element.ALIGN_LEFT);

            tempSumDuration+=r.getDuration();
            tempSumTotal+=(r.getDuration()*r.getRate());
           
            table.addCell(duration);
              table.addCell(rate);
              table.addCell(total);
              table.addCell(desc);
          }
         
          if (map.get(d).isEmpty()) {
              table.addCell(new Paragraph(""));
              table.addCell(new Paragraph(""));
              table.addCell(new Paragraph(""));
              table.addCell(new Paragraph(""));
          } else {
            PdfPCell totalText = new PdfPCell(new Paragraph("Sum",getDefaultBoldFont()));
            totalText.setHorizontalAlignment(Element.ALIGN_LEFT);
            PdfPCell duration = new PdfPCell(new Paragraph(Util.DecimalFormat.format(tempSumDuration),getDefaultBoldFont()));
            duration.setHorizontalAlignment(Element.ALIGN_RIGHT);
            PdfPCell rate = new PdfPCell(new Paragraph("",getDefaultBoldFont()));
            rate.setHorizontalAlignment(Element.ALIGN_RIGHT);
            PdfPCell total = new PdfPCell(new Paragraph(Util.CurrencyFormat.format(tempSumTotal),getDefaultBoldFont()));
            total.setHorizontalAlignment(Element.ALIGN_RIGHT);
            PdfPCell desc = new PdfPCell(new Paragraph("",getDefaultBoldFont()));
            desc.setHorizontalAlignment(Element.ALIGN_LEFT);

            table.addCell(totalText);
            table.addCell(duration);
              table.addCell(rate);
              table.addCell(total);
              table.addCell(desc);
           
              if (!d.equals(end)) {
                  PdfPCell separator = new PdfPCell(new Paragraph("\n\n", getDefaultFont()));
                  separator.setColspan(5);
                  table.addCell(separator);
              }
          }
          sumDuration+=tempSumDuration;
          sumTotal+=tempSumTotal;
         
        }
        // adds total
        PdfPCell totalText = new PdfPCell(new Paragraph("Total",getDefaultBoldFont()));
        totalText.setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell duration = new PdfPCell(new Paragraph(Util.DecimalFormat.format(sumDuration),getDefaultBoldFont()));
        duration.setHorizontalAlignment(Element.ALIGN_RIGHT);
        PdfPCell rate = new PdfPCell(new Paragraph("",getDefaultBoldFont()));
        rate.setHorizontalAlignment(Element.ALIGN_RIGHT);
        PdfPCell total = new PdfPCell(new Paragraph(Util.CurrencyFormat.format(sumTotal),getDefaultBoldFont()));
        total.setHorizontalAlignment(Element.ALIGN_RIGHT);
        PdfPCell desc = new PdfPCell(new Paragraph("",getDefaultBoldFont()));
        desc.setHorizontalAlignment(Element.ALIGN_LEFT);
       
        totalText.setBorder(Rectangle.NO_BORDER);
        duration.setBorder(Rectangle.NO_BORDER);
        rate.setBorder(Rectangle.NO_BORDER);
        total.setBorder(Rectangle.NO_BORDER);
        desc.setBorder(Rectangle.NO_BORDER);
       
        table.addCell(totalText);
        table.addCell(duration);
        table.addCell(rate);
        table.addCell(total);
        table.addCell(desc);
        document.add(table);
    }
View Full Code Here

    from.add(new Chunk("\n"));
      from.add(new Chunk(new LineSeparator(1f, 100f, BaseColor.BLACK, Element.ALIGN_CENTER, 0)));
      from.add(new Chunk("\n\n"));
      document.add(from);
     
      final PdfPTable table = new PdfPTable(2);
      final Paragraph invoice = new Paragraph("Invoice No", getDefaultBoldFont());
      final Paragraph invoiceValue = new Paragraph(this.invoiceNumber, getDefaultFont());
      final Paragraph date = new Paragraph("Date", getDefaultBoldFont());
      final Paragraph dateValue = new Paragraph(Util.ReportDateFormat.format(new Date()), getDefaultFont());
      final Paragraph to = new Paragraph("To", getDefaultBoldFont());
      final Paragraph toValue = new Paragraph(Config.getTo(), getDefaultFont());
     
      // no border
      table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
      table.setWidths(new int[] {15, 100});
     
      table.addCell(invoice);
      table.addCell(invoiceValue);
     
      table.addCell(date);
      table.addCell(dateValue);
     
      table.addCell(to);
      table.addCell(toValue);
     
      table.setHorizontalAlignment(Element.ALIGN_LEFT);
    document.add(table);
    document.add(new Paragraph("\n", getDefaultFont()));
    final String titleStr = "Invoice ("+Util.ReportDateFormat.format(start)+" - "+Util.ReportDateFormat.format(end)+")";
    final Font f = getDefaultBoldFont();
    f.setSize(14);
View Full Code Here

  public void print() {
    Document document = new Document();
        try {
            PdfWriter.getInstance(document,new FileOutputStream("Totaal.pdf"));
            document.open();
            PdfPTable pdfTable = new PdfPTable(table.getColumnCount());
            pdfTable.setLockedWidth(false);
            PdfPCell cell = new PdfPCell();
            Phrase phrase = null;
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell.setBorderWidthLeft(1);
            for(int i=0;i<table.getColumnCount();i++)
            {
                phrase = new Phrase(table.getColumnName(i));
                cell = new PdfPCell(phrase);
                cell.setBackgroundColor(new BaseColor(220, 220, 220));
                pdfTable.addCell(cell);
            }
            for(int i=0;i<table.getRowCount();++i)
            {
                for(int j=0;j<table.getColumnCount();++j)
                {
                    phrase = new Phrase(String.valueOf(table.getValueAt(i, j)));
                    cell = new PdfPCell(phrase);
                    pdfTable.addCell(cell);
                }
            }
            pdfTable.addCell("Totaal");
            pdfTable.addCell("");
            pdfTable.addCell(hoeveel + "");
            pdfTable.addCell("€" + DecimalPlaces.set2decimals(totaal));
            pdfTable.addCell(alBetaald + "");
            pdfTable.addCell("€" + DecimalPlaces.set2decimals(albetaald));
            pdfTable.addCell("€" + DecimalPlaces.set2decimals(subtotaal));
            pdfTable.setHeaderRows(1);
            pdfTable.normalizeHeadersFooters();
            document.add(pdfTable);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return;
View Full Code Here

    }
  }

  public void addTable(Section section, TableInfo tableInfo)
      throws DocumentException {
    PdfPTable t = new PdfPTable(5);
    // 宽度百分比,相对于父容器
    t.setWidthPercentage(98);
    // 各列宽度百分比
    t.setWidths(new int[] { 30, 20, 12, 8, 30 });
    // 上下间隙
    t.setSpacingBefore(25);
    t.setSpacingAfter(25);
    // 设置标题行有几行,跨页时会再生成标题行
    t.setHeaderRows(1);
    /*
     * 如果出现某些行中的文本非常大, 那么iText将按照“行优先”的方式对表格进行分页处理,
     * 所谓“行优先”是说:当遇到无法在当前页显示完整的一行时, 该行将被放到下一页进行显示,而只有当一整业都无法显示完此行时,
     * iText才会将此行拆开显示在两页中。如果不想使用“行优先”的方式,
     * 而是想采用“页优先”方式(保证填满当前页面的前提下,决定是否需要分拆行)显示, 可使用方法setSplitLate(false)。
     */
    t.setSplitLate(true);
    t.setSplitRows(false);
    // 表头
    t.addCell(buildHeaderCell("数据项"));
    t.addCell(buildHeaderCell("字段名"));
    t.addCell(buildHeaderCell("数据类型"));
    t.addCell(buildHeaderCell("填报要求"));
    t.addCell(buildHeaderCell("描述"));

    addColumns(t, tableInfo.getHeaderColumns());
    addColumns(t, tableInfo.getColumns());
    addColumns(t, tableInfo.getFooterColumns());
    section.add(t);
View Full Code Here

        + count + "张业务信息接口表", Fonts.FONT_MAIN_TEXT);
    someSectionText.setSpacingBefore(10);
    someSectionText.setFirstLineIndent(30);
    sTableList.add(someSectionText);
    // 表清单表格
    PdfPTable tTableList = buildTableList(sTableList, biz);
    sTableList.add(tTableList);

    pTableListTitle.setAlignment(Paragraph.ALIGN_LEFT);
  }
View Full Code Here

  }

  public PdfPTable buildTableList(Section parentSection, Biz biz)
      throws DocumentException {
    PdfPTable t = new PdfPTable(3);
    t.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    // 宽度百分比,相对于父容器
    t.setWidthPercentage(98);
    // 各列宽度百分比
    t.setWidths(new int[] { 45, 35, 20 });
    // 上下间隙
    t.setSpacingBefore(25);
    t.setSpacingAfter(25);
    // 设置标题行有几行,跨页时会再生成标题行
    t.setHeaderRows(1);
    /*
     * 如果出现某些行中的文本非常大, 那么iText将按照“行优先”的方式对表格进行分页处理,
     * 所谓“行优先”是说:当遇到无法在当前页显示完整的一行时, 该行将被放到下一页进行显示,而只有当一整业都无法显示完此行时,
     * iText才会将此行拆开显示在两页中。如果不想使用“行优先”的方式,
     * 而是想采用“页优先”方式(保证填满当前页面的前提下,决定是否需要分拆行)显示, 可使用方法setSplitLate(false)。
     */
    t.setSplitLate(true);
    t.setSplitRows(false);
    // 表头
    t.addCell(buildHeaderCell("表中文名"));
    t.addCell(buildHeaderCell("表英文名"));
    t.addCell(buildHeaderCell("表关系"));
    //t.addCell(buildHeaderCell("表描述"));

    // TODO: 第一行不显示,所以填充一行占位!!
    t.addCell(buildCell(""));
    t.addCell(buildCell(""));
    t.addCell(buildCell(""));
    //t.addCell(buildCell(""));

    List<TableTree> tableTrees = biz.getTableTrees();
    addTableTrees(t, tableTrees);

View Full Code Here

     * @return  a PdfPTable
     */
    public PdfPTable createTable() {
      // no rows = simplest table possible
        if (rows.isEmpty())
            return new PdfPTable(1);
        // how many columns?
        int ncol = 0;
        for (PdfPCell pc : rows.get(0)) {
            ncol += pc.getColspan();
        }
        PdfPTable table = new PdfPTable(ncol);
        // table width
        String width = styles.get(HtmlTags.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);
            }
        }
        // horizontal alignment
        String alignment = styles.get(HtmlTags.ALIGN);
        int align = Element.ALIGN_LEFT;
        if (alignment != null) {
          align = HtmlUtilities.alignmentValue(alignment);
        }
        table.setHorizontalAlignment(align);
        // column widths
    try {
      if (colWidths != null)
        table.setWidths(colWidths);
    } catch (Exception e) {
      // fail silently
    }
    // add the cells
        for (List<PdfPCell> col : rows) {
            for (PdfPCell pc : col) {
                table.addCell(pc);
            }
        }
        return table;
    }
View Full Code Here

TOP

Related Classes of com.itextpdf.text.pdf.PdfPTable

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.