private void updateCellStyle(final Cell cell, final CellBackground background) {

    final Color backgroundColor = background.getBackgroundColor();
    if (backgroundColor != null) {
      cell.setBackgroundColor(backgroundColor);
    }
    final BorderEdge top = background.getTop();
    if (BorderEdge.EMPTY.equals(top) == false) {
      cell.setBorderColorTop(top.getColor());
      cell.setBorderWidthTop((float) StrictGeomUtility.toExternalValue(top.getWidth()));
    }

    final BorderEdge left = background.getLeft();
    if (BorderEdge.EMPTY.equals(left) == false) {
      cell.setBorderColorLeft(left.getColor());
      cell.setBorderWidthLeft((float) StrictGeomUtility.toExternalValue(left.getWidth()));
    }

    final BorderEdge bottom = background.getBottom();
    if (BorderEdge.EMPTY.equals(bottom) == false) {
      cell.setBorderColorBottom(bottom.getColor());
      cell.setBorderWidthBottom((float) StrictGeomUtility.toExternalValue(bottom.getWidth()));
    }

    final BorderEdge right = background.getRight();
    if (BorderEdge.EMPTY.equals(right) == false) {
      cell.setBorderColorRight(right.getColor());
      cell.setBorderWidthRight((float) StrictGeomUtility.toExternalValue(right.getWidth()));
    }
  }
Beispiel #2
0
 /**
  * Set all four borders to <code>f</code> width
  *
  * @param f the desired width
  */
 public void setBorderWidth(float f) {
   super.setBorderWidth(f);
   topBorderWidth = f;
   leftBorderWidth = f;
   rightBorderWidth = f;
   bottomBorderWidth = f;
 }
  private void computeCellStyle(final RenderBox content, final Cell cell) {
    final ElementAlignment verticalAlign = content.getNodeLayoutProperties().getVerticalAlignment();
    if (ElementAlignment.BOTTOM.equals(verticalAlign)) {
      cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    } else if (ElementAlignment.MIDDLE.equals(verticalAlign)) {
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    } else {
      cell.setVerticalAlignment(Element.ALIGN_TOP);
    }

    final ElementAlignment textAlign =
        (ElementAlignment) content.getStyleSheet().getStyleProperty(ElementStyleKeys.ALIGNMENT);
    if (ElementAlignment.RIGHT.equals(textAlign)) {
      cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    } else if (ElementAlignment.JUSTIFY.equals(textAlign)) {
      cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    } else if (ElementAlignment.CENTER.equals(textAlign)) {
      cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    }
  }
Beispiel #4
0
 /*
  * (non-Javadoc)
  *
  * @see com.afunms.report.ExportInterface#insertTable(java.util.ArrayList)
  */
 public void insertTable(ArrayList<String[]> tableal) throws Exception {
   // step 3: we open the document
   if (!document.isOpen()) {
     document.open();
   }
   Table pdfTable = new Table(tableal.get(0).length);
   for (int k = 0; k < tableal.size(); k++) {
     String[] row = tableal.get(k);
     for (int j = 0; j < row.length; j++) {
       Cell pdfcell = new Cell();
       if (k == 0) {
         pdfcell.addElement(new Paragraph(row[j], FontChineseTitle));
         pdfcell.setBackgroundColor(Color.gray);
         pdfTable.endHeaders();
       } else {
         pdfcell.addElement(new Paragraph(row[j], FontChineseRow));
         if (k % 2 == 0) {
           pdfcell.setBackgroundColor(Color.LIGHT_GRAY);
         }
       }
       // 合并单元格
       // pdfcell.setColspan(1);
       // pdfcell.setRowspan(1);
       // 对齐方式
       pdfcell.setHorizontalAlignment(Element.ALIGN_CENTER);
       pdfcell.setVerticalAlignment(Element.ALIGN_MIDDLE);
       pdfTable.addCell(pdfcell);
     }
   }
   pdfTable.setWidth(100);
   // 设置表格填距
   pdfTable.setPadding(5);
   pdfTable.setAlignment(Element.ALIGN_CENTER);
   // pdfTable.setTableFitsPage(true);
   document.add(pdfTable);
   // step 5: we close the document
 }
Beispiel #5
0
  /**
   * Shows how a table is split if it doesn't fit the page.
   *
   * @param args no arguments needed
   */
  public static void main(String[] args) {
    System.out.println("table splitting");
    // creation of the document with a certain size and certain margins
    Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50);

    try {
      // creation of the different writers
      PdfWriter.getInstance(document, new FileOutputStream("repeatingtable.pdf"));

      // we add some meta information to the document
      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
      Cell cell =
          new Cell(
              new Phrase(
                  "Administration -System Users Report",
                  FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD)));
      cell.setHorizontalAlignment(Element.ALIGN_CENTER);
      cell.setLeading(30);
      cell.setColspan(10);
      cell.setBorder(Rectangle.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(Element.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(Element.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();
    }

    // we close the document
    document.close();
  }
  /**
   * Imports the Cell properties into the PatchRtfCell
   *
   * @param cell The Cell to import
   */
  private void importCell(Cell cell) {
    this.content = new ArrayList<RtfBasicElement>();

    if (cell == null) {
      this.borders =
          new PatchRtfBorderGroup(
              this.document,
              PatchRtfBorder.CELL_BORDER,
              this.parentRow.getParentTable().getBorders());
      return;
    }

    if (cell instanceof PatchRtfCell) {
      PatchRtfCell rtfCell = (PatchRtfCell) cell;
      this.minimumHeight = rtfCell.minimumHeight;
    }

    this.colspan = cell.getColspan();
    this.rowspan = cell.getRowspan();
    if (cell.getRowspan() > 1) {
      this.mergeType = MERGE_VERT_PARENT;
    }
    if (cell instanceof PatchRtfCell) {
      this.borders =
          new PatchRtfBorderGroup(
              this.document, PatchRtfBorder.CELL_BORDER, ((PatchRtfCell) cell).getBorders());
    } else {
      this.borders =
          new PatchRtfBorderGroup(
              this.document,
              PatchRtfBorder.CELL_BORDER,
              cell.getBorder(),
              cell.getBorderWidth(),
              cell.getBorderColor());
    }
    this.verticalAlignment = cell.getVerticalAlignment();
    if (cell.getBackgroundColor() == null) {
      this.backgroundColor = new RtfColor(this.document, 255, 255, 255);
    } else {
      this.backgroundColor = new RtfColor(this.document, cell.getBackgroundColor());
    }

    this.cellPadding = (int) this.parentRow.getParentTable().getCellPadding();

    Iterator cellIterator = cell.getElements();
    Paragraph container = null;
    while (cellIterator.hasNext()) {
      try {
        Element element = (Element) cellIterator.next();
        // should we wrap it in a paragraph
        if (!(element instanceof Paragraph) && !(element instanceof List)) {
          if (container != null) {
            container.add(element);
          } else {
            container = new Paragraph();
            container.setAlignment(cell.getHorizontalAlignment());
            container.add(element);
          }
        } else {
          if (container != null) {
            RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
            for (int i = 0; i < rtfElements.length; i++) {
              rtfElements[i].setInTable(true);
              this.content.add(rtfElements[i]);
            }
            container = null;
          }
          // if horizontal alignment is undefined overwrite
          // with that of enclosing cell
          if (element instanceof Paragraph
              && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) {
            ((Paragraph) element).setAlignment(cell.getHorizontalAlignment());
          }

          RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(element);
          for (int i = 0; i < rtfElements.length; i++) {
            rtfElements[i].setInTable(true);
            this.content.add(rtfElements[i]);
          }
        }
      } catch (DocumentException de) {
        de.printStackTrace();
      }
    }
    if (container != null) {
      try {
        RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
        for (int i = 0; i < rtfElements.length; i++) {
          rtfElements[i].setInTable(true);
          this.content.add(rtfElements[i]);
        }
      } catch (DocumentException de) {
        de.printStackTrace();
      }
    }
  }
  // utility function to make an item Element.
  private Table makeItemElement(ShoppingCartItemData pItm) throws DocumentException {

    Table itmTbl = new PTable(mColumnCount);
    itmTbl.setWidth(100);
    itmTbl.setWidths(itmColumnWidth);
    itmTbl.getDefaultCell().setBorderColor(java.awt.Color.black);
    itmTbl.getDefaultCell().setVerticalAlignment(Cell.ALIGN_TOP);
    itmTbl.setOffset(0);
    itmTbl.setBorder(Table.NO_BORDER);

    if (!catalogOnly) {
      String t0 = "";
      if (pItm.getIsaInventoryItem()) {
        t0 = "i";
      }

      if (null != mSiteData
          && mSiteData.isAnInventoryAutoOrderItem(pItm.getProduct().getProductId())) {
        t0 += "a";
      }

      Cell tpc0 = new Cell(makePhrase(t0, small, true));
      if (!pItm.getIsaInventoryItem()) {
        tpc0.setBorder(0);
      }
      itmTbl.addCell(tpc0);
    }

    Cell tpc01 = new Cell(makePhrase("", normal, true));
    itmTbl.addCell(tpc01);

    String t = "";
    if (pItm.getProduct().isPackProblemSku()) {
      t += "*";
    }
    if (t.length() > 0) t += " ";
    Cell tpc1 = new Cell(makePhrase(t + pItm.getActualSkuNum(), normal, true));
    itmTbl.addCell(tpc1);

    itmTbl.addCell(makePhrase(pItm.getProduct().getCatalogProductShortDesc(), normal, true));
    if (mShowSize) {
      itmTbl.addCell(makePhrase(pItm.getProduct().getSize(), normal, true));
    }
    // itmTbl.addCell(makePhrase(pItm.getProduct().getPack(), normal, true));
    // itmTbl.addCell(makePhrase(pItm.getProduct().getUom(), normal, true));
    // itmTbl.addCell(makePhrase(pItm.getProduct().getManufacturerName(),normal,true));

    if (mShowPrice) {
      BigDecimal price = new BigDecimal(pItm.getPrice());
      String priceStr = "";
      try {
        priceStr = mFormatter.priceFormatWithoutCurrency(price);
      } catch (Exception exc) {
        exc.printStackTrace();
      }
      Cell pcell = new Cell(makePhrase(priceStr, normal, true));
      pcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
      itmTbl.addCell(pcell);
    }

    if (catalogOnly) {
      if (pItm.getProduct() != null
          && pItm.getProduct().getCatalogDistrMapping() != null
          && Utility.isTrue(pItm.getProduct().getCatalogDistrMapping().getStandardProductList())) {
        String yStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.y", null);
        itmTbl.addCell(makePhrase(yStr, normal, true));
      } else {
        String nStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.n", null);
        itmTbl.addCell(makePhrase(nStr, normal, true));
      }
    }

    if (!catalogOnly) {
      // BigDecimal amount = new BigDecimal(pItm.getAmount());
      itmTbl.addCell(makePhrase("", normal, true));
    }

    return itmTbl;
  }
Beispiel #8
0
  /**
   * Constructs a <CODE>PdfCell</CODE>-object.
   *
   * @param cell the original <CODE>Cell</CODE>
   * @param rownumber the number of the <CODE>Row</CODE> the <CODE>Cell</CODE> was in.
   * @param left the left border of the <CODE>PdfCell</CODE>
   * @param right the right border of the <CODE>PdfCell</CODE>
   * @param top the top border of the <CODE>PdfCell</CODE>
   * @param cellspacing the cellspacing of the <CODE>Table</CODE>
   * @param cellpadding the cellpadding of the <CODE>Table</CODE>
   */
  public PdfCell(
      Cell cell,
      int rownumber,
      float left,
      float right,
      float top,
      float cellspacing,
      float cellpadding) {
    // constructs a Rectangle (the bottomvalue will be changed afterwards)
    super(left, top, right, top);
    // copying the other Rectangle attributes from class Cell
    cloneNonPositionParameters(cell);
    this.cellpadding = cellpadding;
    this.cellspacing = cellspacing;
    this.verticalAlignment = cell.verticalAlignment();
    this.useAscender = cell.isUseAscender();
    this.useDescender = cell.isUseDescender();
    this.useBorderPadding = cell.isUseBorderPadding();

    // initialisation of some parameters
    PdfChunk chunk;
    Element element;
    PdfChunk overflow;
    lines = new ArrayList();
    images = new ArrayList();
    leading = cell.leading();
    int alignment = cell.horizontalAlignment();
    left += cellspacing + cellpadding;
    right -= cellspacing + cellpadding;

    left += getBorderWidthInside(LEFT);
    right -= getBorderWidthInside(RIGHT);

    contentHeight = 0;

    rowspan = cell.rowspan();

    ArrayList allActions;
    int aCounter;
    // we loop over all the elements of the cell
    for (Iterator i = cell.getElements(); i.hasNext(); ) {
      element = (Element) i.next();
      switch (element.type()) {
        case Element.JPEG:
        case Element.IMGRAW:
        case Element.IMGTEMPLATE:
          addImage((Image) element, left, right, 0.4f * leading, alignment); //
          break;
          // if the element is a list
        case Element.LIST:
          if (line != null && line.size() > 0) {
            line.resetAlignment();
            addLine(line);
          }
          allActions = new ArrayList();
          processActions(element, null, allActions);
          aCounter = 0;
          ListItem item;
          // we loop over all the listitems
          for (Iterator items = ((List) element).getItems().iterator(); items.hasNext(); ) {
            item = (ListItem) items.next();
            line = new PdfLine(left + item.indentationLeft(), right, alignment, item.leading());
            line.setListItem(item);
            for (Iterator j = item.getChunks().iterator(); j.hasNext(); ) {
              chunk = new PdfChunk((Chunk) j.next(), (PdfAction) (allActions.get(aCounter++)));
              while ((overflow = line.add(chunk)) != null) {
                addLine(line);
                line = new PdfLine(left + item.indentationLeft(), right, alignment, item.leading());
                chunk = overflow;
              }
              line.resetAlignment();
              addLine(line);
              line = new PdfLine(left + item.indentationLeft(), right, alignment, leading);
            }
          }
          line = new PdfLine(left, right, alignment, leading);
          break;
          // if the element is something else
        default:
          allActions = new ArrayList();
          processActions(element, null, allActions);
          aCounter = 0;

          float currentLineLeading = leading;
          float currentLeft = left;
          float currentRight = right;
          if (element instanceof Phrase) {
            currentLineLeading = ((Phrase) element).leading();
          }
          if (element instanceof Paragraph) {
            Paragraph p = (Paragraph) element;
            currentLeft += p.indentationLeft();
            currentRight -= p.indentationRight();
          }
          if (line == null) {
            line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
          }
          // we loop over the chunks
          ArrayList chunks = element.getChunks();
          if (chunks.isEmpty()) {
            addLine(line); // add empty line - all cells need some lines even if they are empty
            line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
          } else {
            for (Iterator j = chunks.iterator(); j.hasNext(); ) {
              Chunk c = (Chunk) j.next();
              chunk = new PdfChunk(c, (PdfAction) (allActions.get(aCounter++)));
              while ((overflow = line.add(chunk)) != null) {
                addLine(line);
                line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                chunk = overflow;
              }
            }
          }
          // if the element is a paragraph, section or chapter, we reset the alignment and add the
          // line
          switch (element.type()) {
            case Element.PARAGRAPH:
            case Element.SECTION:
            case Element.CHAPTER:
              line.resetAlignment();
              flushCurrentLine();
          }
      }
    }
    flushCurrentLine();
    if (lines.size() > cell.getMaxLines()) {
      while (lines.size() > cell.getMaxLines()) {
        removeLine(lines.size() - 1);
      }
      if (cell.getMaxLines() > 0) {
        String more = cell.getShowTruncation();
        if (more != null && more.length() > 0) {
          // Denote that the content has been truncated
          lastLine = (PdfLine) lines.get(lines.size() - 1);
          if (lastLine.size() >= 0) {
            PdfChunk lastChunk = lastLine.getChunk(lastLine.size() - 1);
            float moreWidth = new PdfChunk(more, lastChunk).width();
            while (lastChunk.toString().length() > 0
                && lastChunk.width() + moreWidth > right - left) {
              // Remove characters to leave room for the 'more' indicator
              lastChunk.setValue(lastChunk.toString().substring(0, lastChunk.length() - 1));
            }
            lastChunk.setValue(lastChunk.toString() + more);
          } else {
            lastLine.add(new PdfChunk(new Chunk(more), null));
          }
        }
      }
    }
    // we set some additional parameters
    if (useDescender && lastLine != null) {
      contentHeight -= lastLine.getDescender();
    }

    // adjust first line height so that it touches the top
    if (lines.size() > 0) {
      firstLine = (PdfLine) lines.get(0);
      float firstLineRealHeight = firstLineRealHeight();
      contentHeight -= firstLine.height();
      firstLine.height = firstLineRealHeight;
      contentHeight += firstLineRealHeight;
    }

    float newBottom = top - contentHeight - (2f * cellpadding()) - (2f * cellspacing());
    newBottom -= getBorderWidthInside(TOP) + getBorderWidthInside(BOTTOM);
    setBottom(newBottom);

    this.rownumber = rownumber;
  }
Beispiel #9
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    WebApplicationContext ctx =
        WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());

    CourseManager manager = (CourseManager) ctx.getBean("courseManager");
    HttpSession session = request.getSession(false);

    List selectFilterCouList = (List) session.getAttribute("selectFilterCouList");

    Date date = new Date();
    DateFormat dateFormat = new SimpleDateFormat("yyyy年 MM月 dd日 HH:mm");

    String stuTmp[] = new String[selectFilterCouList.size()];
    List students = new ArrayList();

    for (int i = 0; i < selectFilterCouList.size(); i++) {
      stuTmp[i] = ((Map) selectFilterCouList.get(i)).get("dtimeOid").toString();
    }
    students = manager.getSeldStuFilterBy(stuTmp, true);

    Document document = new Document(PageSize.A4, 72, 72, 35, 35);
    ByteArrayOutputStream ba = new ByteArrayOutputStream();

    String year = manager.getNowBy("School_year");
    String term = manager.getNowBy("School_term");

    // 如果是下學期, 學年要+1
    if (Integer.parseInt(term) == 2) {
      Integer tmpYear = (Integer.parseInt(year) + 1);
      year = tmpYear.toString();
      term = "1";
    } else {
      term = "2";
    }

    try {

      PdfWriter writer = PdfWriter.getInstance(document, ba);
      // TODO 路徑

      // Image
      // image=Image.getInstance("http://cap.chit.edu.tw/CIS/pages/images/2002chitWatermark.gif");
      // Watermark wamark=new Watermark(image, ((PageSize.A4).width()-image.plainHeight())/2,
      // ((PageSize.A4).height()-image.plainHeight())/2);
      // document.add(wamark);

      Phrase now = doEncode("課程管理系統 " + dateFormat.format(date));
      HeaderFooter header = new HeaderFooter(now, false);
      document.setHeader(header);
      document.setFooter(header);

      // Image logo=Image.getInstance("http://192.192.231.32:8080/CIS/pages/images/art.gif");
      document.open();

      for (int i = 0; i < students.size(); i++) {

        String buf[] = {((Map) students.get(i)).get("student_no").toString()};
        List tmp = manager.getSeldStuFilterBy(buf, false);

        if (i % 2 != 0) {
          document.add(new Paragraph(doEncode("\n")));
          document.add(new Paragraph(doEncode("\n")));
          document.add(new Paragraph(doEncode("\n")));
        }

        document.add(new Paragraph(""));

        Table table = new Table(6);
        table.setWidth(100);

        table.setBorderWidth(0);
        table.setPadding(5);
        // table.setSpacing(5);
        // table.setDefaultHorizontalAlignment(table.ALIGN_CENTER);
        // table.setDefaultHorizontalAlignment(table.ALIGN_MIDDLE);

        // table.setDefaultCellBorderColor(new Color(255, 255, 255));

        Cell cell = new Cell();
        cell.add(doEncode(year));
        cell.add(doEncode("學年 第"));
        cell.add(doEncode(term));
        cell.add(doEncode("學期 網路預選失敗通知單"));
        // cell.addElement(logo);
        cell.setColspan(6);
        cell.setHorizontalAlignment(cell.ALIGN_CENTER);
        cell.setBorderColor(new Color(255, 255, 255));
        table.addCell(cell);

        // ((Map)students.get(i)).get("ClassName2");

        cell = new Cell();
        // cell.add(doEncode("學生班級: "));
        cell.add(doEncode(((Map) students.get(i)).get("ClassName").toString()));
        cell.add(doEncode("\t學號: "));
        cell.add(doEncode(((Map) students.get(i)).get("student_no").toString()));
        cell.add(doEncode("\t姓名: "));
        cell.add(doEncode(((Map) students.get(i)).get("student_name").toString()));

        cell.setColspan(6);
        cell.setHorizontalAlignment(cell.ALIGN_LEFT);
        cell.setBorderColor(new Color(255, 255, 255));
        table.addCell(cell);

        cell = new Cell();
        cell.add(doEncode("您在第一階段網路選課所選的下列課程並未成功,請按照規定時間進行網路第二階段選課,以免影響您的權益。"));

        cell.setColspan(6);
        cell.setHorizontalAlignment(cell.ALIGN_LEFT);
        cell.setBorderColor(new Color(255, 255, 255));
        table.addCell(cell);

        document.add(table);

        float[] widths = {0.2f, 0.3f, 0.1f, 0.1f, 0.1f, 0.2f};
        PdfPTable tables = new PdfPTable(widths);
        tables.setWidthPercentage(100);

        PdfPCell cells = new PdfPCell(doEncode("開課班級"));
        tables.addCell(cells);

        cells = new PdfPCell(doEncode("科目名稱"));
        tables.addCell(cells);
        cells = new PdfPCell(doEncode("選別"));
        tables.addCell(cells);
        cells = new PdfPCell(doEncode("學分"));
        tables.addCell(cells);
        cells = new PdfPCell(doEncode("時數"));
        tables.addCell(cells);
        cells = new PdfPCell(doEncode("上課時間"));
        tables.addCell(cells);

        for (int j = 0; j < tmp.size(); j++) {
          cells = new PdfPCell();
          cells = new PdfPCell(doEncode(((Map) tmp.get(j)).get("ClassName2").toString()));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode(((Map) tmp.get(j)).get("chi_name").toString()));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode(getOpt(((Map) tmp.get(j)).get("opt").toString())));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode(((Map) tmp.get(j)).get("credit").toString()));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode(((Map) tmp.get(j)).get("thour").toString()));
          tables.addCell(cells);

          List dcTmp =
              manager.getDtimeClassListForOpenCourse(((Map) tmp.get(j)).get("dtimeOid").toString());

          StringBuffer strBuf = new StringBuffer();
          DtimeClass dtimeClass;
          for (int x = 0; x < dcTmp.size(); x++) {
            dtimeClass = (DtimeClass) dcTmp.get(x);
            strBuf.append("週" + dtimeClass.getWeek() + ":");
            strBuf.append(dtimeClass.getBegin() + "~" + dtimeClass.getEnd() + " ");
          }

          cells = new PdfPCell(doEncode(strBuf.toString()));
          tables.addCell(cells);
        }

        for (int k = 13; k > tmp.size(); k--) {
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
        }

        document.add(tables);

        if (i % 2 == 1) {
          document.newPage();
        }
      }

    } catch (DocumentException de) {
      de.printStackTrace();
      System.err.println("A Document error:" + de.getMessage());
    }

    document.close();
    response.setContentType("application/pdf");
    response.setContentLength(ba.size());
    ServletOutputStream out = response.getOutputStream();
    ba.writeTo(out);
    ba.close();
    out.flush();
    out.close();
  }
  // int sportId = 1;
  public void SelPlaWD(String filePath, String fileName) {

    SelectPlayerDAO sd = new SelectPlayerDAO();
    // ArrayList departList = new ArrayList();
    ArrayList stuDepartList = new ArrayList();
    ArrayList teaDepartList = new ArrayList();
    // ArrayList selectSportsid=new ArrayList();
    // departList=sd.selectDepartment(sportId);
    // selectSportsid=sd.selectSportsid();

    stuDepartList = sd.slectStuDepidBySid(sportId);
    teaDepartList = sd.selectDepartment(sportId);
    Document document = new Document(PageSize.A4);
    try {
      RtfWriter2.getInstance(document, new FileOutputStream(filePath + fileName));

      document.open();

      for (int i = 0; i < stuDepartList.size(); i++) {

        int id = Integer.parseInt(stuDepartList.get(i).toString());
        // int sid = Integer.parseInt(selectSportsid.get(i).toString());
        ArrayList playBoy = new ArrayList();
        ArrayList playGirl = new ArrayList();
        // ArrayList playTeacher = new ArrayList();
        // int type=sd.selectDepartmentType(id);
        // if(type==1){
        // 查询学生男子组的姓名和号码
        playBoy = sd.selectPlayersByDept(1, id, sportId);
        String groupname = "男子组";
        String departname = sd.selectDepartmentName(id);
        Paragraph p =
            new Paragraph(departname, new Font(Font.BOLD, 18, Font.BOLD, new Color(0, 0, 0)));
        p.setAlignment(1);
        document.add(p);
        // document.add(new Paragraph(groupname));
        Table table = new Table(8);
        Cell cc5 = new Cell(groupname);

        cc5.setColspan(8);
        cc5.setBorderWidth(0);
        table.addCell(cc5);

        // 指定表格为八列

        table.setBorder(0);
        table.setBorderWidth(0);
        table.setBorderColor(Color.WHITE);
        table.setPadding(0);
        table.setSpacing(0);
        for (int a = 0; a < playBoy.size(); a++) {
          PlayerPojo pojp = (PlayerPojo) playBoy.get(a);

          Cell cc = new Cell(pojp.getPlayernum());
          cc.setBorderWidth(0);
          table.addCell(cc);
          Cell ce = new Cell(pojp.getPlayername());
          ce.setBorderWidth(0);
          table.addCell(ce);
        }

        // document.add(p1);
        document.add(table);
        // 查询学生女子组的姓名和号码
        Table table1 = new Table(8);
        // 指定表格为八列
        table1.setBorder(0);
        table1.setBorderWidth(0);
        table1.setBorderColor(Color.WHITE);
        table1.setPadding(0);
        table1.setSpacing(0);
        playGirl = sd.selectPlayersByDept(0, id, sportId);
        String groupname1 = "女子组";
        // document.add(new Paragraph(groupname1));

        Cell cc6 = new Cell(groupname1);
        cc6.setColspan(8);
        cc6.setBorderWidth(0);
        table1.addCell(cc6);

        for (int a = 0; a < playGirl.size(); a++) {
          PlayerPojo pojp = (PlayerPojo) playGirl.get(a);
          Cell cc1 = new Cell(pojp.getPlayernum());
          cc1.setBorderWidth(0);
          table1.addCell(cc1);
          Cell ce1 = new Cell(pojp.getPlayername());
          ce1.setBorderWidth(0);
          table1.addCell(ce1);
        }
        document.add(table1);
        document.add(new Paragraph());
        document.add(new Paragraph());
        // } else{
      }
      for (int i = 0; i < teaDepartList.size(); i++) {
        int id = Integer.parseInt(teaDepartList.get(i).toString());
        ArrayList playTeacher = sd.selectPlayersByDept1(id, sportId);

        String groupname = "教工组";
        String departname = sd.selectDepartmentName(id);
        Paragraph p =
            new Paragraph(departname, new Font(Font.BOLD, 18, Font.BOLD, new Color(0, 0, 0)));
        p.setAlignment(1);
        document.add(p);
        // document.add(new Paragraph(groupname));
        Table table2 = new Table(8);
        Cell cc6 = new Cell(groupname);
        cc6.setColspan(8);
        cc6.setBorderWidth(0);
        table2.addCell(cc6);

        // 指定表格为八列

        table2.setBorder(0);
        table2.setBorderWidth(0);
        table2.setBorderColor(Color.WHITE);
        table2.setPadding(0);
        table2.setSpacing(0);
        for (int a = 0; a < playTeacher.size(); a++) {
          PlayerPojo pojp = (PlayerPojo) playTeacher.get(a);

          Cell cc = new Cell(pojp.getPlayernum());
          cc.setBorderWidth(0);
          table2.addCell(cc);
          Cell ce = new Cell(pojp.getPlayername());
          ce.setBorderWidth(0);
          table2.addCell(ce);
        }
        document.add(table2);
      }

      // 查询教工组的姓名和号码

      // document.add(p1);

      document.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (DocumentException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }