Example usage for com.lowagie.text.pdf PdfPCell setColspan

List of usage examples for com.lowagie.text.pdf PdfPCell setColspan

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setColspan.

Prototype

public void setColspan(int colspan) 

Source Link

Document

Setter for property colspan.

Usage

From source file:bucks.GenerateChecks.java

License:Open Source License

void generate_gc(Document document, int seq, String value, Image image, PdfWriter writer) {
    try {//from www  . ja  v  a  2s.  c o  m
        float[] widths = { 13f, 54f, 33f }; // percents
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(46f);
        table.addCell(cell);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("FARMERS' MARKET GIFT CERTIFICATE\n", fntb2);
        phrase.add(ch);
        ch = new Chunk("Parks & Recreation\nBloomington, IN", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Issue Date__________ ", fnt10);
        phrase.add(ch);
        ch = new Chunk("No. " + seq, fnt10);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is good for ", fnt);
        phrase.add(ch);
        ch = new Chunk("$" + value + ".00 ", fntb2);
        phrase.add(ch);
        ch = new Chunk("towards the purchase of ", fnt);
        phrase.add(ch);
        ch = new Chunk("products from ", fnt);
        phrase.add(ch);
        ch = new Chunk("the Bloomington Community Farmers' Market and A Fair of The Arts Vendors. ", fnt);
        phrase.add(ch);
        ch = new Chunk("Change may be given. \n", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setColspan(3);
        cell.setFixedHeight(48f);
        table.addCell(cell);
        document.add(table);
        //
        float[] widths2 = { 60f, 25f, 10f, 5f };
        table = new PdfPTable(widths2);
        table.setWidthPercentage(100);
        table.setSpacingBefore(0f);
        table.setSpacingAfter(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        //
        phrase = new Phrase();
        ch = new Chunk("Customers shall redeem this certificate at Market\nwithin one year of date issued. ",
                fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setColspan(2);

        cell.setFixedHeight(81f);
        table.addCell(cell);

        Barcode barcode = BarcodeFactory.createCode39("" + seq, true);
        barcode.setDrawingText(false);
        BufferedImage bi = BarcodeImageHandler.getImage(barcode);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //
        ImageIO.write(bi, "png", baos);
        byte[] imageBytes = baos.toByteArray();
        //
        Image barCodeImage = Image.getInstance(imageBytes);

        barCodeImage.setRotationDegrees(90);
        // barCodeImage.scalePercent(35f);
        barCodeImage.scalePercent(35f, 50f);
        cell = new PdfPCell(barCodeImage);
        //
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        table.addCell(cell);
        //
        // adding text underneath the barcode
        //
        int textWidth = 53, textHeight = 50;
        BufferedImage bi2 = new BufferedImage(textWidth, textHeight, BufferedImage.TYPE_BYTE_BINARY);
        Graphics2D g = bi2.createGraphics();
        g.setFont(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10));
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, textWidth, textHeight);
        g.setColor(Color.BLACK);
        g.drawString("" + seq, 5, 10);

        g.dispose();
        baos = new ByteArrayOutputStream();
        ImageIO.write(bi2, "png", baos);
        imageBytes = baos.toByteArray();
        Image barCodeTextImage = Image.getInstance(imageBytes);

        barCodeTextImage.setRotationDegrees(90f);
        cell = new PdfPCell(barCodeTextImage);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is not refundable and cannot be replaced if lost or stolen.\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(30f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("\nMust have official stamp to be valid.\n\n", fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setColspan(3);
        table.addCell(cell);
        document.add(table);
        //
        float[] widths3 = { 40f, 60f }; // percentages         
        table = new PdfPTable(widths3);
        table.setWidthPercentage(100);
        table.setSpacingBefore(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

        phrase = new Phrase();
        ch = new Chunk("APPROVED BY THE STATE BOARD OF ACCOUNTS\nFOR THE CITY OF BLOOMINGTON, IN 2007\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        // cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setFixedHeight(44f);
        table.addCell(cell);
        phrase = new Phrase();
        ch = new Chunk(
                "VENDERS SHALL REDEEM THIS CERTIFICATE THROUGH BLOOMINGTON'S\nPARKS & REC DEPT. BY DECEMBER 15TH OF THE YEAR RECEIVED\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);

        document.add(table);
        // document.add( Chunk.NEWLINE );
    } catch (Exception ex) {
        System.err.println(ex);
    }
}

From source file:bucks.RedeemInvoice.java

License:Open Source License

void generateInvoice(HttpServletResponse res, Redeem redeem) {

    ///*from  w ww . j  a  v  a  2  s. com*/
    // paper size legal (A4) 8.5 x 11
    // page 1-inch = 72 points
    //
    String spacer = "   \n";
    User user = redeem.getUser();
    Vendor vendor = redeem.getVendor();
    List<Buck> bk_bucks = redeem.getBk_bucks();
    List<Buck> gc5_bucks = redeem.getGc5_bucks();
    List<Buck> gc20_bucks = redeem.getGc20_bucks();
    List<Buck> gc_bucks = redeem.getGc_bucks();
    List<Dispute> disputes = redeem.getDisputes();
    int bk_total = 0, gc5_total = 0, gc20_total = 0, total = 0;
    if (bk_bucks.size() > 0) {
        bk_total = bk_bucks.size() * 3;
    }
    if (gc5_bucks.size() > 0) {
        gc5_total = gc5_bucks.size() * 5;
    }
    if (gc20_bucks.size() > 0) {
        gc20_total = gc20_bucks.size() * 20;
    }
    total = bk_total + gc5_total + gc20_total;
    String vendor_name = "";
    if (vendor != null) {
        vendor_name = vendor.getCleanName();
    }
    ServletOutputStream out = null;
    String filename = "invoice_" + vendor_name + "_" + redeem.getId() + ".pdf";
    try {
        // space
        //         
        Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11"
        Document document = new Document(pageSize, 36, 36, 18, 18);// 18,18,54,35         
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        Image image = Image.getInstance(imageUrl);
        // image = Image.getInstance(byte bytes[]);// generated image
        image.scalePercent(20f);
        Font fnt = new Font(Font.TIMES_ROMAN, 12, Font.NORMAL);
        Font fntb = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);
        Font fntb2 = new Font(Font.TIMES_ROMAN, 14, Font.BOLD);

        //
        Phrase spacePhrase = new Phrase();
        Chunk ch = new Chunk(spacer, fnt);
        spacePhrase.add(ch);

        float[] widths = { 15f, 85f }; // percentages
        PdfPTable headTable = new PdfPTable(widths);
        headTable.setWidthPercentage(100);
        headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        // image.setWidthPercentage(15.0f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        // cell.setFixedHeight(46f);
        headTable.addCell(cell);

        Phrase phrase = new Phrase();
        ch = new Chunk(
                "City of Bloomington Community Farmers Market\n Gift Certificates/Market Bucks Invoice\n ",
                fntb2);
        phrase.add(ch);
        Paragraph pp = new Paragraph();
        pp.setIndentationLeft(20);
        pp.setAlignment(Element.ALIGN_LEFT);
        pp.add(phrase);
        cell = new PdfPCell(pp);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headTable.addCell(cell);
        document.add(headTable);
        //
        float[] widths3 = { 50f, 50f }; // percentages
        PdfPTable table = new PdfPTable(widths3);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        phrase = new Phrase();
        ch = new Chunk(" Vendor Name: ", fntb);
        phrase.add(ch);
        ch = new Chunk(vendor.getFullName(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //         
        phrase = new Phrase();
        ch = new Chunk("Date: ", fntb);
        phrase.add(ch);
        ch = new Chunk(redeem.getDate(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        phrase = new Phrase();
        ch = new Chunk(" Vendor Number: ", fntb);
        phrase.add(ch);
        ch = new Chunk(vendor.getId(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        phrase = new Phrase(); // empty cell
        ch = new Chunk(" ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        table.addCell(cell); // extra space
        table.addCell(cell);
        document.add(table);
        //
        phrase = new Phrase(new Chunk("\n", fnt));
        document.add(phrase);
        //
        float[] widths2 = { 30f, 25f, 15f, 15f, 15f }; // percentages
        table = new PdfPTable(widths2);
        table.setWidthPercentage(90);
        // table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        // table.getDefaultCell().setPadding(5);
        phrase = new Phrase();
        ch = new Chunk("Type of Voucher", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("City Account Number", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Quantity", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("Multiply", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("Value", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        // second row
        phrase = new Phrase();
        ch = new Chunk("Market Bucks", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("201-18-1865003-47240", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        String str = " ";
        if (bk_bucks.size() > 0) {
            str = "" + bk_bucks.size();
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("x $3.00 = ", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);

        phrase = new Phrase();
        str = " ";
        if (bk_total > 0) {
            str = "$" + bk_total + ".00";
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);
        //
        // 3rd row
        phrase = new Phrase();
        ch = new Chunk("$5 Gift Cerificates", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("201-18-1865003-47230", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        str = " ";
        if (gc5_bucks.size() > 0) {
            str = "" + gc5_bucks.size();
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("x $5.00 = ", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);

        phrase = new Phrase();
        str = " ";
        if (gc5_total > 0) {
            str = "$" + gc5_total + ".00";
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);
        //
        // 4th row
        phrase = new Phrase();
        ch = new Chunk("$20 Gift Certificates", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("201-18-1865003-47230", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        str = " ";
        if (gc20_bucks.size() > 0) {
            str = "" + gc20_bucks.size();
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("x $20.00 = ", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        str = " ";
        if (gc20_total > 0) {
            str = "$" + gc20_total + ".00";
        }
        phrase = new Phrase();
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);
        //
        // 5th row total
        phrase = new Phrase();
        ch = new Chunk(" Total Value: ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(2f);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("$" + total + ".00", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(2f);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        document.add(table);
        //
        //
        float[] withs5 = { 100f };
        table = new PdfPTable(withs5);
        table.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase(" "));
        cell.setBorder(Rectangle.BOTTOM);
        // cell.setBorderColorBottom(Color.BLACK);
        cell.setBorderWidthBottom(2f);
        table.addCell(cell);
        document.add(table);
        //
        ch = new Chunk("\n", fnt);
        phrase = new Phrase();
        phrase.add(ch);
        document.add(phrase);
        //
        // float[] widths3 = {50f, 50f}; // percentages
        table = new PdfPTable(widths3);
        table.setWidthPercentage(100);
        // table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        phrase = new Phrase();
        ch = new Chunk(" Data Entry Completed by: ", fntb);
        phrase.add(ch);
        ch = new Chunk(user.getFullName(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk(" Invoice Number: ", fntb);
        phrase.add(ch);
        ch = new Chunk(redeem.getId(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        document.add(table);
        document.add(spacePhrase);
        document.add(spacePhrase);
        //
        // adding bucks and GC
        //
        float[] widths4 = { 100f }; // percentages
        table = new PdfPTable(widths4);
        table.setWidthPercentage(100);
        // table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        int row = 1, col = 1;
        if (bk_bucks.size() > 0) {
            phrase = new Phrase();
            ch = new Chunk(" Market Bucks ", fntb);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidth(2f);
            table.addCell(cell);
            phrase = new Phrase();
            for (Buck one : bk_bucks) {
                ch = new Chunk("" + one.getId() + " ", fntb);
                phrase.add(ch);
                col++;
                if (col > 15) {
                    row++;
                    col = 1;
                    cell = new PdfPCell(phrase);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.addCell(cell);
                    phrase = new Phrase();
                }
            }
            if (col > 1) {
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            }
            if (row < 10) {
                for (int j = 0; j < 2; j++) {
                    phrase = new Phrase();
                    ch = new Chunk(" ", fntb);
                    phrase.add(ch);
                    cell = new PdfPCell(phrase);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.addCell(cell);
                    row++;
                }
            }
        }
        col = 1;
        if (gc_bucks.size() > 0) {
            phrase = new Phrase();
            ch = new Chunk(" Gift Certificates ", fntb);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidth(2f);
            table.addCell(cell);
            phrase = new Phrase();
            for (Buck one : gc_bucks) {
                ch = new Chunk("" + one.getId() + " ", fntb);
                phrase.add(ch);
                col++;
                if (col > 15) {
                    row++;
                    col = 1;
                    cell = new PdfPCell(phrase);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.addCell(cell);
                    phrase = new Phrase();
                }
            }
            if (col > 1) {
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            }
            if (row < 15) {
                for (int j = 0; j < 2; j++) {
                    phrase = new Phrase();
                    ch = new Chunk(" ", fntb);
                    phrase.add(ch);
                    cell = new PdfPCell(phrase);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.addCell(cell);
                    row++;
                }
            }
        }
        if (disputes != null && disputes.size() > 0) {
            phrase = new Phrase();
            ch = new Chunk(" Disputed Market Bucks and/or Gift Certificates (number: reason)", fntb);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidth(2f);
            table.addCell(cell);
            row++;
            for (Dispute one : disputes) {
                phrase = new Phrase();
                ch = new Chunk(one.getBuck_id() + ": " + one.getReason(), fnt);
                phrase.add(ch);
                if (one.hasNotes()) {
                    ch = new Chunk("\nNotice: " + one.getNotes(), fnt);
                    phrase.add(ch);
                    row++;
                }
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
                row++;
            }
        }
        if (redeem.hasNotes()) {
            phrase = new Phrase();
            ch = new Chunk("\nNotice: " + redeem.getNotes(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
            row++;
        }
        if (row < 18) {
            for (int j = row; j < 18; j++) {
                phrase = new Phrase();
                ch = new Chunk(" ", fntb);
                phrase.add(ch);
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            }
        }

        document.add(table);
        document.close();
        writer.close();
        res.setHeader("Expires", "0");
        res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        res.setHeader("Pragma", "public");
        //
        // setting the content type
        res.setHeader("Content-Disposition", " attachment; filename=" + filename);
        res.setContentType("application/pdf");
        //
        // the contentlength is needed for MSIE!!!
        res.setContentLength(baos.size());
        //
        out = res.getOutputStream();
        if (out != null) {
            baos.writeTo(out);
        }
    } catch (Exception ex) {
        System.err.println(ex);
    }
}

From source file:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java

License:Open Source License

/**
 * @param widths The maximum width of each column's contents in
 * points.  THIS ARRAY WILL BE MODIFIED to the width of the widest
 * single word in the heading if it is wider than the existing
 * width value for that column.  Words are split using the default
 * settings for java.util.StringTokenizer.
 * @param headerTopNColumns reference to the null count/% inner table in the header
 * @param headerValueColumns reference to the unique count/% inner table in the header
 * @param headerLengthColumns reference to the length min/max/avg inner table in the header
 * @param headerUniqueColumns reference to the value min/max/avg inner table in the header
 * @param headerNullColumns reference to the top N Value/count inner table in the header
 * we will resert widths of these inner table after we have all rows
 *//* ww w.  ja  v  a2s.c om*/
private void addHeaderRow(TableProfileResult result, ProfileTableStructure profile, BaseFont bf,
        float titleFSize, float colHeadingFSize, float[] widths)
        throws DocumentException, IOException, SQLObjectException {

    int ncols = headings.length;

    Font titleFont = new Font(bf, titleFSize, Font.BOLD);
    Font colHeadingFont = new Font(bf, colHeadingFSize);
    PdfPTable table = profile.getMainTable();
    SQLTable sqlTable = result.getProfiledObject();

    //        TableProfileResult tProfile = (TableProfileResult) pm.getResult(sqlTable);
    PdfPTable infoTable = new PdfPTable(2);
    StringBuffer heading = new StringBuffer();
    heading.append("Connection: ").append(sqlTable.getParentDatabase().getName()).append("\n");
    heading.append("Table: ").append(SQLObjectUtils.toQualifiedName(sqlTable, SQLDatabase.class));
    if (result.getException() != null) {
        heading.append("\nProfiling Error");
        if (result.getException() != null) {
            heading.append(":\n").append(result.getException());
            StackTraceElement[] stackTrace = result.getException().getStackTrace();
            for (int i = 0; i < STACK_TRACE_LENGTH && i < stackTrace.length; i++) {
                StackTraceElement element = stackTrace[i];
                heading.append("\n   ").append(element.getFileName()).append(".").append(element.getClassName())
                        .append(".").append(element.getMethodName()).append("(").append(element.getLineNumber())
                        .append(")");
            }
            if (stackTrace.length > STACK_TRACE_LENGTH) {
                heading.append("\n   ... ").append(stackTrace.length).append(" more");
            }
        }
    } else {
        PdfPCell infoCell;

        infoCell = new PdfPCell(new Phrase("Row Count:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase(String.valueOf(result.getRowCount()), colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase("Create Date:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        infoCell = new PdfPCell(new Phrase(df.format(new Date(result.getCreateStartTime())), colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase("Elapsed:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase(result.getTimeToCreate() + "ms", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);
    }

    PdfPCell hcell = new PdfPCell(new Phrase(heading.toString(), titleFont));
    hcell.setColspan(ncols - 3);
    hcell.setBorder(Rectangle.NO_BORDER);
    hcell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(hcell);

    hcell = new PdfPCell(infoTable);
    hcell.setColspan(3);
    hcell.setBorder(Rectangle.NO_BORDER);
    table.addCell(hcell);

    if (sqlTable.getColumns().size() > 0) {

        int colNo = 0;
        // column name
        Phrase colTitle = new Phrase("Column Name", colHeadingFont);
        PdfPCell cell = new PdfPCell(colTitle);
        cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP);
        cell.setBorderWidth(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        // ensure column width is at least enough for widest word in heading
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        // date type
        colTitle = new Phrase("Data Type", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP);
        cell.setBorderWidth(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        // null count and %
        colTitle = new Phrase("NULL", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("%", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableNullColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // unique count and %
        colTitle = new Phrase("Unique", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        profile.getInnerTableUniqueColumn().addCell(cell);

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableUniqueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("%", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableUniqueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableUniqueColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        cell.setBorderWidth(2);
        table.addCell(cell);

        // length max/min/avg
        colTitle = new Phrase("Length", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        profile.getInnerTableLengthColumn().addCell(cell);

        colTitle = new Phrase("Min", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Max", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Avg", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableLengthColumn());
        cell.setColspan(3);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // value max/min/avg
        colTitle = new Phrase("Value", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        profile.getInnerTableValueColumn().addCell(cell);

        colTitle = new Phrase("Min", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Max", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Avg", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableValueColumn());
        cell.setColspan(3);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // top n
        colTitle = new Phrase("Top N", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        profile.getInnerTableTopNColumn().addCell(cell);

        colTitle = new Phrase("Values", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableTopNColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableTopNColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableTopNColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

    } else {
        hcell = new PdfPCell(new Phrase("No Column Found in the table", titleFont));
        hcell.setColspan(ncols);
        hcell.setBorder(Rectangle.BOTTOM);
        hcell.setVerticalAlignment(Element.ALIGN_LEFT);
        table.addCell(hcell);
    }
    table.setHeaderRows(2);
}

From source file:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java

License:Open Source License

private void addBodyRow(TableProfileResult tProfile, ColumnProfileResult result, DDLGenerator ddlg,
        PdfPTable table, BaseFont bf, Font f, float fsize, float[] widths)
        throws DocumentException, IOException, SQLObjectException, SQLException {

    SQLColumn col = result.getProfiledObject();

    int rowCount = -1;
    if (tProfile != null && tProfile.getException() == null) {
        rowCount = tProfile.getRowCount();
    }/*from w ww  .  j  a va 2 s .  co  m*/
    java.util.List<ColumnValueCount> topTen = null;

    boolean errorColumnProfiling = false;
    Exception columnException = null;
    if (result != null && result.getException() == null) {
        topTen = result.getValueCount();
    } else {
        errorColumnProfiling = true;
        if (result != null && result.getException() != null) {
            columnException = result.getException();
            logger.debug("Exception " + columnException + " on column " + col.getName());
        }
    }

    DecimalFormat pctFormat = new DecimalFormat("0%");

    DecimalFormat df = new DecimalFormat("#,##0.00");
    df.setMaximumFractionDigits(col.getScale());
    df.setMinimumFractionDigits(col.getScale());

    DecimalFormat adf = new DecimalFormat("#,##0.00");
    adf.setMaximumFractionDigits(Math.max(2, col.getScale()));
    adf.setMinimumFractionDigits(Math.max(2, col.getScale()));

    DecimalFormat aldf = new DecimalFormat("#,##0.0");
    aldf.setMaximumFractionDigits(1);
    aldf.setMinimumFractionDigits(0);

    boolean errorSpanRemaining = false;
    for (int colNo = 0; colNo < totalColumn; colNo++) {

        String contents;
        int alignment;

        if (headings[colNo].equalsIgnoreCase("table name")) {
            String fqTableName = SQLObjectUtils.toQualifiedName(col.getParent(), SQLDatabase.class);
            if (tProfile == null || tProfile.getException() != null) {
                contents = fqTableName + "\nProfiling Error:\n";
                if (tProfile != null && tProfile.getException() != null) {
                    contents += tProfile.getException();
                    errorSpanRemaining = true;
                }
            } else {
                contents = fqTableName;
            }
            alignment = Element.ALIGN_LEFT;
        } else if (headings[colNo].equalsIgnoreCase("row count")) {
            contents = String.valueOf(rowCount);
            alignment = Element.ALIGN_RIGHT;
        } else if (headings[colNo].equalsIgnoreCase("column name")) {
            contents = col.getName();
            alignment = Element.ALIGN_LEFT;
        } else if (headings[colNo].equalsIgnoreCase("data type")) {
            contents = ddlg.columnType(col);
            alignment = Element.ALIGN_LEFT;
        } else if (headings[colNo].equalsIgnoreCase("null count")) {

            if (errorColumnProfiling) {
                if (result == null) {
                    contents = "Column Profiling Not Found\n";
                } else {
                    contents = "Column Profiling Error:\n";
                    if (columnException != null) {
                        contents += columnException;
                        errorSpanRemaining = true;
                    }
                }
                alignment = Element.ALIGN_LEFT;
            } else {
                if (col.isDefinitelyNullable()) {
                    contents = String.valueOf(result.getNullCount());
                } else {
                    contents = "---";
                }
                alignment = Element.ALIGN_RIGHT;
            }
        } else if (headings[colNo].equalsIgnoreCase("% null")) {
            if (errorColumnProfiling) {
                continue;
            } else {
                if (col.isDefinitelyNullable()) {
                    if (rowCount <= 0) {
                        contents = "N/A";
                        alignment = Element.ALIGN_CENTER;
                    } else {
                        contents = pctFormat.format(result.getNullCount() / (double) rowCount);
                        alignment = Element.ALIGN_RIGHT;
                    }
                } else {
                    contents = "---";
                    alignment = Element.ALIGN_CENTER;
                }
            }
        } else if (headings[colNo].equalsIgnoreCase("Unique Count")) {
            if (!errorColumnProfiling) {
                contents = String.valueOf(result.getDistinctValueCount());
                alignment = Element.ALIGN_RIGHT;
            } else {
                continue;
            }
        } else if (headings[colNo].equalsIgnoreCase("% unique")) {
            if (!errorColumnProfiling) {
                if (rowCount == 0) {
                    contents = "N/A";
                    alignment = Element.ALIGN_CENTER;
                } else {
                    contents = pctFormat.format(result.getDistinctValueCount() / (double) rowCount);
                    alignment = Element.ALIGN_RIGHT;
                }
            } else {
                continue;
            }
        } else if (headings[colNo].equalsIgnoreCase("Min Length")) {
            if (!errorColumnProfiling) {
                contents = String.valueOf(result.getMinLength());
                alignment = Element.ALIGN_RIGHT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Max Length")) {
            if (!errorColumnProfiling) {
                contents = String.valueOf(result.getMaxLength());
                alignment = Element.ALIGN_RIGHT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("avg Length")) {
            if (!errorColumnProfiling) {
                contents = aldf.format(result.getAvgLength());
                alignment = Element.ALIGN_RIGHT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Min value")) {
            if (!errorColumnProfiling) {
                if (result.getMinValue() == null) {
                    alignment = Element.ALIGN_CENTER;
                    contents = "";
                } else if (result.getMinValue() instanceof Number) {
                    alignment = Element.ALIGN_RIGHT;
                    contents = df.format((Number) result.getMinValue());
                } else {
                    alignment = Element.ALIGN_LEFT;
                    contents = String.valueOf(result.getMinValue());
                }
                alignment = Element.ALIGN_LEFT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Max value")) {
            if (!errorColumnProfiling) {
                if (result.getMaxValue() == null) {
                    alignment = Element.ALIGN_CENTER;
                    contents = "";
                } else if (result.getMaxValue() instanceof Number) {
                    alignment = Element.ALIGN_RIGHT;
                    contents = df.format((Number) result.getMaxValue());
                } else {
                    alignment = Element.ALIGN_LEFT;
                    contents = String.valueOf(result.getMaxValue());
                }
                alignment = Element.ALIGN_LEFT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("avg value")) {
            if (!errorColumnProfiling) {
                if (result.getAvgValue() == null) {
                    alignment = Element.ALIGN_CENTER;
                    contents = "";
                } else if (result.getAvgValue() instanceof Number) {
                    alignment = Element.ALIGN_RIGHT;
                    contents = adf.format((Number) result.getAvgValue());
                } else {
                    alignment = Element.ALIGN_LEFT;
                    contents = String.valueOf(result.getAvgValue());
                }
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Top N Values")) {
            if (!errorColumnProfiling && topTen != null) {
                StringBuffer sb = new StringBuffer();
                for (ColumnValueCount cvc : topTen) {
                    sb.append(cvc.getValue()).append("\n");
                }
                contents = sb.toString();
                alignment = Element.ALIGN_LEFT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Count")) {
            if (!errorColumnProfiling) {
                StringBuffer sb = new StringBuffer();
                for (ColumnValueCount cvc : topTen) {
                    sb.append(cvc.getCount()).append("\n");
                }
                contents = sb.toString();
                alignment = Element.ALIGN_RIGHT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else {
            throw new IllegalStateException("I don't know about column " + colNo);
        }

        StringBuffer truncContents = new StringBuffer(contents.length());

        // update column width to reflect the widest cell
        for (String contentLine : contents.split("\n")) {
            String newLine;
            if (truncateLength >= 0 && !errorSpanRemaining) {
                if (bf.getWidthPoint(contentLine, fsize) < truncateLength) {
                    newLine = contentLine + "\n";
                } else {
                    double currentLength = bf.getWidthPoint("...", fsize);
                    int stringPosition = 0;
                    for (; stringPosition < contentLine.length(); stringPosition++) {
                        if (currentLength > truncateLength) {
                            break;
                        }
                        currentLength = bf.getWidthPoint(contentLine.substring(0, stringPosition) + "...",
                                fsize);
                        stringPosition++;
                    }
                    newLine = contentLine.substring(0, stringPosition - 1) + "...\n";
                }
            } else {
                newLine = contentLine + "\n";
            }
            truncContents.append(newLine);
            if (!errorSpanRemaining) {
                widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(newLine, fsize));
                logger.debug("width is now " + widths[colNo] + " for column " + colNo);
            }
        }

        PdfPCell cell;
        if (headings[colNo].equalsIgnoreCase("Top N Values") || headings[colNo].equalsIgnoreCase("Count")) {
            cell = new PdfPCell(new Paragraph(truncContents.toString(), f));
            cell.setNoWrap(true);
        } else if (headings[colNo].equalsIgnoreCase("null count") && errorColumnProfiling) {
            cell = new PdfPCell(new Paragraph(truncContents.toString(), f));
            cell.setColspan(4);
        } else {
            Phrase phr = new Phrase(truncContents.toString(), f);
            cell = new PdfPCell(phr);

        }
        //            cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(alignment);
        if (errorSpanRemaining) {
            cell.setColspan(totalColumn - colNo);
        }
        table.addCell(cell);
        if (errorSpanRemaining) {
            break;
        }
    }
}

From source file:classroom.filmfestival_b.Movies14.java

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

    // step 1//w w  w. j  av  a 2  s.  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("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();

        PdfPTable table = new PdfPTable(2);
        table.setWidths(new float[] { 1, 5 });
        File f;
        Paragraph p;
        Chunk c;
        PdfPCell cell = new PdfPCell();
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        p = new Paragraph("FILMFESTIVAL", bold);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setColspan(2);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setFixedHeight(20);
        cell.setColspan(2);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setCellEvent(new Movies14().new PageCell());
        table.addCell(cell);
        table.setHeaderRows(2);
        table.setFooterRows(1);
        for (FilmTitle movie : results) {
            f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
            if (f.exists()) {
                cell = new PdfPCell(Image.getInstance(f.getPath()), true);
                cell.setPadding(2);
            } else {
                cell = new PdfPCell();
            }
            table.addCell(cell);
            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);
            cell = new PdfPCell();
            cell.setUseAscender(true);
            cell.setUseDescender(true);
            cell.addElement(p);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            cell.addElement(list);
            table.addCell(cell);
        }
        document.add(table);
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_b.Movies15.java

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

    // step 1//ww w.ja v  a 2  s.c  om
    Document document = new Document();
    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();

        PdfPTable table = new PdfPTable(2);
        table.setComplete(false);
        table.setWidths(new float[] { 1, 5 });
        File f;
        Paragraph p;
        Chunk c;
        PdfPCell cell = new PdfPCell();
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        p = new Paragraph("FILMFESTIVAL", bold);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setColspan(2);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setFixedHeight(20);
        cell.setColspan(2);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setCellEvent(new Movies14().new PageCell());
        table.addCell(cell);
        table.setHeaderRows(2);
        table.setFooterRows(1);
        int counter = 10;
        for (FilmTitle movie : results) {
            f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
            if (f.exists()) {
                cell = new PdfPCell(Image.getInstance(f.getPath()), true);
                cell.setPadding(2);
            } else {
                cell = new PdfPCell();
            }
            table.addCell(cell);
            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);
            cell = new PdfPCell();
            cell.setUseAscender(true);
            cell.setUseDescender(true);
            cell.addElement(p);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            cell.addElement(list);
            table.addCell(cell);
            if (counter % 10 == 0) {
                document.add(table);
            }
            System.out.println(writer.getPageNumber());
            counter++;
        }
        table.setComplete(true);
        document.add(table);
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_c.Movies16.java

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

    // step 1/*from w ww.  j av a2 s  .co  m*/
    Document document = new Document();
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter.getInstance(document, os);
        // step 3
        document.open();
        // step 4
        PdfPTable table;
        PdfPCell cell;
        Chunk imdb;

        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();
        java.util.List<FestivalScreening> screenings;

        for (Date day : days) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(day);
            if (gc.get(GregorianCalendar.YEAR) != YEAR)
                continue;

            table = new PdfPTable(new float[] { 7, 1, 2, 1 });
            cell = new PdfPCell(new Phrase(day.toString(), NORMALWHITE));
            cell.setBackgroundColor(BLACK);
            cell.setColspan(4);
            table.addCell(cell);

            q = session.createQuery("from FestivalScreening where id.day=? order by id.time, id.place");
            q.setDate(0, day);
            screenings = q.list();
            for (FestivalScreening screening : screenings) {
                table.addCell(screening.getFilmTitle().getTitle());
                table.addCell(screening.getId().getPlace().toString());
                cell = new PdfPCell(new Phrase(screening.getId().getTime().toString()));
                if (screening.getPress() == 1) {
                    cell.setBackgroundColor(SILVER);
                }
                table.addCell(cell);
                if (screening.getFilmTitle().getImdb().startsWith("?")) {
                    table.addCell("");
                } else {
                    imdb = new Chunk("imdb");
                    imdb.setAnchor("http://imdb.com/title/tt" + screening.getFilmTitle().getImdb());
                    table.addCell(new Phrase(imdb));
                }
            }

            document.add(table);
        }

        // 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

protected static void addScreening(PdfPTable outer, FestivalScreening screening) throws DocumentException {
    FilmTitle movie = screening.getFilmTitle();
    // we construct a 3 column table
    PdfPTable table = new PdfPTable(3);
    table.setWidths(WIDTHS);// www  . j a v  a 2s  . c om
    // the first cell with the full title spans all the columns
    PdfPCell cell = new PdfPCell();
    cell.addElement(fullTitle(screening));
    cell.setColspan(3);
    cell.setBorder(PdfPCell.NO_BORDER);
    setColor(movie, cell);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.addElement(directors(movie));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.addElement(screenings(screening));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    table.addCell(cell);

    outer.addCell(table);

}

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

/**
 * @author wxy pdf/*from  w  w  w .  ja va 2  s .  c om*/
 * @param filename
 * @date 2010-3-27
 */
public void createReport_ServiceEventPdf(String filename) throws IOException {

    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        PdfWriter.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 starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

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

        List eventlist = new ArrayList();
        eventlist = (List) reportHash.get("eventlist");
        String ip = "";
        String sum = "";
        String levelone = "";
        String leveltwo = "";
        String levelthree = "";
        String servicename = "";
        if (eventlist != null && eventlist.size() > 0) {

            List _eventlist = (List) eventlist.get(0);
            if (_eventlist != null && _eventlist.size() > 0) {
                ip = (String) _eventlist.get(0);
                servicename = (String) _eventlist.get(1);
                sum = (String) _eventlist.get(2);
                levelone = (String) _eventlist.get(3);
                leveltwo = (String) _eventlist.get(4);
                levelthree = (String) _eventlist.get(5);
            }
        }

        Paragraph title = new Paragraph(servicename + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);

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

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(6);
        // 
        context.setFirstLineIndent(6);
        document.add(context);
        document.add(new Paragraph("\n"));

        PdfPTable servTable = new PdfPTable(6);
        float[] cellWidths = { 220f, 220f, 220f, 220f, 220f, 220f };
        servTable.setWidths(cellWidths);
        servTable.setWidthPercentage(100);
        PdfPCell cell = null;
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setColspan(6);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase("IP", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase("()", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase("()", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase("()", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase("()", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase(ip, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase(servicename, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase(sum, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase(levelone, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase(leveltwo, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        cell = new PdfPCell(new Phrase(levelthree, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        servTable.addCell(cell);
        document.add(servTable);
        document.add(new Paragraph("\n"));

        // 
        PdfPTable eventTable = new PdfPTable(6);
        float[] eventWidths = { 220f, 220f, 220f, 220f, 220f, 220f };
        eventTable.setWidths(eventWidths);
        eventTable.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setColspan(6);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase(" ", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase(" ", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase(" ", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase(" ", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        int index = 0;
        java.text.SimpleDateFormat _sdf = new java.text.SimpleDateFormat("MM-dd HH:mm");
        List list = (ArrayList) reportHash.get("list");
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                index++;
                EventList event = (EventList) list.get(i);
                Date cc = event.getRecordtime().getTime();
                Integer eventid = event.getId();
                String eventlocation = event.getEventlocation();
                String content = event.getContent();
                String level = String.valueOf(event.getLevel1());
                String status = String.valueOf(event.getManagesign());
                String s = status;
                String showlevel = null;
                String act = "";
                if ("1".equals(level)) {
                    showlevel = "";
                } else if ("2".equals(level)) {
                    showlevel = "";
                } else {
                    showlevel = "";
                }
                if ("0".equals(status)) {
                    status = "";
                }
                if ("1".equals(status)) {
                    status = "";
                }
                if ("2".equals(status)) {
                    status = "";
                }
                String rptman = event.getReportman();
                String rtime1 = _sdf.format(cc);
                cell = new PdfPCell(new Phrase(String.valueOf(index), contextFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                eventTable.addCell(cell);
                if ("3".equals(level)) {
                    cell = new PdfPCell(new Phrase(showlevel, contextFont));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                    cell.setBackgroundColor(Color.red);
                    eventTable.addCell(cell);
                } else if ("2".equals(level)) {
                    cell = new PdfPCell(new Phrase(showlevel, contextFont));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                    cell.setBackgroundColor(Color.orange);
                    eventTable.addCell(cell);
                } else {
                    cell = new PdfPCell(new Phrase(showlevel, contextFont));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                    cell.setBackgroundColor(Color.yellow);
                    eventTable.addCell(cell);
                }
                cell = new PdfPCell(new Phrase(content, contextFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                eventTable.addCell(cell);
                cell = new PdfPCell(new Phrase(rtime1, contextFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                eventTable.addCell(cell);
                cell = new PdfPCell(new Phrase(rptman, contextFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                eventTable.addCell(cell);
                cell = new PdfPCell(new Phrase(status, contextFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                eventTable.addCell(cell);
            }
        }
        document.add(eventTable);
        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 sqlserverpdf//from w  w  w. j  av  a  2 s  .  c  o m
 * @param filename
 * @throws DocumentException
 * @throws IOException
 */
public void createReport_SqlServerCldPdf(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        PdfWriter.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");
        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);
        document.add(new Paragraph("\n"));
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        // 
        PdfPTable dbTable = new PdfPTable(5);
        float[] cellWidths = { 220f, 220f, 220f, 220f, 220f };
        dbTable.setWidths(cellWidths);
        dbTable.setWidthPercentage(100);
        PdfPCell dbCell = null;
        dbCell = new PdfPCell(new Phrase("", titleFont));
        dbCell.setColspan(5);
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase("", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase("IP", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase("", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase("", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase("", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase(vo.getDbName(), contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase(ip, contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase(typename, contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase(runstr, contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new PdfPCell(new Phrase(grade, contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);

        PdfPTable aTable = new PdfPTable(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidthPercentage(100);
        PdfPCell cell = null;
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase(pingnow + "%", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase(pingmin + "%", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase(pingconavg + "%", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

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

        // (KB)
        PdfPTable dbInfoTable = new PdfPTable(5);
        float[] dbInfoWidths = { 220f, 220f, 220f, 220f, 220f };
        dbInfoTable.setWidths(dbInfoWidths);
        dbInfoTable.setWidthPercentage(100);
        Hashtable mems = (Hashtable) reportHash.get("mems");// 
        cell = new PdfPCell(new Phrase("(KB)", titleFont));
        cell.setColspan(5);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase("SQL", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) mems.get("totalMemory"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) mems.get("optMemory"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) mems.get("conMemory"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) mems.get("sqlMem"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) mems.get("lockMem"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        document.add(dbInfoTable);
        document.add(new Paragraph("\n"));

        // (KB)
        PdfPTable ncTable = new PdfPTable(4);
        float[] ncWidths = { 220f, 220f, 220f, 220f };
        ncTable.setWidths(ncWidths);
        ncTable.setWidthPercentage(100);
        Hashtable sysValue = (Hashtable) reportHash.get("sysValue");// 
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) sysValue.get("productlevel"), titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) sysValue.get("IsIntegratedSecurityOnly"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) sysValue.get("IsSingleUser"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) sysValue.get("IsClustered"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        document.add(ncTable);
        document.add(new Paragraph("\n"));

        PdfPTable aTable1 = new PdfPTable(6);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f };
        aTable1.setWidths(width);
        aTable1.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setColspan(6);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("(%)", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        Hashtable dbValue = (Hashtable) reportHash.get("tableinfo_v");
        Hashtable alldatabase = new Hashtable();
        if (dbValue.get("database") != null)
            alldatabase = (Hashtable) dbValue.get("database");
        Vector names = new Vector();
        if (dbValue.get("names") != null)
            names = (Vector) dbValue.get("names");

        if (alldatabase != null && alldatabase.size() > 0) {
            if (names == null)
                names = new Vector();
            int row = 1;
            for (int i = 0; i < names.size(); i++) {
                String key = (String) names.get(i);
                if (alldatabase.get(key) == null)
                    continue;
                Hashtable data = (Hashtable) alldatabase.get(key);
                String dbname = data.get("dbname").toString();
                String size = data.get("size").toString();
                String usedsize = "";
                if (data.get("usedsize") != null) {
                    usedsize = data.get("usedsize").toString();
                }
                String usedperc = "";
                if (data.get("usedperc") != null)
                    usedperc = data.get("usedperc").toString();
                cell = new PdfPCell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(row + ""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(dbname));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(size));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(usedsize));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(usedperc));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                row++;

            }
        }

        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(new Paragraph("\n"));

        // 
        PdfPTable eventTable = new PdfPTable(2);
        float[] eventWidths = { 220f, 220f };
        eventTable.setWidths(eventWidths);
        eventTable.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) reportHash.get("downnum"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        cell = new PdfPCell(new Phrase(reportHash.get("count") + "", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        eventTable.addCell(cell);
        document.add(eventTable);

        document.add(new Paragraph("\n"));
        // 
        addEventLisToPdf(document);

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