public PdfPCell printStrTopLine(
     String text, int colspan, int fontsize, boolean bold, boolean border, int align) {
   try {
     if (text == null) text = "";
     Paragraph p = new Paragraph();
     float padding = 3.0f;
     // set bold feature
     if (bold) {
       p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize, Font.BOLD)));
       padding = 3.0f;
     } else p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize)));
     PdfPCell cell = new PdfPCell(p);
     // set colspan feature
     cell.setColspan(colspan);
     // set alignment feature
     if (align == 0) cell.setHorizontalAlignment(cell.ALIGN_LEFT);
     else if (align == 1) cell.setHorizontalAlignment(cell.ALIGN_CENTER);
     else if (align == 2) cell.setHorizontalAlignment(cell.ALIGN_RIGHT);
     // set border feature
     cell.setBorder(cell.NO_BORDER);
     cell.setBorder(cell.TOP);
     cell.setPaddingBottom(padding);
     return cell;
   } catch (Exception e) {
     return null;
   }
 }
예제 #2
0
  protected void apply(PdfPCell cell, RenderingContext context, PJsonObject params) {
    if (paddingLeft != null) cell.setPaddingLeft(paddingLeft.floatValue());
    if (paddingRight != null) cell.setPaddingRight(paddingRight.floatValue());
    if (paddingTop != null) cell.setPaddingTop(paddingTop.floatValue());
    if (paddingBottom != null) cell.setPaddingBottom(paddingBottom.floatValue());

    if (borderWidthLeft != null) cell.setBorderWidthLeft(borderWidthLeft.floatValue());
    if (borderWidthRight != null) cell.setBorderWidthRight(borderWidthRight.floatValue());
    if (borderWidthTop != null) cell.setBorderWidthTop(borderWidthTop.floatValue());
    if (borderWidthBottom != null) cell.setBorderWidthBottom(borderWidthBottom.floatValue());

    if (getBorderColorLeftVal(context, params) != null)
      cell.setBorderColorLeft(getBorderColorLeftVal(context, params));
    if (getBorderColorRightVal(context, params) != null)
      cell.setBorderColorRight(getBorderColorRightVal(context, params));
    if (getBorderColorTopVal(context, params) != null)
      cell.setBorderColorTop(getBorderColorTopVal(context, params));
    if (getBorderColorBottomVal(context, params) != null)
      cell.setBorderColorBottom(getBorderColorBottomVal(context, params));

    if (getBackgroundColorVal(context, params) != null)
      cell.setBackgroundColor(getBackgroundColorVal(context, params));

    if (align != null) cell.setHorizontalAlignment(align.getCode());
    if (vertAlign != null) cell.setVerticalAlignment(vertAlign.getCode());
  }
예제 #3
0
파일: PDFUtils.java 프로젝트: kakada/dhis2
  public static PdfPCell resetPaddings(
      PdfPCell cell, float top, float bottom, float left, float right) {
    cell.setPaddingTop(top);
    cell.setPaddingBottom(bottom);
    cell.setPaddingLeft(left);
    cell.setPaddingRight(right);

    return cell;
  }
  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   -----------
  }
    public void onStartPage(PdfWriter writer, Document document) {
      try {
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);

        PdfPTable tab1 = new PdfPTable(1);

        // sub table 2
        PdfPTable subtab2 = new PdfPTable(1);
        subtab2.setWidthPercentage(100);
        subtab2.addCell(
            printStr("SINGAPORE CONSULATE-GENERAL HONG KONG", 1, 25, true, PdfPCell.NO_BORDER, 1));
        subtab2.addCell(printStr("Tel:2527 2212", 1, 25, true, PdfPCell.NO_BORDER, 1));
        PdfPCell subcel2 = new PdfPCell(subtab2);
        subcel2.setColspan(1);
        subcel2.setHorizontalAlignment(subcel2.ALIGN_LEFT);
        subcel2.setBorder(subcel2.NO_BORDER);
        subcel2.setPaddingBottom(0.0f);
        tab1.addCell(subcel2);

        float[] widths = {80};
        tab1.setWidths(widths);
        PdfPCell cel1 = new PdfPCell(tab1);
        cel1.setColspan(1);
        cel1.setHorizontalAlignment(cel1.ALIGN_LEFT);
        cel1.setBorder(cel1.NO_BORDER);
        cel1.setPaddingBottom(0.0f);
        cel1.setFixedHeight(120f);
        table.addCell(cel1);
        // col headers
        float[] widths4 = {80};
        table.setWidths(widths4);
        Rectangle page = document.getPageSize();
        table.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
        table.writeSelectedRows(0, -1, 20, page.height() - 20 + table.getTotalHeight() - 90, cb);

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
 public PdfPCell printStrBoldUnderline(String text, int colspan, int fontsize, int align) {
   try {
     Paragraph p = new Paragraph();
     float padding = 3f;
     // set bold feature
     p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize, Font.BOLD)));
     PdfPCell cell = new PdfPCell(p);
     // set colspan feature
     cell.setColspan(colspan);
     // set alignment feature
     if (align == 0) cell.setHorizontalAlignment(cell.ALIGN_LEFT);
     else if (align == 1) cell.setHorizontalAlignment(cell.ALIGN_CENTER);
     else if (align == 2) cell.setHorizontalAlignment(cell.ALIGN_RIGHT);
     // set border feature
     cell.disableBorderSide(cell.LEFT);
     cell.disableBorderSide(cell.RIGHT);
     cell.disableBorderSide(cell.TOP);
     cell.setPaddingBottom(padding);
     return cell;
   } catch (Exception e) {
     return null;
   }
 }
예제 #7
0
 @Override
 public Element getITextElement() {
   PdfPCell cell = new PdfPCell();
   cell.setBorderColorTop(getBorderTopColor());
   cell.setBorderColorBottom(getBorderBottomColor());
   cell.setBorderColorLeft(getBorderLeftColor());
   cell.setBorderColorRight(getBorderRightColor());
   cell.setBorderWidthTop(APdfBuilder.mmToPoints(getBorderTopWidth()));
   cell.setBorderWidthBottom(APdfBuilder.mmToPoints(getBorderBottomWidth()));
   cell.setBorderWidthLeft(APdfBuilder.mmToPoints(getBorderLeftWidth()));
   cell.setBorderWidthRight(APdfBuilder.mmToPoints(getBorderRightWidth()));
   cell.setPadding(0);
   cell.setPaddingTop(APdfBuilder.mmToPoints(getPaddingTop()));
   cell.setPaddingBottom(APdfBuilder.mmToPoints(getPaddingBottom()));
   cell.setPaddingLeft(APdfBuilder.mmToPoints(getPaddingLeft()));
   cell.setPaddingRight(APdfBuilder.mmToPoints(getPaddingRight()));
   cell.setExtraParagraphSpace(0);
   cell.setIndent(0);
   cell.setUseBorderPadding(false);
   cell.setBackgroundColor(getBackgroundColor());
   cell.setColspan(getColspan());
   for (ItextElement element : elements) cell.addElement(element.getITextElement());
   return cell;
 }
예제 #8
0
  public ByteArrayOutputStream create(Info in, Image toplogo) throws Exception {
    DocHelper dh = new DocHelper();
    Document document = new Document(PageSize.LETTER);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    writer.setEncryption(
        PdfWriter.STRENGTH128BITS, "", "3p(0pdf", PdfWriter.AllowCopy | PdfWriter.AllowPrinting);
    // when creating based off this document, cut out from here---------------------

    contract.next();
    float amount = contract.getFloat("amount");
    String job_name = contract.getString("job_name");
    String company = contract.getString("company_name");
    String costCode = contract.getString("division") + " " + contract.getString("cost_code");
    String phaseCode = contract.getString("phase_code");

    float change_order_num = 0;
    int sub_co_number = 0;
    String item_number = "0";
    String co_desc, subject, status;
    float unit_amount = 0, unit_quantity = 0, net_cost = 0;
    float total = 0;
    DecimalFormat df = new DecimalFormat("$###,###,##0.00");
    DecimalFormat codf = new DecimalFormat("0.##");
    SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy");

    // blank spacer for keeping tables apart
    PdfPTable spacer = new PdfPTable(1);
    /*
    spacer.setBorderWidth(0);
    spacer.setDefaultCellBorderWidth(0);
    spacer.setWidth(100);
    spacer.setPadding(0);
    spacer.setSpacing(0);
    */
    PdfPCell blank =
        new PdfPCell(
            new Phrase("", new Font(Font.TIMES_ROMAN, 1, Font.BOLD, new Color(255, 255, 255))));
    blank.setBorderWidth(0);
    // blank.setLeading(0);
    spacer.addCell(blank);

    // start of document
    Phrase p1 =
        new Phrase(
            "Printed: " + sdf.format(new java.util.Date()),
            new Font(Font.TIMES_ROMAN, 8, Font.ITALIC));
    HeaderFooter footer = new HeaderFooter(p1, false);
    footer.setAlignment(Element.ALIGN_CENTER);
    footer.setBorder(Rectangle.NO_BORDER);
    document.setFooter(footer);
    document.open();

    Image blank1_0 = Image.getInstance(in.path + "/jsp/images/blank1_0.jpg");
    blank1_0.scalePercent(60);
    toplogo.scalePercent(20);

    /*
    Table table1=new Table(1,1);
    table1.setBorderWidth(0);
    table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    */

    PdfPTable table1 = new PdfPTable(2);
    // t.setBorder(0);
    // t.setDefaultPdfPCellBorder(0);
    table1.setWidthPercentage(100);

    PdfPCell cell = new PdfPCell(toplogo);
    dh.top(cell);
    cell.setPaddingBottom(4);
    cell.setBorder(0);
    table1.addCell(cell);

    Phrase name = new Phrase(job_name + "\n", dh.font(16));
    name.add(new Phrase("Subcontract CO Report", dh.font(14)));
    cell = new PdfPCell(name);
    dh.middle(cell);
    dh.center(cell);
    cell.setBorder(0);
    table1.addCell(cell);

    document.add(table1);

    table1 = new PdfPTable(1);
    table1.setWidthPercentage(100);

    p1 = new Phrase(costCode + "-" + phaseCode + ": " + company, dh.font(16, Font.BOLD));
    cell = new PdfPCell(p1);
    cell.setUseDescender(true);
    dh.center(cell);
    dh.middle(cell);
    dh.gray(cell);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);
    document.add(spacer);

    // header cells
    table1 = new PdfPTable(5);
    int[] widths1 = {5, 5, 57, 15, 15};
    table1.setWidths(widths1);
    table1.setWidthPercentage(100);

    // data cells
    float grand_total = 0;
    while (item.next()) {
      change_order_num = item.getFloat("change_order_num");
      sub_co_number = item.getInt("sub_co_number");
      co_desc = item.getString("description");
      if (co_desc == null) co_desc = "";
      item_number = item.getString("item_number");
      subject = item.getString("subject");
      if (subject == null) subject = "";
      unit_amount = item.getFloat("unit_amount");
      unit_quantity = item.getFloat("unit_quantity");
      status = item.getString("status");
      // bonds_and_insurance = item.getFloat("bonds_and_insurance");
      // item_tax = item.getFloat("item_tax");
      // epco_markup = item.getFloat("epco_markup");

      net_cost = (unit_amount * unit_quantity);
      if (status.equals("Approved")) {
        total += net_cost;
        grand_total += net_cost;
      }

      // first row
      table1.addCell(blank);

      if (change_order_num == -1) co_desc = "Backcharge";
      if (change_order_num == 0) co_desc = "";
      p1 = new Phrase(Integer.toString(sub_co_number), new Font(Font.TIMES_ROMAN, 8, Font.NORMAL));
      cell = new PdfPCell(p1);
      dh.top(cell);
      cell.setBackgroundColor(new Color(225, 225, 225));
      cell.setBorder(0);
      table1.addCell(cell);

      cell = new PdfPCell(new Phrase(co_desc, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
      cell.setColspan(2);
      dh.top(cell);
      cell.setBackgroundColor(new Color(225, 225, 225));
      cell.setBorder(0);
      table1.addCell(cell);

      cell =
          new PdfPCell(
              new Phrase(
                  "CO# " + codf.format(change_order_num) + "-" + item_number,
                  new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
      dh.top(cell);
      dh.right(cell);
      cell.setBackgroundColor(new Color(225, 225, 225));
      cell.setBorder(0);
      table1.addCell(cell);

      table1.addCell(blank);
      table1.addCell(blank);

      cell = new PdfPCell(new Phrase(subject, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
      dh.top(cell);
      cell.setBorder(0);
      table1.addCell(cell);

      cell =
          new PdfPCell(new Phrase(df.format(net_cost), new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
      dh.right(cell);
      dh.top(cell);
      cell.setBorder(0);
      table1.addCell(cell);

      cell = new PdfPCell(new Phrase(status, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
      dh.right(cell);
      dh.top(cell);
      cell.setBorder(0);
      table1.addCell(cell);
    } // end while
    // Spit out final total row

    document.add(table1);
    document.add(spacer);

    table1 = new PdfPTable(3);
    int[] widths2 = {72, 15, 12};
    table1.setWidths(widths2);
    cell =
        new PdfPCell(
            new Phrase(
                "Total Approved Change Orders:", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    dh.right(cell);
    dh.middle(cell);
    cell.setBorder(0);
    table1.addCell(cell);

    cell =
        new PdfPCell(
            new Phrase(df.format(grand_total), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    dh.right(cell);
    dh.middle(cell);
    cell.setBorder(0);
    table1.addCell(cell);

    table1.addCell(blank);

    cell =
        new PdfPCell(
            new Phrase("Original Contract Amount:", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    dh.right(cell);
    dh.middle(cell);
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(amount), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    dh.right(cell);
    dh.middle(cell);
    cell.setBorder(0);
    table1.addCell(cell);

    table1.addCell(blank);

    cell =
        new PdfPCell(
            new Phrase("Current Approved Total:", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    dh.right(cell);
    dh.middle(cell);
    cell.setBorder(0);
    table1.addCell(cell);

    grand_total += amount;
    cell =
        new PdfPCell(new Phrase(df.format(grand_total), new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    dh.right(cell);
    dh.middle(cell);
    cell.setBorder(0);
    table1.addCell(cell);
    table1.addCell(blank);
    document.add(table1);

    if (contract != null) contract.getStatement().close();
    contract = null;
    if (item != null) item.getStatement().close();
    item = null;
    // -----------------------to here--------------------

    document.close();
    return baos;
  }