public void getHeaderFooter(Document document) throws JSONException {
    java.awt.Color tColor = new Color(0, 0, 0);
    fontSmallRegular.setColor(tColor);

    java.util.Date dt = new java.util.Date();
    String dformat = "yyyy-MM-d";
    java.text.SimpleDateFormat dtf = new java.text.SimpleDateFormat(dformat);
    String DateStr = dtf.format(dt);

    // -------- header ----------------

    header = new PdfPTable(1);
    PdfPCell headerNotecell = new PdfPCell(new Phrase("Project Summary Report", fontSmallRegular));
    headerNotecell.setBorder(0);
    headerNotecell.setPaddingBottom(4);
    headerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    header.addCell(headerNotecell);

    PdfPCell headerSeparator = new PdfPCell(new Phrase(""));
    headerSeparator.setBorder(PdfPCell.BOX);
    headerSeparator.setPadding(0);
    headerSeparator.setColspan(1);
    header.addCell(headerSeparator);
    // -------- header end ----------------

    // -------- footer  -------------------
    footer = new PdfPTable(3);
    PdfPCell footerSeparator = new PdfPCell(new Phrase(""));
    footerSeparator.setBorder(PdfPCell.BOX);
    footerSeparator.setPadding(0);
    footerSeparator.setColspan(3);
    footer.addCell(footerSeparator);

    PdfPCell emptyCell = new PdfPCell(new Phrase("", fontSmallRegular));
    emptyCell.setBorder(0);
    emptyCell.setColspan(1);
    emptyCell.setHorizontalAlignment(PdfCell.ALIGN_LEFT);
    footer.addCell(emptyCell);

    PdfPCell footerNotecell = new PdfPCell(new Phrase("Project Summary Report", fontSmallRegular));
    footerNotecell.setBorder(0);
    footerNotecell.setColspan(1);
    footerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    footer.addCell(footerNotecell);

    PdfPCell pagerDateCell = new PdfPCell(new Phrase(DateStr, fontSmallRegular));
    pagerDateCell.setBorder(0);
    pagerDateCell.setColspan(1);
    pagerDateCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    footer.addCell(pagerDateCell);

    // -------- footer end   -----------
  }
Ejemplo n.º 2
0
 public CostCalculationMaterial(
     String productNumber,
     String unit,
     BigDecimal productQuantity,
     BigDecimal costForGivenQuantity) {
   this.productNumber = productNumber;
   this.unit = unit;
   this.productQuantity = productQuantity;
   this.costForGivenQuantity = costForGivenQuantity;
   this.totalCost = costForGivenQuantity;
   this.toAdd = BigDecimal.ZERO;
   redFont = new Font(FontUtils.getDejavu(), 7);
   redFont.setColor(Color.RED);
 }
  private static void addTitleSubtitle(Document d) throws DocumentException, JSONException {
    java.awt.Color tColor = new Color(0, 0, 0);
    fontBold.setColor(tColor);
    fontRegular.setColor(tColor);
    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
    java.util.Date today = new java.util.Date();

    table.setWidthPercentage(100);
    table.setSpacingBefore(6);

    // Report Title
    PdfPCell cell = new PdfPCell(new Paragraph("Project Summary", fontBold));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    // Sub-title(s)
    cell = new PdfPCell(new Paragraph("(on comparison with " + baseName + ")", fontRegular));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    // Separator line
    PdfPTable line = new PdfPTable(1);
    line.setWidthPercentage(100);
    PdfPCell cell1 = null;
    cell1 = new PdfPCell(new Paragraph(""));
    cell1.setBorder(PdfPCell.BOTTOM);
    line.addCell(cell1);
    d.add(table);
    d.add(line);
  }
  private void addTable(
      JSONArray store,
      String[] res,
      String[] colIndex,
      String[] colHeader,
      String[] mainHeader,
      String[] val,
      Document document)
      throws JSONException, DocumentException {

    java.awt.Color tColor = new Color(0, 0, 0);
    fontSmallBold.setColor(tColor);
    Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);

    float[] colw = new float[4];
    for (int x = 0; x < 4; x++) {
      colw[x] = 150;
    }
    int col = 0;

    for (int x = 0; x < mainHeader.length; x++) {
      // table start
      PdfPTable table = new PdfPTable(colw);
      table.setTotalWidth(88);
      table.setWidthPercentage(colw, document.getPageSize());
      // table.setSpacingBefore(10);

      PdfPTable mainTable = new PdfPTable(1);
      mainTable.setTotalWidth(90);
      mainTable.setWidthPercentage(100);
      mainTable.setSpacingBefore(20);

      // header cell for mainTable
      PdfPCell headcell = null;
      headcell = new PdfPCell(new Paragraph(mainHeader[x], fontSmallBold));
      headcell.setBackgroundColor(new Color(0xEEEEEE));
      headcell.setPadding(padding);
      mainTable.addCell(headcell);
      document.add(mainTable);

      // header cell added to mainTable
      int row = 3;
      if (x == 0 || x == 4) {
        row = 4;
      } else if (x == 5) {
        row = 0;
      }
      for (; row > 0; row--) {
        for (int y = 1;
            y < colw.length + 1;
            y++) { // for each column add the colHeader and value cell
          if (col != colHeader.length) {
            if (y % 2 != 0) {
              Paragraph p = new Paragraph(colHeader[col], f1);
              if (colHeader[col].contains("Variance")) {
                p = new Paragraph(colHeader[col], fontSmallBold);
              }
              PdfPCell pcell = new PdfPCell(p);
              if (gridBorder) {
                pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
              } else {
                pcell.setBorder(0);
              }
              pcell.setPadding(padding);
              pcell.setBorderColor(new Color(0xF2F2F2));
              pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
              pcell.setVerticalAlignment(Element.ALIGN_CENTER);
              table.addCell(pcell);
            } else {
              Paragraph p;
              p = new Paragraph(val[col], f1);
              if (colHeader[col].contains("Start Variance")
                  || colHeader[col].contains("End Variance")) {
                p = new Paragraph(val[col] + " days", fontSmallBold);
              } else if (colHeader[col].contains("Duration")) {
                if (colHeader[col].contains("Duration Variance"))
                  p = new Paragraph(val[col] + " days", fontSmallBold);
                else p = new Paragraph(val[col] + " days", f1);
              } else if (colHeader[col].contains("Work")) {
                if (colHeader[col].contains("Work Variance"))
                  p = new Paragraph(val[col] + " hrs", fontSmallBold);
                else p = new Paragraph(val[col] + " hrs", f1);
              } else if (colHeader[col].contains("Cost")) {
                if (colHeader[col].contains("Cost Variance"))
                  p = new Paragraph(currSymbol + " " + val[col], fontSmallBold);
                else p = new Paragraph(currSymbol + " " + val[col], f1);
              } else if (colHeader[col].contains("Percent Complete")) {
                p = new Paragraph(val[col] + " %", f1);
              }
              PdfPCell pcell = new PdfPCell(p);
              if (gridBorder) {
                pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
              } else {
                pcell.setBorder(0);
              }
              pcell.setPadding(padding);
              pcell.setBorderColor(new Color(0xF2F2F2));
              pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
              pcell.setVerticalAlignment(Element.ALIGN_CENTER);
              table.addCell(pcell);
              col++;
            }
          }
        }
      }
      if (x == 5) {
        int y = 0;
        row = res.length / 4;
        for (; row > 0; row--) {
          for (int c = 0; c < 2; c++) {
            Paragraph p = new Paragraph(res[y], f1);
            PdfPCell pcell = new PdfPCell(p);
            if (gridBorder) {
              pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
            } else {
              pcell.setBorder(0);
            }
            pcell.setPadding(padding);
            pcell.setBorderColor(new Color(0xF2F2F2));
            pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            pcell.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(pcell);
            p = new Paragraph(res[y + 1], f1);
            pcell = new PdfPCell(p);
            if (gridBorder) {
              pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
            } else {
              pcell.setBorder(0);
            }
            pcell.setPadding(padding);
            pcell.setBorderColor(new Color(0xF2F2F2));
            pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            pcell.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(pcell);
            y += 2;
          }
        }
      }
      document.add(table);
    }
  }
Ejemplo n.º 5
0
  public void onClick$buttonImprimir() {
    String nombrepdf = "";
    try {
      Calendar cal = Calendar.getInstance();
      // lol
      Calendar cal2 = new GregorianCalendar();
      Document document = new Document();
      String nombre =
          ""
              + (cal.getTime().getYear() + 1900)
              + "_"
              + (cal.getTime().getMonth() + 1)
              + "_"
              + cal.getTime().getDate();
      String tipo = "";
      Font miFuente = new Font();
      miFuente.setStyle(Font.BOLD);
      miFuente.setColor(Color.BLUE);
      Font miFuente2 = new Font();
      miFuente2.setStyle(Font.BOLD);
      miFuente2.setColor(Color.RED);
      PdfPTable tabla;
      PdfPCell celda;
      PdfPCell c1;
      ReporteProducto rowlista;
      String dem = "";
      String esp = "";
      if (cmb_demanda.getText().equals("Mayor Demanda")) {
        dem = "mayDemanda";
      } else {
        dem = "menDemanda";
      }

      if (cmb_tipo.getText().equals("General")) {
        esp = dem + "General";
      } else {
        esp = dem + "PorCat";
      }

      if (cmb_tiempo.getText().equals("Por Año")) {
        tipo = esp + "PorAño";
        tabla = new PdfPTable(4);
        celda = new PdfPCell(new Phrase("Año", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Producto", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Categoría", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        for (int i = 0; i < lista.size(); i++) {
          rowlista = lista.get(i);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFinicial()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getProducto()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCategoria()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCantidad()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
        }
      } else {
        if (cmb_tiempo.getText().equals("Por Mes")) {
          tipo = esp + "PorMes";
          tabla = new PdfPTable(5);
          celda = new PdfPCell(new Phrase("Año", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Mes", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Producto", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Categoría", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);

        } else {
          tipo = esp + "PorFecha";
          tabla = new PdfPTable(5);
          celda = new PdfPCell(new Phrase("Fecha Inicial", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Fecha Final", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Producto", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Categoría", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
        }

        for (int i = 0; i < lista.size(); i++) {
          rowlista = lista.get(i);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFinicial()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFfinal()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getProducto()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCategoria()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCantidad()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
        }
      }
      nombrepdf = "ReporteProductos" + tipo + "_" + nombre + ".pdf";
      PdfWriter.getInstance(document, new FileOutputStream(nombrepdf));
      document.open();
      Paragraph Titulo =
          new Paragraph(
              "Reporte "
                  + cmb_tipo.getText()
                  + " de Productos de "
                  + cmb_demanda.getText()
                  + " "
                  + cmb_tiempo.getText(),
              miFuente);
      Titulo.setAlignment(Element.ALIGN_CENTER);
      Paragraph encabezado = new Paragraph("Prueba");
      encabezado.setAlignment(Element.ALIGN_CENTER);
      document.add(Titulo);
      document.add(encabezado);
      document.add(new Paragraph(" "));

      document.add(tabla);
      document.close();
    } catch (Exception e) {

      e.printStackTrace();
    }
    Hashtable h = new Hashtable();
    h.put("File", nombrepdf);
    Executions.getCurrent()
        .createComponents("Modulo_Reportes/Pdf_Viewer.zul", win_reportesproductos, h);
    File filepdf = new File(nombrepdf);
    filepdf.delete();
    /*  try {
    if ((new File(nombrepdf)).exists()) {
    	Process p = Runtime
    	   .getRuntime()
    	   .exec("rundll32 url.dll,FileProtocolHandler "+nombrepdf);
    	p.waitFor();
    	buttonImprimir.setVisible(false);
    } else {
    	alert("File is not exists!");
    }
    alert("Done!");
    	  } catch (Exception ex) {
    ex.printStackTrace();
     }*/
  }