コード例 #1
0
ファイル: CellConfig.java プロジェクト: ahennr/mapfish-print
  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());
  }
コード例 #2
0
ファイル: PdfPView.java プロジェクト: mingcheong/SMSS_XJX
  @SuppressWarnings("deprecation")
  public PdfPTable render() {
    PdfPTable pdfpTable = new PdfPTable(getTable().getRow().getColumns().size());
    pdfpTable.setSpacingBefore(3);

    Row row = getTable().getRow();

    List<Column> columns = row.getColumns();

    // build table headers
    for (Iterator<Column> iter = columns.iterator(); iter.hasNext(); ) {
      Column column = iter.next();
      PdfPCell cell = new PdfPCell(new Paragraph(column.getTitle(), getHeaderCellFont()));
      cell.setPadding(3.0f);
      cell.setBackgroundColor(getHeaderBackgroundColor());
      pdfpTable.addCell(cell);
    }

    // build table body
    Collection<?> items = getCoreContext().getPageItems();
    int rowcount = 0;
    for (Object item : items) {
      rowcount++;
      columns = row.getColumns();
      for (Iterator<Column> iter = columns.iterator(); iter.hasNext(); ) {
        Column column = iter.next();
        String property = column.getProperty();
        Object value = column.getCellRenderer().getCellEditor().getValue(item, property, rowcount);
        PdfPCell cell =
            new PdfPCell(new Paragraph(value == null ? "" : String.valueOf(value), getCellFont()));
        cell.setPadding(3.0f);

        if (isRowEven(rowcount)) {
          cell.setBackgroundColor(getEvenCellBackgroundColor());
        } else {
          cell.setBackgroundColor(getOddCellBackgroundColor());
        }

        pdfpTable.addCell(cell);
      }
    }

    return pdfpTable;
  }
コード例 #3
0
  public void geraCabecalhoPDF(
      final int tam,
      final GerencialItemInformationDTO gerencialItemDto,
      final PdfPTable tableParm,
      final PdfWriter writer,
      final Document document,
      final Rectangle page) {
    final PdfPTable table = new PdfPTable(tamTabela);
    table.setWidthPercentage(100);
    try {
      table.setWidths(tamanhoColunasReal);
    } catch (final DocumentException e1) {
      e1.printStackTrace();
    }

    for (int j = 0; j < tam; j++) {
      final PdfPCell cell = new PdfPCell();
      final GerencialFieldDTO fieldDto =
          (GerencialFieldDTO) ((List) gerencialItemDto.getListFields()).get(j);

      final GerencialGroupDTO grupoDefinicaoDto =
          this.fieldInGroupDefinition(fieldDto.getName(), gerencialItemDto.getListGroups());
      if (grupoDefinicaoDto == null) { // So mostra se nao for um agrupador
        if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.String")) {
          table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
          cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        }
        if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.Double")) {
          table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
          cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        }
        if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.Integer")) {
          table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
          cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        }
        if (fieldDto.getClassField().getName().equalsIgnoreCase("java.sql.Date")) {
          table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
          cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        }
        cell.setBackgroundColor(Color.GRAY);
        cell.setPhrase(new Phrase(fieldDto.getTitle()));
        table.addCell(cell);
      }
    }
    final PdfPCell celula0 = new PdfPCell(new Phrase(" "));
    celula0.setColspan(2);
    celula0.setBorder(0);
    tableParm.addCell(celula0);

    final PdfPCell celula = new PdfPCell(table);
    celula.setColspan(2);
    tableParm.addCell(celula);
  }
コード例 #4
0
  protected void insertCell(
      PdfPTable table, String text, int align, int colspan, Font font, int border) {
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
    cell.setHorizontalAlignment(align);
    cell.setColspan(colspan);
    cell.setBorder(border);
    cell.setBorderColor(borderColor);
    cell.setBackgroundColor(backgroundColor);

    if (text.trim().equalsIgnoreCase("")) {
      cell.setMinimumHeight(minimumCellHeight);
    }

    table.addCell(cell);
  }
コード例 #5
0
ファイル: Cell.java プロジェクト: gthiruva/ilarkesto
 @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;
 }
  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);
    }
  }
コード例 #7
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;
  }
コード例 #8
0
ファイル: TemplateImages.java プロジェクト: rototor/itext
  /**
   * PdfTemplates can be wrapped in an Image.
   *
   * @param args no arguments needed
   */
  public static void main(String[] args) {

    System.out.println("PdfTemplate wrapped in an Image");

    // step 1: creation of a document-object
    Rectangle rect = new Rectangle(PageSize.A4);
    rect.setBackgroundColor(new Color(238, 221, 88));
    Document document = new Document(rect, 50, 50, 50, 50);
    try {
      // step 2: we create a writer that listens to the document
      PdfWriter writer =
          PdfWriter.getInstance(document, new FileOutputStream("templateImages.pdf"));
      // step 3: we open the document
      document.open();
      // step 4:
      PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
      BaseFont bf =
          BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
      String text = "Vertical";
      float size = 16;
      float width = bf.getWidthPoint(text, size);
      template.beginText();
      template.setRGBColorFillF(1, 1, 1);
      template.setFontAndSize(bf, size);
      template.setTextMatrix(0, 2);
      template.showText(text);
      template.endText();
      template.setWidth(width);
      template.setHeight(size + 2);
      template.sanityCheck();
      Image img = Image.getInstance(template);
      img.setRotationDegrees(90);
      Chunk ck = new Chunk(img, 0, 0);
      PdfPTable table = new PdfPTable(3);
      table.setWidthPercentage(100);
      table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
      table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
      PdfPCell cell = new PdfPCell(img);
      cell.setPadding(4);
      cell.setBackgroundColor(new Color(0, 0, 255));
      cell.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell("I see a template on my right");
      table.addCell(cell);
      table.addCell("I see a template on my left");
      table.addCell(cell);
      table.addCell("I see a template everywhere");
      table.addCell(cell);
      table.addCell("I see a template on my right");
      table.addCell(cell);
      table.addCell("I see a template on my left");

      Paragraph p1 = new Paragraph("This is a template ");
      p1.add(ck);
      p1.add(" just here.");
      p1.setLeading(img.getScaledHeight() * 1.1f);
      document.add(p1);
      document.add(table);
      Paragraph p2 = new Paragraph("More templates ");
      p2.setLeading(img.getScaledHeight() * 1.1f);
      p2.setAlignment(Element.ALIGN_JUSTIFIED);
      img.scalePercent(70);
      for (int k = 0; k < 20; ++k) p2.add(ck);
      document.add(p2);
      // step 5: we close the document
      document.close();
    } catch (Exception de) {
      System.err.println(de.getMessage());
    }
  }