Example usage for com.lowagie.text Table deleteAllRows

List of usage examples for com.lowagie.text Table deleteAllRows

Introduction

In this page you can find the example usage for com.lowagie.text Table deleteAllRows.

Prototype

public void deleteAllRows() 

Source Link

Document

Deletes all rows in this table.

Usage

From source file:open.dolphin.client.AuditController.java

License:Open Source License

private void makePDF() {

    //- ?//from www .  ja  va2  s . c o m
    Document doc = new Document(PageSize.A4, 20.0F, 20.0F, 40.0F, 40.0F);

    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName = "_" + sdf.format(new java.util.Date()) + ".pdf";

        //()??
        FileOutputStream fos = new FileOutputStream(outputDir.getText() + fileName);
        PdfWriter pdfwriter = PdfWriter.getInstance(doc, fos);
        Font font_header = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 15.0F, 1);
        Font font_g11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F);
        Font font_g10 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 10.0F);
        //- ?
        Font font_m8 = new Font(BaseFont.createFont("HeiseiMin-W3", "UniJIS-UCS2-HW-H", false), 8.0F);
        Font font_underline_11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F,
                4);
        Font font_red_11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F);
        font_red_11.setColor(new Color(255, 0, 0));
        Font font_empty = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 9.0F);
        font_empty.setColor(new Color(255, 255, 255));

        Paragraph para_NF = new Paragraph(5, "\r\n",
                new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 13, Font.NORMAL));
        para_NF.setAlignment(Element.ALIGN_CENTER);

        // ??
        String author = Project.getProjectStub().getUserModel().getCommonName();
        doc.addAuthor(author);
        doc.addSubject("");

        HeaderFooter header = new HeaderFooter(new Phrase("", font_header),
                false);
        header.setAlignment(1);
        doc.setHeader(header);

        HeaderFooter footer = new HeaderFooter(new Phrase("--"), new Phrase("--"));
        footer.setAlignment(1);
        footer.setBorder(0);
        doc.setFooter(footer);

        doc.open();

        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy''MM''dd'' HH''mm''");
        String today = sdf1.format(new java.util.Date());
        Paragraph para_0 = new Paragraph("?" + today, font_g11);
        para_0.setAlignment(2);
        doc.add(para_0);
        Paragraph para_1 = new Paragraph("?" + author, font_g11);
        para_1.setAlignment(2);
        doc.add(para_1);
        doc.add(new Paragraph(""));
        // 
        doc.add(para_NF);
        doc.add(para_NF);

        for (int cnt = 0; cnt < outputList.size(); cnt++) {

            InnerBean bean = outputList.get(cnt);
            Person person = bean.getPerson();

            Paragraph para_2 = new Paragraph("ID" + person.idProperty().get(), font_underline_11);
            para_2.setAlignment(0);
            doc.add(para_2);
            Paragraph para_3 = new Paragraph("???" + person.nameProperty().get(),
                    font_underline_11);
            para_3.setAlignment(0);
            doc.add(para_3);
            Paragraph para_4 = new Paragraph("" + person.nameKanaProperty().get(),
                    font_underline_11);
            para_4.setAlignment(0);
            doc.add(para_4);
            Paragraph para_5 = new Paragraph("" + person.sexProperty().get(), font_underline_11);
            para_5.setAlignment(0);
            doc.add(para_5);
            Paragraph para_6 = new Paragraph("" + person.birthdayProperty().get(),
                    font_underline_11);
            para_6.setAlignment(0);
            doc.add(para_6);

            Table karteHistoryTable = new Table(5);
            karteHistoryTable.setWidth(100.0F);
            int[] uriage_table_width = { 25, 20, 30, 20, 25 };
            karteHistoryTable.setWidths(uriage_table_width);
            //karteHistoryTable.setDefaultHorizontalAlignment(1);
            //karteHistoryTable.setDefaultVerticalAlignment(5);
            karteHistoryTable.setPadding(3.0F);
            karteHistoryTable.setSpacing(0.0F);
            karteHistoryTable.setBorderColor(new Color(0, 0, 0));

            Cell cell_01 = new Cell(new Phrase("?", font_g10));
            cell_01.setGrayFill(0.8F);
            cell_01.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_11 = new Cell(new Phrase("?", font_g10));
            cell_11.setGrayFill(0.8F);
            cell_11.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_21 = new Cell(new Phrase("", font_g10));
            cell_21.setGrayFill(0.8F);
            cell_21.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_31 = new Cell(new Phrase("", font_g10));
            cell_31.setGrayFill(0.8F);
            cell_31.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_41 = new Cell(new Phrase("", font_g10));
            cell_41.setGrayFill(0.8F);
            cell_41.setHorizontalAlignment(Element.ALIGN_CENTER);

            karteHistoryTable.addCell(cell_01);
            karteHistoryTable.addCell(cell_11);
            karteHistoryTable.addCell(cell_21);
            karteHistoryTable.addCell(cell_31);
            karteHistoryTable.addCell(cell_41);

            List<KarteBean> list = bean.getResult();
            KarteBean karteInfo = list.get(0);
            List<DocInfoModel> docInfoList = karteInfo.getDocInfoList();

            //- ???
            int stepCount = 22;
            int tempCount = 0;
            int pageCount = 0;

            String firstKarteMaker = null;
            String karteMakeDate = null;
            if (docInfoList != null) {
                for (int i = 0; i < docInfoList.size(); ++i) {
                    DocInfoModel docInfo = docInfoList.get(i);
                    Cell cell = new Cell(new Phrase(docInfo.getFirstConfirmDateTime(), font_m8));
                    if (karteMakeDate == null || !karteMakeDate.equals(docInfo.getFirstConfirmDateTime())) {
                        karteMakeDate = docInfo.getFirstConfirmDateTime();
                        firstKarteMaker = docInfo.getPurpose();
                    }
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(firstKarteMaker, font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    //- 
                    String addTitle = docInfo.getTitle();
                    addTitle = addTitle.replace("\r\n", "");
                    addTitle = addTitle.replace("\n", "");
                    cell = new Cell(new Phrase(addTitle, font_m8));
                    cell.setHorizontalAlignment(0);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(docInfo.getPurpose(), font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(docInfo.getConfirmDateTime(), font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);

                    if (stepCount == tempCount) {
                        if (pageCount == 0) {
                            stepCount += 5;
                            pageCount++;
                        }
                        tempCount = 0;
                        doc.add(karteHistoryTable);
                        doc.newPage();
                        karteHistoryTable.deleteAllRows();
                        karteHistoryTable.addCell(cell_01);
                        karteHistoryTable.addCell(cell_11);
                        karteHistoryTable.addCell(cell_21);
                        karteHistoryTable.addCell(cell_31);
                        karteHistoryTable.addCell(cell_41);
                    } else {
                        tempCount++;
                    }
                }

                //                    Cell Empty_Cell = new Cell(new Phrase("empty", font_empty));
                //                    for (int i = docInfoList.size(); i < docInfoList.size() + 4; ++i) {
                //                        for (int j = 0; j < 4; ++j) {
                //                            karteHistoryTable.addCell(Empty_Cell);
                //                        }
                //                    }
                //
                //            Cell cell_goukei = new Cell(new Phrase("?", font_g10));
                //            cell_goukei.setGrayFill(0.8F);
                //            cell_goukei.setColspan(3);
                //            karteHistoryTable.addCell(cell_goukei);
                //            Cell cell_sum = new Cell(new Phrase("136,900", font_m10));
                //            cell_sum.setHorizontalAlignment(2);
                //            karteHistoryTable.addCell(cell_sum);
                doc.add(karteHistoryTable);
                doc.newPage();

            } else {
                // 
                doc.add(para_NF);

                Paragraph noData = new Paragraph("??", font_m8);
                noData.setAlignment(0);
                doc.add(noData);
                doc.newPage();
            }
        }
    } catch (DocumentException | IOException e) {
        Logger.getLogger(AuditController.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        doc.close();
    }
}