Example usage for com.lowagie.text Document newPage

List of usage examples for com.lowagie.text Document newPage

Introduction

In this page you can find the example usage for com.lowagie.text Document newPage.

Prototype


public boolean newPage() 

Source Link

Document

Signals that an new page has to be started.

Usage

From source file:classroom.filmfestival_b.Movies10.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {

    // step 1//  w  w w .j  a v  a  2s .co  m
    Document document = new Document();
    float middle = (document.right() + document.left()) / 2;
    float columns[][] = { { document.left(), document.bottom(), middle - 12, document.top() },
            { middle + 12, document.bottom(), document.right(), document.top() } };
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();

        ColumnText column = new ColumnText(writer.getDirectContent());
        column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]);

        float pos;
        int status;
        int ccount = 0;
        File f;
        Image img;
        Paragraph p;
        Chunk c;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        for (FilmTitle movie : results) {
            f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
            if (f.exists()) {
                img = Image.getInstance(f.getPath());
                img.setWidthPercentage(0);
                img.scaleToFit(72, 144);
            } else {
                img = null;
            }
            p = new Paragraph(20);
            c = new Chunk(movie.getTitle(), bold);
            c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId());
            p.add(c);
            c = new Chunk(" (" + movie.getYear() + ") ", italic);
            p.add(c);
            c = new Chunk("IMDB");
            c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb());
            p.add(c);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }

            if (img != null)
                column.addElement(img);
            column.addElement(p);
            column.addElement(list);
            pos = column.getYLine();
            status = column.go(true);
            if (ColumnText.hasMoreText(status)) {
                column.setText(null);
                ccount++;
                if (ccount > 1) {
                    ccount = 0;
                    document.newPage();
                    column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]);
                } else {
                    column.setSimpleColumn(columns[1][0], columns[1][1], columns[1][2], columns[1][3]);
                }
            } else {
                column.setYLine(pos);
            }
            if (img != null)
                column.addElement(img);
            column.addElement(p);
            column.addElement(list);
            column.addElement(Chunk.NEWLINE);
            column.go();
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_b.Movies11.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {

    // step 1//from  w  w w. j a v  a  2  s.c  o  m
    Document document = new Document();
    document.setMargins(36, 36, 48, 48);
    float middle = (document.right() + document.left()) / 2;
    float columns[][] = { { document.left(), document.bottom(), middle - 12, document.top() },
            { middle + 12, document.bottom(), document.right(), document.top() } };
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        writer.setPageEvent(new Movies11().new MoviePageEvents(middle, document.top(), document.bottom()));
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();

        ColumnText column = new ColumnText(writer.getDirectContent());
        column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]);

        float pos;
        int status;
        int ccount = 0;
        File f;
        Image img;
        Paragraph p;
        Chunk c;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        for (FilmTitle movie : results) {
            f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
            if (f.exists()) {
                img = Image.getInstance(f.getPath());
                img.setWidthPercentage(0);
                img.scaleToFit(72, 144);
            } else {
                img = null;
            }
            p = new Paragraph(20);
            c = new Chunk(movie.getTitle(), bold);
            c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId());
            p.add(c);
            c = new Chunk(" (" + movie.getYear() + ") ", italic);
            p.add(c);
            c = new Chunk("IMDB");
            c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb());
            p.add(c);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }

            if (img != null)
                column.addElement(img);
            column.addElement(p);
            column.addElement(list);
            pos = column.getYLine();
            status = column.go(true);
            if (ColumnText.hasMoreText(status)) {
                column.setText(null);
                ccount++;
                if (ccount > 1) {
                    ccount = 0;
                    document.newPage();
                    column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]);
                } else {
                    column.setSimpleColumn(columns[1][0], columns[1][1], columns[1][2], columns[1][3]);
                }
            } else {
                column.setYLine(pos);
            }
            if (img != null)
                column.addElement(img);
            column.addElement(p);
            column.addElement(list);
            column.addElement(Chunk.NEWLINE);
            column.go();
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_c.Movies17.java

@SuppressWarnings({ "unchecked", "deprecation" })
public static void main(String[] args) {

    // step 1/*from   w  ww .  j a  va 2s.co m*/
    Document document = new Document();
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter.getInstance(document, os);
        // step 3
        document.open();
        // step 4

        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery(
                "select distinct festival.id.day from FestivalScreening as festival order by festival.id.day");
        java.util.List<Date> days = q.list();

        Query query = session.createQuery("from FestivalScreening where id.day=? order by id.time, id.place");
        for (Date day : days) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(day);
            if (gc.get(GregorianCalendar.YEAR) != YEAR)
                continue;
            document.add(getTable(query, day));
            document.newPage();
        }

        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_c.Movies19.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1/*from  ww w  .  j a v  a2 s .c  o m*/
    Rectangle rect = PageSize.A4.rotate();
    Document document = new Document(rect);
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        Rectangle art = new Rectangle(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        writer.setBoxSize("art", art);
        // step 3
        document.open();
        // step 4

        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery(
                "select distinct festival.id.day from FestivalScreening as festival order by festival.id.day");
        java.util.List<Date> days = q.list();

        for (Date day : days) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(day);
            if (gc.get(GregorianCalendar.YEAR) != YEAR)
                continue;
            createSheet(session, day, writer);
            document.newPage();
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_c.Movies20.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1/*  w  ww .ja  va  2 s.  c o m*/
    Rectangle rect = PageSize.A4.rotate();
    Document document = new Document(rect);
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        Rectangle art = new Rectangle(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        writer.setBoxSize("art", art);
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        // step 3
        document.open();
        // step 4

        PdfOutline root = writer.getDirectContent().getRootOutline();

        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery(
                "select distinct festival.id.day from FestivalScreening as festival order by festival.id.day");
        java.util.List<Date> days = q.list();

        for (Date day : days) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(day);
            if (gc.get(GregorianCalendar.YEAR) != YEAR)
                continue;
            createSheet(session, day, writer);
            new PdfOutline(root, new PdfDestination(PdfDestination.FIT), day.toString());
            document.newPage();
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java

License:Open Source License

public static void printCages(List<Container> cages, boolean printGroupsTreatments, boolean printTreatmentDesc,
        boolean whiteBackground) throws Exception {
    final int margin = 15;
    File f = File.createTempFile("cages__", ".pdf");
    Document doc = new Document(PageSize.A4.rotate());
    Image maleImg, femaleImg, nosexImg;
    try {//from  www .  j  a  va  2  s.c o  m
        maleImg = Image.getInstance(CagePrinterPDF.class.getResource("male.png"));
        femaleImg = Image.getInstance(CagePrinterPDF.class.getResource("female.png"));
        nosexImg = Image.getInstance(CagePrinterPDF.class.getResource("nosex.png"));
    } catch (Exception e) {
        throw new Exception("Could not find images in the classpath: " + e);
    }

    FileOutputStream os = new FileOutputStream(f);
    PdfWriter writer = PdfWriter.getInstance(doc, os);
    doc.open();

    PdfContentByte canvas = writer.getDirectContentUnder();

    float tileW = (doc.getPageSize().getWidth()) / 4;
    float tileH = (doc.getPageSize().getHeight()) / 2;
    for (int i = 0; i < cages.size(); i++) {
        Container cage = cages.get(i);

        Study study = cage.getStudy();
        Set<Group> groups = cage.getGroups();
        Group group = cage.getGroup();
        Set<Biosample> animals = new TreeSet<>(Biosample.COMPARATOR_NAME);
        animals.addAll(cage.getBiosamples());

        //Find the treatments applied to this group
        Set<NamedTreatment> allTreatments = new LinkedHashSet<>();
        for (Group gr : groups) {
            allTreatments.addAll(gr.getAllTreatments(-1));
        }

        //Draw
        if (i % 8 == 0) {
            if (i > 0)
                doc.newPage();
            drawCageSeparation(doc, canvas);
        }

        int col = (i % 8) % 4;
        int row = (i % 8) / 4;

        float x = margin + tileW * col;
        float x2 = x + tileW - margin;
        float baseY = tileH * row;
        float y;

        //Display Sex
        canvas.moveTo(tileW * col - 50, doc.getPageSize().getHeight() - (tileH * row + 50));
        Image img = null;
        String sex = getMetadata(animals, "Sex");
        if (study.isBlindAll()) {
            img = nosexImg;
        } else if (sex.equals("M")) {
            img = maleImg;
        } else if (sex.equals("F")) {
            img = femaleImg;
        } else if (sex.length() > 0) {
            img = nosexImg;
        }
        if (img != null) {
            img.scaleToFit(20, 20);
            img.setAbsolutePosition(tileW * (col + 1) - 33,
                    doc.getPageSize().getHeight() - (tileH * row + 12 + margin));
            doc.add(img);
        }
        if (group != null && group.getColor() != null && (study != null && !study.isBlind())
                && !whiteBackground) {
            Color c = group.getColor();
            canvas.saveState();
            canvas.setRGBColorFill(c.getRed() / 3 + 170, c.getGreen() / 3 + 170, c.getBlue() / 3 + 170);
            canvas.rectangle(x - margin + 1, doc.getPageSize().getHeight() - baseY - tileH + 1, tileW - 2,
                    tileH - 2);
            canvas.fill();
            canvas.restoreState();
        }
        Color treatmentColor = Color.BLACK;
        if (allTreatments.size() > 0 && !study.isBlind() && printGroupsTreatments) {
            int offset = 0;
            for (NamedTreatment t : allTreatments) {
                if (t.getColor() != null) {
                    if (allTreatments.size() == 1)
                        treatmentColor = new Color(t.getColor().getRed() / 2, t.getColor().getGreen() / 2,
                                t.getColor().getBlue() / 2);
                    canvas.saveState();
                    canvas.setColorStroke(Color.BLACK);
                    canvas.setRGBColorFill(t.getColor().getRed(), t.getColor().getGreen(),
                            t.getColor().getBlue());
                    y = baseY + 42 + 15 + 86 + 13 + 22 + 14 + 23 + 28;
                    canvas.rectangle(x + 20 + offset * 5, doc.getPageSize().getHeight() - y - (offset % 2) * 4,
                            22, 22);
                    canvas.fillStroke();
                    canvas.restoreState();
                    offset++;
                }
            }
        }

        canvas.beginText();
        canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false), 16f);
        canvas.showTextAligned(Element.ALIGN_LEFT, cage.getContainerId(), x,
                doc.getPageSize().getHeight() - (baseY + 23), 0);

        canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, "Cp1252", false), 11f);
        y = 42 + baseY;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Type: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 15;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Animals_ID: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 86;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Delivery date: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 13;
        canvas.showTextAligned(Element.ALIGN_LEFT, "PO Number: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 22;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Study: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 14;
        if (study != null && !study.isBlind() && printGroupsTreatments)
            canvas.showTextAligned(Element.ALIGN_LEFT, "Group: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 23;
        if (study != null && !study.isBlind() && printGroupsTreatments)
            canvas.showTextAligned(Element.ALIGN_LEFT, "Treatment: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 50;
        canvas.showTextAligned(Element.ALIGN_LEFT, "License: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 13;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Experimenter: ", x, doc.getPageSize().getHeight() - y, 0);
        canvas.endText();

        y = 42 + baseY;
        print(canvas, study.isBlindAll() ? "Blinded" : getMetadata(animals, "Type"), x + 65,
                doc.getPageSize().getHeight() - y, x2, 11, 11, FontFactory.HELVETICA, Color.BLACK, 11f);
        y += 15;

        if (animals.size() <= 6) {
            int n = 0;
            for (Biosample animal : animals) {
                print(canvas, animal.getSampleId(), x + 75, doc.getPageSize().getHeight() - y - 12 * n, x2 - 50,
                        12, 12, FontFactory.HELVETICA, Color.BLACK, 11f);
                if (animal.getSampleName() != null && animal.getSampleName().length() > 0) {
                    print(canvas, "[ " + animal.getSampleName() + " ]", x2 - 60,
                            doc.getPageSize().getHeight() - y - 12 * n, x2, 12, 12, FontFactory.HELVETICA_BOLD,
                            Color.BLACK, 11f);
                }
                n++;
            }
        } else {
            int nPerRow = animals.size() / 2;
            int n = 0;
            for (Biosample animal : animals) {
                int nx = n / nPerRow;
                int ny = n % nPerRow;
                print(canvas, animal.getSampleId(), x + nx * (x2 - x) / 2,
                        doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12,
                        FontFactory.HELVETICA, Color.BLACK, 10f);
                if (animal.getSampleName() != null && animal.getSampleName().length() > 0) {
                    print(canvas, "[ " + animal.getSampleName() + " ]", x + (1 + nx) * (x2 - x) / 2 - 35,
                            doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12,
                            12, FontFactory.HELVETICA_BOLD, Color.BLACK, 10f);
                }
                n++;
            }
        }

        y += 86;
        print(canvas, getMetadata(animals, "Delivery Date"), x + 75, doc.getPageSize().getHeight() - y, x2, 0,
                10, FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 13;
        print(canvas, getMetadata(animals, "PO Number"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10,
                FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 22;
        print(canvas, study.getStudyIdAndInternalId(), x + 40, doc.getPageSize().getHeight() - y, x2, 0, 11,
                BaseFont.HELVETICA_BOLD, Color.BLACK, 11f);
        y += 14;
        if (!study.isBlind() && printGroupsTreatments)
            print(canvas, getGroups(animals), x + 40, doc.getPageSize().getHeight() - y, x2, 22, 11,
                    BaseFont.HELVETICA_BOLD, Color.BLACK, 11f);
        y += 23;
        if (!study.isBlind() && printGroupsTreatments)
            print(canvas, getTreatments(animals, printTreatmentDesc), x + 62, doc.getPageSize().getHeight() - y,
                    x2, 50, printTreatmentDesc ? 9 : 12, FontFactory.HELVETICA, treatmentColor,
                    printTreatmentDesc ? 9f : 10f);
        y += 50;
        print(canvas, study.getMetadataMap().get("LICENSENO"), x + 74, doc.getPageSize().getHeight() - y, x2,
                15, 10, FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 13;
        print(canvas, study.getMetadataMap().get("EXPERIMENTER"), x + 74, doc.getPageSize().getHeight() - y, x2,
                20, 10, FontFactory.HELVETICA, Color.BLACK, 10f);
    }

    doc.close();
    os.close();
    Desktop.getDesktop().open(f);
    try {
        Thread.sleep(500);
    } catch (Exception e) {
    }

}

From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java

License:Open Source License

public static void convertHSSF2Pdf(Workbook wb, String header, File reportFile) throws Exception {
    assert wb != null;
    assert reportFile != null;

    //Precompute formula
    FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
    for (int i = 0; i < wb.getNumberOfSheets(); i++) {
        Sheet sheet = wb.getSheetAt(i);// w  ww.  j  a v  a2 s .  co m

        for (Row r : sheet) {
            for (Cell c : r) {
                if (c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
                    try {
                        evaluator.evaluateFormulaCell(c);
                    } catch (Exception e) {
                        System.err.println(e);
                    }
                }
            }
        }
    }

    File tmp = File.createTempFile("tmp_", ".xlsx");
    try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp))) {
        wb.write(out);
    }

    //Find page orientation
    int maxColumnsGlobal = 0;
    for (int sheetNo = 0; sheetNo < wb.getNumberOfSheets(); sheetNo++) {
        Sheet sheet = wb.getSheetAt(sheetNo);
        for (Iterator<Row> rowIterator = sheet.iterator(); rowIterator.hasNext();) {
            Row row = rowIterator.next();
            maxColumnsGlobal = Math.max(maxColumnsGlobal, row.getLastCellNum());
        }
    }

    Rectangle pageSize = maxColumnsGlobal < 10 ? PageSize.A4 : PageSize.A4.rotate();
    Document pdfDocument = new Document(pageSize, 10f, 10f, 20f, 20f);

    PdfWriter writer = PdfWriter.getInstance(pdfDocument, new FileOutputStream(reportFile));
    addHeader(writer, header);
    pdfDocument.open();
    //we have two columns in the Excel sheet, so we create a PDF table with two columns
    //Note: There are ways to make this dynamic in nature, if you want to.
    //Loop through sheets
    for (int sheetNo = 0; sheetNo < wb.getNumberOfSheets(); sheetNo++) {
        Sheet sheet = wb.getSheetAt(sheetNo);

        //Loop through rows, to find number of columns
        int minColumns = 1000;
        int maxColumns = 0;
        for (Iterator<Row> rowIterator = sheet.iterator(); rowIterator.hasNext();) {
            Row row = rowIterator.next();
            if (row.getFirstCellNum() >= 0)
                minColumns = Math.min(minColumns, row.getFirstCellNum());
            if (row.getLastCellNum() >= 0)
                maxColumns = Math.max(maxColumns, row.getLastCellNum());
        }
        if (maxColumns == 0)
            continue;

        //Loop through first rows, to find relative width
        float[] widths = new float[maxColumns];
        int totalWidth = 0;
        for (int c = 0; c < maxColumns; c++) {
            int w = sheet.getColumnWidth(c);
            widths[c] = w;
            totalWidth += w;
        }

        for (int c = 0; c < maxColumns; c++) {
            widths[c] /= totalWidth;
        }

        //Create new page and a new chapter with the sheet's name
        if (sheetNo > 0)
            pdfDocument.newPage();
        Chapter pdfSheet = new Chapter(sheet.getSheetName(), sheetNo + 1);

        PdfPTable pdfTable = null;
        PdfPCell pdfCell = null;
        boolean inTable = false;

        //Loop through cells, to create the content
        //         boolean leftBorder = true;
        //         boolean[] topBorder = new boolean[maxColumns+1];
        for (int r = 0; r <= sheet.getLastRowNum(); r++) {
            Row row = sheet.getRow(r);

            //Check if we exited a table (empty line)
            if (row == null) {
                if (pdfTable != null) {
                    addTable(pdfDocument, pdfSheet, totalWidth, widths, pdfTable);
                    pdfTable = null;
                }
                inTable = false;
                continue;
            }

            //Check if we start a table (>MIN_COL_IN_TABLE columns)
            if (row.getLastCellNum() >= MIN_COL_IN_TABLE) {
                inTable = true;
            }

            if (!inTable) {
                //Process the data outside table, just add the text
                boolean hasData = false;
                Iterator<Cell> cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) {
                    Cell cell = cellIterator.next();
                    if (cell.getCellType() == Cell.CELL_TYPE_BLANK)
                        continue;
                    Chunk chunk = getChunk(wb, cell);
                    pdfSheet.add(chunk);
                    pdfSheet.add(new Chunk(" "));
                    hasData = true;
                }
                if (hasData)
                    pdfSheet.add(Chunk.NEWLINE);

            } else {
                //Process the data in table
                if (pdfTable == null) {
                    //Create table
                    pdfTable = new PdfPTable(maxColumns);
                    pdfTable.setWidths(widths);
                    //                  topBorder = new boolean[maxColumns+1];
                }

                int cellNumber = minColumns;
                //               leftBorder = false;
                Iterator<Cell> cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) {

                    Cell cell = cellIterator.next();

                    for (; cellNumber < cell.getColumnIndex(); cellNumber++) {
                        pdfCell = new PdfPCell();
                        pdfCell.setBorder(0);
                        pdfTable.addCell(pdfCell);
                    }

                    Chunk phrase = getChunk(wb, cell);
                    pdfCell = new PdfPCell(new Phrase(phrase));
                    pdfCell.setFixedHeight(row.getHeightInPoints() - 3);
                    pdfCell.setNoWrap(!cell.getCellStyle().getWrapText());
                    pdfCell.setPaddingLeft(1);
                    pdfCell.setHorizontalAlignment(
                            cell.getCellStyle().getAlignment() == CellStyle.ALIGN_CENTER ? PdfPCell.ALIGN_CENTER
                                    : cell.getCellStyle().getAlignment() == CellStyle.ALIGN_RIGHT
                                            ? PdfPCell.ALIGN_RIGHT
                                            : PdfPCell.ALIGN_LEFT);
                    pdfCell.setUseBorderPadding(false);
                    pdfCell.setUseVariableBorders(false);
                    pdfCell.setBorderWidthRight(cell.getCellStyle().getBorderRight() == 0 ? 0 : .5f);
                    pdfCell.setBorderWidthBottom(cell.getCellStyle().getBorderBottom() == 0 ? 0
                            : cell.getCellStyle().getBorderBottom() > 1 ? 1 : .5f);
                    pdfCell.setBorderWidthLeft(cell.getCellStyle().getBorderLeft() == 0 ? 0
                            : cell.getCellStyle().getBorderLeft() > 1 ? 1 : .5f);
                    pdfCell.setBorderWidthTop(cell.getCellStyle().getBorderTop() == 0 ? 0
                            : cell.getCellStyle().getBorderTop() > 1 ? 1 : .5f);
                    String color = cell.getCellStyle().getFillForegroundColorColor() == null ? null
                            : ((XSSFColor) cell.getCellStyle().getFillForegroundColorColor()).getARGBHex();
                    if (color != null)
                        pdfCell.setBackgroundColor(new Color(Integer.decode("0x" + color.substring(2))));
                    pdfTable.addCell(pdfCell);
                    cellNumber++;
                }
                for (; cellNumber < maxColumns; cellNumber++) {
                    pdfCell = new PdfPCell();
                    pdfCell.setBorder(0);
                    pdfTable.addCell(pdfCell);
                }
            }

            //Custom code to add all images on the first sheet (works for reporting)
            if (sheetNo == 0 && row.getRowNum() == 0) {
                for (PictureData pd : wb.getAllPictures()) {
                    try {
                        Image pdfImg = Image.getInstance(pd.getData());
                        pdfImg.scaleToFit(
                                pageSize.getWidth() * .8f - pageSize.getBorderWidthLeft()
                                        - pageSize.getBorderWidthRight(),
                                pageSize.getHeight() * .8f - pageSize.getBorderWidthTop()
                                        - pageSize.getBorderWidthBottom());
                        pdfSheet.add(pdfImg);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        if (pdfTable != null) {
            addTable(pdfDocument, pdfSheet, totalWidth, widths, pdfTable);
        }

        pdfDocument.add(pdfSheet);
    }
    pdfDocument.close();

}

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @author HONGLI db2word/*  w  w w.jav  a2 s . c  om*/
 * @param filename
 * @param type
 * @throws IOException
 */
public void createReport_DB2CldDoc(String filename, String type) throws IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        if ("pdf".equals(type)) {
            PdfWriter.getInstance(document, new FileOutputStream(filename));
        } else {
            RtfWriter2.getInstance(document, new FileOutputStream(filename));
        }
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String typename = (String) reportHash.get("typename");
        String runstr = (String) reportHash.get("runstr");
        String grade = (String) reportHash.get("grade");
        String pingnow = (String) reportHash.get("pingnow");
        String pingmin = (String) reportHash.get("pingmin");
        String pingconavg = (String) reportHash.get("pingconavg");
        DBVo vo = (DBVo) reportHash.get("vo");
        Hashtable conn = (Hashtable) reportHash.get("conn");// 
        if (conn == null)
            conn = new Hashtable();
        Hashtable poolInfo = (Hashtable) reportHash.get("poolInfo");// 
        if (poolInfo == null)
            poolInfo = new Hashtable();
        Hashtable log = (Hashtable) reportHash.get("log");// 
        if (log == null)
            log = new Hashtable();
        Hashtable spaceInfo = (Hashtable) reportHash.get("spaceInfo");// 
        if (spaceInfo == null)
            spaceInfo = new Hashtable();
        String[] sysDbStatus = { "", "", "", "" };
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        // 
        Table dbTable = new Table(5);
        this.setTableFormat(dbTable);
        // float[] cellWidths = { 220f, 220f, 220f, 220f, 220f };
        // dbTable.setWidths(cellWidths);
        // dbTable.setWidth(100); //  90%
        // dbTable.setAlignment(Element.ALIGN_CENTER);// 
        // dbTable.setAutoFillEmptyCells(true); // 
        // dbTable.setBorderWidth(1); // 
        // dbTable.setBorderColor(new Color(0, 125, 255)); // 
        // dbTable.setPadding(2);// 
        // dbTable.setSpacing(0);// 
        // dbTable.setBorder(2);// 
        // dbTable.endHeaders();

        Cell dbCell = null;
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbCell.setColspan(5);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("IP", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(vo.getDbName(), contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(ip, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(typename, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(runstr, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(grade, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);

        Table aTable = new Table(3);
        this.setTableFormat(aTable);
        // float[] widths = { 220f, 220f, 220f };
        // aTable.setWidths(widths);
        // aTable.setWidth(100); //  90%
        // aTable.setAlignment(Element.ALIGN_CENTER);// 
        // aTable.setAutoFillEmptyCells(true); // 
        // aTable.setBorderWidth(1); // 
        // aTable.setBorderColor(new Color(0, 125, 255)); // 
        // aTable.setPadding(2);// 
        // aTable.setSpacing(0);// 
        // aTable.setBorder(2);// 
        // aTable.endHeaders();
        Cell cell = null;
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingnow + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingmin + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingconavg + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);

        // 
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        // img.setAbsolutePosition(0, 0);
        if ("pdf".equals(type)) {
            img.scalePercent(75);
        }
        img.setAlignment(Image.LEFT);// 
        document.add(dbTable);
        document.add(aTable);
        document.add(img);
        document.add(new Paragraph("\n"));

        // 
        Table spaceTable = new Table(5);
        this.setTableFormat(spaceTable);
        // float[] width3 = { 220f, 220f, 220f, 220f, 220f };
        // spaceTable.setWidths(width3);
        // spaceTable.setWidth(100); //  90%
        // spaceTable.setAlignment(Element.ALIGN_CENTER);// 
        // spaceTable.setAutoFillEmptyCells(true); // 
        // spaceTable.setBorderWidth(1); // 
        // spaceTable.setBorderColor(new Color(0, 125, 255)); // 
        // spaceTable.setPadding(2);// 
        // spaceTable.setSpacing(0);// 
        // spaceTable.setBorder(2);// 
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        cell.setColspan(5);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase(" % ", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);

        Iterator iterator = spaceInfo.keySet().iterator();
        while (iterator.hasNext()) {
            String dbName = (String) iterator.next();
            List toolsdb = (ArrayList) spaceInfo.get(dbName);
            if (toolsdb != null && toolsdb.size() > 0) {
                for (int i = 0; i < toolsdb.size(); i++) {
                    Hashtable tempSpace = new Hashtable();
                    tempSpace = (Hashtable) toolsdb.get(i);
                    String tablespace_name = (String) tempSpace.get("tablespace_name");
                    String totalspac = (String) tempSpace.get("totalspac");
                    String usablespac = (String) tempSpace.get("usablespac");
                    String usableper = (String) tempSpace.get("usableper");

                    if (usableper == null || "0".equals(totalspac.trim())) {
                        usableper = "100";
                    }
                    cell = new Cell(new Phrase((i + 1) + "", titleFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase(tablespace_name, titleFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase(totalspac, titleFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase(usablespac, titleFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase(usableper, titleFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                }
            }
        }
        document.add(spaceTable);

        //  
        Table dbInfoTable = new Table(10);
        this.setTableFormat(dbInfoTable);
        // float[] dbInfoWidths = { 220f, 220f, 220f, 220f, 220f, 220f,
        // 220f, 220f, 220f, 220f };
        // dbInfoTable.setWidths(dbInfoWidths);
        // dbInfoTable.setWidth(100); //  90%
        // dbInfoTable.setAlignment(Element.ALIGN_CENTER);// 
        // dbInfoTable.setAutoFillEmptyCells(true); // 
        // dbInfoTable.setBorderWidth(1); // 
        // dbInfoTable.setBorderColor(new Color(0, 125, 255)); // 
        // dbInfoTable.setPadding(2);// 
        // dbInfoTable.setSpacing(0);// 
        // dbInfoTable.setBorder(2);// 
        Hashtable mems = (Hashtable) reportHash.get("mems");//    
        cell = new Cell(new Phrase("   ", titleFont));
        cell.setColspan(10);
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("SQL ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("SQL ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        Enumeration dbs = conn.keys();
        Hashtable<String, Object> allhash = new Hashtable();
        List poolList = new ArrayList();
        while (dbs.hasMoreElements()) {
            String obj = (String) dbs.nextElement();
            List connList = (List) conn.get(obj);

            for (int i = 0; i < connList.size(); i++) {
                Hashtable ht = (Hashtable) connList.get(i);
                String db_name = ht.get("db_name").toString();
                String db_path = ht.get("db_path").toString();
                String db_status = ht.get("db_status").toString();
                String sqlm_elm_last_backup = ht.get("sqlm_elm_last_backup").toString();
                String total_cons = ht.get("total_cons").toString();
                String connections_top = ht.get("connections_top").toString();
                String appls_cur_cons = ht.get("appls_cur_cons").toString();
                String failedsql = ht.get("failedsql").toString();
                String commitsql = ht.get("commitsql").toString();

                cell = new Cell(new Phrase((i + 1) + "", contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(db_name, contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(db_path, contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(sysDbStatus[Integer.parseInt(db_status)], contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(sqlm_elm_last_backup, contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(total_cons, contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(connections_top, contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(appls_cur_cons, contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(failedsql, contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
                cell = new Cell(new Phrase(commitsql, contextFont));
                this.setCellFormat(cell, false);
                dbInfoTable.addCell(cell);
            }
        }
        document.add(dbInfoTable);

        //    
        Table sysInfoTable = new Table(7);
        this.setTableFormat(sysInfoTable);
        // sysInfoTable.setWidth(100); //  90%
        // sysInfoTable.setAlignment(Element.ALIGN_CENTER);// 
        // sysInfoTable.setAutoFillEmptyCells(true); // 
        // sysInfoTable.setBorderWidth(1); // 
        // sysInfoTable.setBorderColor(new Color(0, 125, 255)); // 
        // sysInfoTable.setPadding(2);// 
        // sysInfoTable.setSpacing(0);// 
        // sysInfoTable.setBorder(2);// 
        Hashtable sysValue = (Hashtable) reportHash.get("sysValue");// 
        cell = new Cell(new Phrase("   ", titleFont));
        this.setCellFormat(cell, true);
        cell.setColspan(7);
        sysInfoTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        sysInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        sysInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        sysInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        sysInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        sysInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        sysInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        sysInfoTable.addCell(cell);
        Enumeration dbs2 = poolInfo.keys();
        Hashtable<String, Object> allhash2 = new Hashtable();
        List poolList2 = new ArrayList();
        while (dbs2.hasMoreElements()) {
            String obj = (String) dbs2.nextElement();
            allhash = (Hashtable) poolInfo.get(obj);
            poolList = (List) allhash.get("poolValue");
            List lockList = (List) allhash.get("lockValue");
            List readList = (List) allhash.get("readValue");
            List writeList = (List) allhash.get("writeValue");
            for (int i = 0; i < poolList.size(); i++) {
                Hashtable ht = (Hashtable) poolList.get(i);
                String bp_name = ht.get("bp_name").toString();
                String data_hit_ratio = ht.get("data_hit_ratio").toString();
                String index_hit_ratio = ht.get("index_hit_ratio").toString();
                String BP_hit_ratio = ht.get("BP_hit_ratio").toString();
                String Async_read_pct = ht.get("Async_read_pct").toString();
                String Direct_RW_Ratio = ht.get("Direct_RW_Ratio").toString();

                cell = new Cell(new Phrase((i + 1) + "", contextFont));
                this.setCellFormat(cell, false);
                sysInfoTable.addCell(cell);
                cell = new Cell(new Phrase(bp_name, contextFont));
                this.setCellFormat(cell, false);
                sysInfoTable.addCell(cell);
                cell = new Cell(new Phrase(data_hit_ratio, contextFont));
                this.setCellFormat(cell, false);
                sysInfoTable.addCell(cell);
                cell = new Cell(new Phrase(index_hit_ratio, contextFont));
                this.setCellFormat(cell, false);
                sysInfoTable.addCell(cell);
                cell = new Cell(new Phrase(BP_hit_ratio, contextFont));
                this.setCellFormat(cell, false);
                sysInfoTable.addCell(cell);
                cell = new Cell(new Phrase(Async_read_pct, contextFont));
                this.setCellFormat(cell, false);
                sysInfoTable.addCell(cell);
                cell = new Cell(new Phrase(Direct_RW_Ratio, contextFont));
                this.setCellFormat(cell, false);
                sysInfoTable.addCell(cell);
            }
        }
        document.newPage();
        document.add(sysInfoTable);

        //   
        Table aTable1 = new Table(10);
        this.setTableFormat(aTable1);
        // float[] width = { 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f,
        // 220f, 220f };
        // aTable1.setWidths(width);
        // aTable1.setWidth(100); //  90%
        // aTable1.setAlignment(Element.ALIGN_CENTER);// 
        // aTable1.setAutoFillEmptyCells(true); // 
        // aTable1.setBorderWidth(1); // 
        // aTable1.setBorderColor(new Color(0, 125, 255)); // 
        // aTable1.setPadding(2);// 
        // aTable1.setSpacing(0);// 
        // aTable1.setBorder(2);// 
        cell = new Cell(new Phrase("  ", titleFont));
        cell.setColspan(10);
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        Enumeration dbs3 = poolInfo.keys();
        Hashtable<String, Object> allhash3 = new Hashtable();
        List poolList3 = new ArrayList();
        while (dbs3.hasMoreElements()) {
            String obj = (String) dbs3.nextElement();
            allhash3 = (Hashtable) poolInfo.get(obj);
            poolList3 = (List) allhash3.get("poolValue");
            // System.out.println("poolList size === "+poolList.size());
            List lockList = (List) allhash3.get("lockValue");
            List readList = (List) allhash3.get("readValue");
            List writeList = (List) allhash3.get("writeValue");
            for (int i = 0; i < lockList.size(); i++) {
                Hashtable ht = (Hashtable) lockList.get(i);
                String db_name = ht.get("db_name").toString();
                String rows_read = ht.get("rows_read").toString();
                String rows_selected = ht.get("rows_selected").toString();
                String lock_waits = ht.get("lock_waits").toString();
                String lock_wait_time = ht.get("lock_wait_time").toString();
                String deadlocks = ht.get("deadlocks").toString();
                String lock_escals = ht.get("lock_escals").toString();
                String total_sorts = ht.get("total_sorts").toString();
                String total_sort_time = ht.get("total_sort_time").toString();
                cell = new Cell(new Phrase((i + 1) + ""));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(db_name, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(rows_read, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(rows_selected, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(lock_waits, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(lock_wait_time, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(deadlocks, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(lock_escals, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(total_sorts, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(total_sort_time, contextFont));
                this.setCellFormat(cell, false);
                aTable1.addCell(cell);

            }
        }

        // 
        Table aTable2 = new Table(7);
        this.setTableFormat(aTable2);
        // float[] width2 = { 220f, 220f, 220f, 220f, 220f, 220f, 220f };
        // aTable2.setWidths(width2);
        // aTable2.setWidth(100); //  90%
        // aTable2.setAlignment(Element.ALIGN_CENTER);// 
        // aTable2.setAutoFillEmptyCells(true); // 
        // aTable2.setBorderWidth(1); // 
        // aTable2.setBorderColor(new Color(0, 125, 255)); // 
        // aTable2.setPadding(2);// 
        // aTable2.setSpacing(0);// 
        // aTable2.setBorder(2);// 
        cell = new Cell(new Phrase("   ", titleFont));
        cell.setColspan(7);
        this.setCellFormat(cell, true);
        aTable2.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable2.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        aTable2.addCell(cell);
        cell = new Cell(new Phrase("(Mb)  ", titleFont));
        this.setCellFormat(cell, true);
        aTable2.addCell(cell);
        cell = new Cell(new Phrase("(Mb)   ", titleFont));
        this.setCellFormat(cell, true);
        aTable2.addCell(cell);
        cell = new Cell(new Phrase("(%)  ", titleFont));
        this.setCellFormat(cell, true);
        aTable2.addCell(cell);
        cell = new Cell(new Phrase("(Mb) ", titleFont));
        this.setCellFormat(cell, true);
        aTable2.addCell(cell);
        cell = new Cell(new Phrase("/", titleFont));
        this.setCellFormat(cell, true);
        aTable2.addCell(cell);
        Enumeration dbs4 = log.keys();
        Hashtable<String, Object> allhash4 = new Hashtable();
        List poolList4 = new ArrayList();
        while (dbs4.hasMoreElements()) {
            String obj = (String) dbs4.nextElement();
            List logList = (List) log.get(obj);
            for (int i = 0; i < logList.size(); i++) {
                Hashtable ht = (Hashtable) logList.get(i);
                String logused = ht.get("logused").toString();
                String logspacefree = ht.get("logspacefree").toString();
                String pctused = ht.get("pctused").toString();
                String maxlogused = ht.get("maxlogused").toString();
                String maxsecused = ht.get("maxsecused").toString();
                cell = new Cell(new Phrase((i + 1) + ""));
                this.setCellFormat(cell, false);
                aTable2.addCell(cell);
                cell = new Cell(new Phrase(obj, contextFont));
                this.setCellFormat(cell, false);
                aTable2.addCell(cell);
                cell = new Cell(new Phrase(logused, contextFont));
                this.setCellFormat(cell, false);
                aTable2.addCell(cell);
                cell = new Cell(new Phrase(logspacefree, contextFont));
                this.setCellFormat(cell, false);
                aTable2.addCell(cell);
                cell = new Cell(new Phrase(pctused, contextFont));
                this.setCellFormat(cell, false);
                aTable2.addCell(cell);
                cell = new Cell(new Phrase(maxlogused, contextFont));
                this.setCellFormat(cell, false);
                aTable2.addCell(cell);
                cell = new Cell(new Phrase(maxsecused, contextFont));
                this.setCellFormat(cell, false);
                aTable2.addCell(cell);
            }
        }

        // 
        Table aTable3 = new Table(7);
        this.setTableFormat(aTable3);
        // float[] awidth3 = { 220f, 220f, 220f, 220f, 220f, 220f, 220f };
        // aTable3.setWidths(awidth3);
        // aTable3.setWidth(100); //  90%
        // aTable3.setAlignment(Element.ALIGN_CENTER);// 
        // aTable3.setAutoFillEmptyCells(true); // 
        // aTable3.setBorderWidth(1); // 
        // aTable3.setBorderColor(new Color(0, 125, 255)); // 
        // aTable3.setPadding(2);// 
        // aTable3.setSpacing(0);// 
        // aTable3.setBorder(2);// 
        cell = new Cell(new Phrase("10", titleFont));
        cell.setColspan(7);
        this.setCellFormat(cell, true);
        aTable3.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable3.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        aTable3.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        aTable3.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable3.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable3.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        aTable3.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable3.addCell(cell);
        Enumeration dbs5 = poolInfo.keys();
        Hashtable<String, Object> allhash5 = new Hashtable();
        List poolList5 = new ArrayList();
        String obj = null;
        Hashtable allhash6 = null;
        List lockList = null;
        List readList = null;
        List writeList = null;
        while (dbs5.hasMoreElements()) {
            obj = (String) dbs5.nextElement();
            allhash6 = (Hashtable) poolInfo.get(obj);
            poolList = (List) allhash6.get("poolValue");
            // System.out.println("poolList size === "+poolList.size());
            lockList = (List) allhash6.get("lockValue");
            readList = (List) allhash6.get("readValue");
            writeList = (List) allhash6.get("writeValue");
        }
        if (readList != null && readList.size() > 0) {
            for (int i = 0; i < readList.size(); i++) {
                Hashtable ht = (Hashtable) readList.get(i);
                String tbschema = ht.get("tbschema").toString();
                String tbname = ht.get("tbname").toString();
                String rows_read = ht.get("rows_read").toString();
                String rows_written = ht.get("rows_written").toString();
                String overflow_accesses = ht.get("overflow_accesses").toString();
                String page_reorgs = ht.get("page_reorgs").toString();

                cell = new Cell(new Phrase((i + 1) + "", contextFont));
                this.setCellFormat(cell, false);
                aTable3.addCell(cell);
                cell = new Cell(new Phrase(tbschema, contextFont));
                this.setCellFormat(cell, false);
                aTable3.addCell(cell);
                cell = new Cell(new Phrase(tbname, contextFont));
                this.setCellFormat(cell, false);
                aTable3.addCell(cell);
                cell = new Cell(new Phrase(rows_read, contextFont));
                this.setCellFormat(cell, false);
                aTable3.addCell(cell);
                cell = new Cell(new Phrase(rows_written, contextFont));
                this.setCellFormat(cell, false);
                aTable3.addCell(cell);
                cell = new Cell(new Phrase(overflow_accesses, contextFont));
                this.setCellFormat(cell, false);
                aTable3.addCell(cell);
                cell = new Cell(new Phrase(page_reorgs, contextFont));
                this.setCellFormat(cell, false);
                aTable3.addCell(cell);
            }
        }
        Table aTable4 = new Table(7);
        this.setTableFormat(aTable4);
        // float[] width4 = { 220f, 220f, 220f, 220f, 220f, 220f, 220f };
        // aTable4.setWidths(width4);
        // aTable4.setWidth(100); //  90%
        // aTable4.setAlignment(Element.ALIGN_CENTER);// 
        // aTable4.setAutoFillEmptyCells(true); // 
        // aTable4.setBorderWidth(1); // 
        // aTable4.setBorderColor(new Color(0, 125, 255)); // 
        // aTable4.setPadding(2);// 
        // aTable4.setSpacing(0);// 
        // aTable4.setBorder(2);// 
        cell = new Cell(new Phrase("10", titleFont));
        cell.setColspan(7);
        this.setCellFormat(cell, true);
        aTable4.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable4.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        aTable4.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        aTable4.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable4.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable4.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        aTable4.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        aTable4.addCell(cell);

        if (writeList != null && writeList.size() > 0) {
            for (int i = 0; i < writeList.size(); i++) {
                Hashtable ht = (Hashtable) writeList.get(i);
                String tbschema = ht.get("tbschema").toString();
                String tbname = ht.get("tbname").toString();
                String rows_read = ht.get("rows_read").toString();
                String rows_written = ht.get("rows_written").toString();
                String overflow_accesses = ht.get("overflow_accesses").toString();
                String page_reorgs = ht.get("page_reorgs").toString();

                cell = new Cell(new Phrase((i + 1) + "", contextFont));
                this.setCellFormat(cell, false);
                aTable4.addCell(cell);
                cell = new Cell(new Phrase(tbschema, contextFont));
                this.setCellFormat(cell, false);
                aTable4.addCell(cell);
                cell = new Cell(new Phrase(tbname, contextFont));
                this.setCellFormat(cell, false);
                aTable4.addCell(cell);
                cell = new Cell(new Phrase(rows_read, contextFont));
                this.setCellFormat(cell, false);
                aTable4.addCell(cell);
                cell = new Cell(new Phrase(rows_written, contextFont));
                this.setCellFormat(cell, false);
                aTable4.addCell(cell);
                cell = new Cell(new Phrase(overflow_accesses, contextFont));
                this.setCellFormat(cell, false);
                aTable4.addCell(cell);
                cell = new Cell(new Phrase(page_reorgs, contextFont));
                this.setCellFormat(cell, false);
                aTable4.addCell(cell);
            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            // img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(aTable1);
        document.add(aTable2);
        document.add(aTable3);
        document.add(aTable4);

        //    
        Table evenInfoTable = new Table(2);
        this.setTableFormat(evenInfoTable);
        // float[] evenInfoWidths = { 220f, 220f };
        // evenInfoTable.setWidths(evenInfoWidths);
        // evenInfoTable.setWidth(100); //  90%
        // evenInfoTable.setAlignment(Element.ALIGN_CENTER);// 
        // evenInfoTable.setAutoFillEmptyCells(true); // 
        // evenInfoTable.setBorderWidth(1); // 
        // evenInfoTable.setBorderColor(new Color(0, 125, 255)); // 
        // evenInfoTable.setPadding(2);// 
        // evenInfoTable.setSpacing(0);// 
        // evenInfoTable.setBorder(2);// 
        String downnum = (String) reportHash.get("downnum");
        String count = (Integer) reportHash.get("count") + "";
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(2);
        this.setCellFormat(cell, true);
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase(downnum, contextFont));
        this.setCellFormat(cell, false);
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase(count, contextFont));
        this.setCellFormat(cell, false);
        evenInfoTable.addCell(cell);
        document.newPage();
        document.add(evenInfoTable);
        // 
        addEventListToDoc(document, titleFont, contextFont);

        document.close();
    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @author HONGLI Informixword//  w  ww .  j  a v  a  2s  .  com
 * @param filename
 * @param types
 * @throws IOException
 */
public void createReport_InformixCldDoc(String filename, String types) throws IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        if ("pdf".equals(types)) {
            PdfWriter.getInstance(document, new FileOutputStream(filename));
        } else {
            RtfWriter2.getInstance(document, new FileOutputStream(filename));
        }
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String typename = (String) reportHash.get("typename");
        String runstr = (String) reportHash.get("runstr");
        String grade = (String) reportHash.get("grade");
        String pingnow = (String) reportHash.get("pingnow");
        String pingmin = (String) reportHash.get("pingmin");
        Hashtable dbinfo = new Hashtable();
        dbinfo = (Hashtable) reportHash.get("dbValue");
        String pingconavg = (String) reportHash.get("pingconavg");
        DBVo vo = (DBVo) reportHash.get("vo");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        // 
        Table dbTable = new Table(5);
        this.setTableFormat(dbTable);
        // float[] cellWidths = { 220f, 220f, 220f, 220f, 220f };
        // dbTable.setWidths(cellWidths);
        // dbTable.setWidth(100); //  90%
        // dbTable.setAlignment(Element.ALIGN_CENTER);// 
        // dbTable.setAutoFillEmptyCells(true); // 
        // dbTable.setBorderWidth(1); // 
        // dbTable.setBorderColor(new Color(0, 125, 255)); // 
        // dbTable.setPadding(2);// 
        // dbTable.setSpacing(0);// 
        // dbTable.setBorder(2);// 
        // dbTable.endHeaders();

        Cell dbCell = null;
        dbCell = new Cell(new Phrase("", titleFont));
        dbCell.setColspan(5);
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("IP", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(vo.getDbName(), contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(ip, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(typename, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(runstr, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(grade, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);

        Table aTable = new Table(3);
        // float[] widths = { 220f, 220f, 220f };
        // aTable.setWidths(widths);
        // aTable.setWidth(100); //  90%
        // aTable.setAlignment(Element.ALIGN_CENTER);// 
        // aTable.setAutoFillEmptyCells(true); // 
        // aTable.setBorderWidth(1); // 
        // aTable.setBorderColor(new Color(0, 125, 255)); // 
        // aTable.setPadding(2);// 
        // aTable.setSpacing(0);// 
        // aTable.setBorder(2);// 
        // aTable.endHeaders();
        this.setTableFormat(aTable);
        Cell cell = null;
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingnow + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingmin + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingconavg + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);

        // 
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        // img.setAbsolutePosition(0, 0);
        img.scalePercent(75);
        img.setAlignment(Image.LEFT);// 
        document.add(dbTable);
        document.add(aTable);
        document.add(img);
        document.add(new Paragraph("\n"));

        // Informix
        Table spaceTable = new Table(8);
        this.setTableFormat(spaceTable);
        // float[] width = { 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f
        // };
        // spaceTable.setWidths(width);
        // spaceTable.setWidth(100); //  90%
        // spaceTable.setAlignment(Element.ALIGN_CENTER);// 
        // spaceTable.setAutoFillEmptyCells(true); // 
        // spaceTable.setBorderWidth(1); // 
        // spaceTable.setBorderColor(new Color(0, 125, 255)); // 
        // spaceTable.setPadding(2);// 
        // spaceTable.setSpacing(0);// 
        // spaceTable.setBorder(2);// 
        cell = new Cell(new Phrase("   ", titleFont));
        cell.setColspan(8);
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        spaceTable.addCell(cell);
        // spaceTable.endHeaders();
        ArrayList dbspaces = new ArrayList();
        if (dbinfo != null) {
            dbspaces = (ArrayList) dbinfo.get("informixspaces");// 
        }
        if (dbspaces != null) {
            if (dbspaces.size() > 0) {
                DecimalFormat df = new DecimalFormat("#.###");
                for (int i = 0; i < dbspaces.size(); i++) {
                    Hashtable tablesVO = (Hashtable) dbspaces.get(i);
                    cell = new Cell(new Phrase((i + 1) + ""));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase((String) tablesVO.get("dbspace"), contextFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase((String) tablesVO.get("owner"), contextFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase((String) tablesVO.get("fname"), contextFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase(
                            df.format(Float.parseFloat(tablesVO.get("pages_size") + "")) + "M", contextFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase(
                            df.format(Float.parseFloat(tablesVO.get("pages_used") + "")) + "M", contextFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase(
                            df.format(Float.parseFloat(tablesVO.get("pages_free") + "")) + "M", contextFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);
                    cell = new Cell(new Phrase(
                            df.format(100 - Float.parseFloat(tablesVO.get("percent_free") + "")) + "%",
                            contextFont));
                    this.setCellFormat(cell, false);
                    spaceTable.addCell(cell);

                }
            }
        }
        document.add(spaceTable);
        document.newPage();
        // Informix
        Table hhTable = new Table(8);
        this.setTableFormat(hhTable);
        float[] hhWidth = { 220f, 220f, 220f, 220f, 220f, 440f, 220f, 220f };
        hhTable.setWidths(hhWidth);
        // hhTable.setWidth(100); //  90%
        // hhTable.setAlignment(Element.ALIGN_CENTER);// 
        // hhTable.setAutoFillEmptyCells(true); // 
        // hhTable.setBorderWidth(1); // 
        // hhTable.setBorderColor(new Color(0, 125, 255)); // 
        // hhTable.setPadding(2);// 
        // hhTable.setSpacing(0);// 
        // hhTable.setBorder(2);// 
        cell = new Cell(new Phrase("   ", titleFont));
        cell.setColspan(8);
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        hhTable.addCell(cell);
        // hhTable.endHeaders();
        List dbsession = (ArrayList) dbinfo.get("sessionList");// 
        if (dbsession != null && dbsession.size() > 0) {
            for (int i = 0; i < dbsession.size(); i++) {
                Hashtable tablesVO = (Hashtable) dbsession.get(i);
                String seqscans = String.valueOf(tablesVO.get("seqscans"));
                if ("null".equals(seqscans)) {
                    seqscans = "";
                }
                String total_sorts = String.valueOf(tablesVO.get("total_sorts"));
                if ("null".equals(total_sorts)) {
                    total_sorts = "";
                }
                String dsksorts = String.valueOf(tablesVO.get("dsksorts"));
                if ("null".equals(dsksorts)) {
                    dsksorts = "";
                }
                cell = new Cell(new Phrase((i + 1) + ""));
                this.setCellFormat(cell, false);
                hhTable.addCell(cell);
                cell = new Cell(new Phrase((String) tablesVO.get("username"), contextFont));
                this.setCellFormat(cell, false);
                hhTable.addCell(cell);
                cell = new Cell(new Phrase((String) tablesVO.get("hostname"), contextFont));
                this.setCellFormat(cell, false);
                hhTable.addCell(cell);
                cell = new Cell(new Phrase(tablesVO.get("access") + "", contextFont));
                this.setCellFormat(cell, false);
                hhTable.addCell(cell);
                cell = new Cell(new Phrase(tablesVO.get("locksheld") + "", contextFont));
                this.setCellFormat(cell, false);
                hhTable.addCell(cell);
                cell = new Cell(new Phrase(seqscans, contextFont));
                this.setCellFormat(cell, false);
                hhTable.addCell(cell);
                cell = new Cell(new Phrase(total_sorts, contextFont));
                this.setCellFormat(cell, false);
                hhTable.addCell(cell);
                cell = new Cell(new Phrase(dsksorts, contextFont));
                this.setCellFormat(cell, false);
                hhTable.addCell(cell);
            }
        }

        document.add(hhTable);

        // Informix
        Table lockTable = new Table(6);
        // float[] lockWidth = { 220f, 220f, 220f, 220f, 220f, 220f };
        // lockTable.setWidths(lockWidth);
        // lockTable.setWidth(100); //  90%
        // lockTable.setAlignment(Element.ALIGN_CENTER);// 
        // lockTable.setAutoFillEmptyCells(true); // 
        // lockTable.setBorderWidth(1); // 
        // lockTable.setBorderColor(new Color(0, 125, 255)); // 
        // lockTable.setPadding(2);// 
        // lockTable.setSpacing(0);// 
        // lockTable.setBorder(2);// 
        this.setTableFormat(lockTable);
        cell = new Cell(new Phrase(" ", titleFont));
        cell.setColspan(6);
        this.setCellFormat(cell, true);
        lockTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        lockTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        lockTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        lockTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        lockTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        lockTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        lockTable.addCell(cell);
        // lockTable.endHeaders();
        List dblock = (ArrayList) dbinfo.get("lockList");// 
        if (dblock != null && dblock.size() > 0) {
            for (int i = 0; i < dblock.size(); i++) {
                Hashtable tablesVO = (Hashtable) dblock.get(i);
                String type = (String) tablesVO.get("type");
                String desc = "";
                if ("B".equals(type)) {
                    desc = "";
                } else if ("IS".equals(type)) {
                    desc = "";
                } else if ("S".equals(type)) {
                    desc = "";
                } else if ("XS".equals(type)) {
                    desc = "";
                } else if ("U".equals(type)) {
                    desc = "";
                } else if ("IX".equals(type)) {
                    desc = "";
                } else if ("SIX".equals(type)) {
                    desc = "";
                } else if ("X".equals(type)) {
                    desc = "";
                } else if ("XR".equals(type)) {
                    desc = "";
                }
                cell = new Cell(new Phrase((i + 1) + ""));
                this.setCellFormat(cell, false);
                lockTable.addCell(cell);
                cell = new Cell(new Phrase((String) tablesVO.get("username"), contextFont));
                this.setCellFormat(cell, false);
                lockTable.addCell(cell);
                cell = new Cell(new Phrase((String) tablesVO.get("hostname"), contextFont));
                this.setCellFormat(cell, false);
                lockTable.addCell(cell);
                cell = new Cell(new Phrase((String) tablesVO.get("dbsname"), contextFont));
                this.setCellFormat(cell, false);
                lockTable.addCell(cell);
                cell = new Cell(new Phrase((String) tablesVO.get("tabname"), contextFont));
                this.setCellFormat(cell, false);
                lockTable.addCell(cell);
                cell = new Cell(new Phrase(desc, contextFont));
                this.setCellFormat(cell, false);
                lockTable.addCell(cell);
            }
        }
        document.add(lockTable);

        // Informix
        Table logTable = new Table(9);
        this.setTableFormat(logTable);
        // float[] logWidth = { 220f, 220f, 220f, 220f, 220f, 220f, 220f,
        // 220f, 220f };
        // logTable.setWidths(logWidth);
        // logTable.setWidth(100); //  90%
        // logTable.setAlignment(Element.ALIGN_CENTER);// 
        // logTable.setAutoFillEmptyCells(true); // 
        // logTable.setBorderWidth(1); // 
        // logTable.setBorderColor(new Color(0, 125, 255)); // 
        // logTable.setPadding(2);// 
        // logTable.setSpacing(0);// 
        // logTable.setBorder(2);// 
        cell = new Cell(new Phrase(" ", titleFont));
        cell.setColspan(9);
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase("ID   ", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        logTable.addCell(cell);
        // logTable.endHeaders();
        List dblog = (ArrayList) dbinfo.get("informixlog");// 
        if (dblog != null && dblog.size() > 0) {
            for (int i = 0; i < dblog.size(); i++) {
                Hashtable tablesVO = (Hashtable) dblog.get(i);
                cell = new Cell(new Phrase((i + 1) + ""));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("uniqid")), contextFont));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("size")), contextFont));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("used")), contextFont));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("is_used")), contextFont));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("is_current")), contextFont));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("is_backed_up")), contextFont));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("is_archived")), contextFont));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("is_temp")), contextFont));
                this.setCellFormat(cell, false);
                logTable.addCell(cell);
            }
        }
        document.add(logTable);

        // InformixIO
        Table ioTable = new Table(10);
        this.setTableFormat(ioTable);
        // float[] ioWidth = { 220f, 220f, 220f, 220f, 220f, 220f, 220f,
        // 220f, 220f, 220f };
        // ioTable.setWidths(ioWidth);
        // ioTable.setWidth(100); //  90%
        // ioTable.setAlignment(Element.ALIGN_CENTER);// 
        // ioTable.setAutoFillEmptyCells(true); // 
        // ioTable.setBorderWidth(1); // 
        // ioTable.setBorderColor(new Color(0, 125, 255)); // 
        // ioTable.setPadding(2);// 
        // ioTable.setSpacing(0);// 
        // ioTable.setBorder(2);// 
        cell = new Cell(new Phrase("IO ", titleFont));
        cell.setColspan(10);
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase("   ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase("   ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase("  ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase("   ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        ioTable.addCell(cell);
        // ioTable.endHeaders();
        List dbio = (ArrayList) dbinfo.get("iolist");// IO
        if (dbio != null && dbio.size() > 0) {
            for (int i = 0; i < dbio.size(); i++) {
                Hashtable tablesVO = (Hashtable) dbio.get(i);
                cell = new Cell(new Phrase((i + 1) + ""));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("chunknum")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("reads")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("pagesread")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("writes")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("pageswritten")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("mreads")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("mpagesread")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("mwrites")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
                cell = new Cell(new Phrase(String.valueOf(tablesVO.get("mpageswritten")), contextFont));
                this.setCellFormat(cell, false);
                ioTable.addCell(cell);
            }
        }
        document.add(ioTable);

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            // img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        //    
        Table evenInfoTable = new Table(2);
        // float[] evenInfoWidths = { 220f, 220f };
        // evenInfoTable.setWidths(evenInfoWidths);
        // evenInfoTable.setWidth(100); //  90%
        // evenInfoTable.setAlignment(Element.ALIGN_CENTER);// 
        // evenInfoTable.setAutoFillEmptyCells(true); // 
        // evenInfoTable.setBorderWidth(1); // 
        // evenInfoTable.setBorderColor(new Color(0, 125, 255)); // 
        // evenInfoTable.setPadding(2);// 
        // evenInfoTable.setSpacing(0);// 
        // evenInfoTable.setBorder(2);// 
        this.setTableFormat(evenInfoTable);
        String downnum = (String) reportHash.get("downnum");
        String count = (Integer) reportHash.get("count") + "";
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(2);
        this.setCellFormat(cell, true);
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase(downnum, contextFont));
        this.setCellFormat(cell, false);
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase(count, contextFont));
        this.setCellFormat(cell, false);
        evenInfoTable.addCell(cell);
        document.add(evenInfoTable);

        // 
        addEventListToDoc(document, titleFont, contextFont);
        document.close();
    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    }
}

From source file:com.amphisoft.epub2pdf.Converter.java

License:Open Source License

public void convert(String epubPath) throws IOException, DocumentException {
    File epubFile = new File(epubPath);
    if (!(epubFile.canRead())) {
        throw new IOException("Could not read " + epubPath);
    } else {//from  ww  w  .j ava 2s.c  om
        System.err.println("Converting " + epubFile.getAbsolutePath());
    }
    String epubFilename = epubFile.getName();
    String epubFilenameBase = epubFilename.substring(0, epubFilename.length() - 5);
    String pdfFilename = epubFilenameBase + ".pdf";

    File outputFile = new File(outputDir.getAbsolutePath() + File.separator + pdfFilename);

    epubIn = Epub.fromFile(epubPath);
    XhtmlHandler.setSourceEpub(epubIn);

    Opf opf = epubIn.getOpf();
    List<String> contentPaths = opf.spineHrefs();
    List<File> contentFiles = new ArrayList<File>();
    for (String path : contentPaths) {
        contentFiles.add(new File(epubIn.getContentRoot(), path));
    }
    Ncx ncx = epubIn.getNcx();

    List<NavPoint> ncxToc = new ArrayList<NavPoint>();
    if (ncx != null) {
        ncxToc.addAll(ncx.getNavPointsFlat());
    }

    Tree<TocTreeNode> tocTree = TocTreeNode.buildTocTree(ncx);
    XhtmlHandler.setTocTree(tocTree);

    Document doc = new Document();
    boolean pageSizeOK = doc.setPageSize(pageSize);
    boolean marginsOK = doc.setMargins(marginLeftPt, marginRightPt, marginTopPt, marginBottomPt);

    System.err.println("Writing PDF to " + outputFile.getAbsolutePath());
    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(outputFile));
    writer.setStrictImageSequence(true);
    PdfOutline bookmarkRoot = null;

    if (!(pageSizeOK && marginsOK)) {
        throw new RuntimeException("Failed to set PDF page size a/o margins");
    }

    int fileCount = contentFiles.size();
    printlnerr("Processing " + fileCount + " HTML file(s): ");
    int currentFile = 0;

    for (File file : contentFiles) {
        currentFile++;

        char progressChar;

        int mod10 = currentFile % 10;
        if (mod10 == 5)
            progressChar = '5';
        else if (mod10 == 0)
            progressChar = '0';
        else
            progressChar = '.';

        printerr(progressChar);
        if (!(doc.isOpen())) {
            doc.open();
            doc.newPage();
            bookmarkRoot = writer.getRootOutline();
            XhtmlHandler.setBookmarkRoot(bookmarkRoot);
        }
        NavPoint fileLevelNP = Ncx.findNavPoint(ncxToc, file.getName());
        TreeNode<TocTreeNode> npNode = TocTreeNode.findInTreeByNavPoint(tocTree, fileLevelNP);

        if (fileLevelNP != null) {
            doc.newPage();
            PdfOutline pdfOutlineParent = bookmarkRoot;
            if (npNode != null) {
                TreeNode<TocTreeNode> parent = npNode.getParent();
                if (parent != null) {
                    TocTreeNode parentTTN = parent.getValue();
                    if (parentTTN != null && parentTTN.getPdfOutline() != null) {
                        pdfOutlineParent = parentTTN.getPdfOutline();
                    }
                }
            }

            PdfDestination here = new PdfDestination(PdfDestination.FIT);
            PdfOutline pdfTocEntry = new PdfOutline(pdfOutlineParent, here, fileLevelNP.getNavLabelText());
            if (npNode != null) {
                npNode.getValue().setPdfDestination(here);
                npNode.getValue().setPdfOutline(pdfTocEntry);
            }
        }
        XhtmlHandler.process(file.getCanonicalPath(), doc);
    }
    printlnerr();

    doc.close();
    System.err.println("PDF written to " + outputFile.getAbsolutePath());
    epubIn.cleanup();
}