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

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

Introduction

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

Prototype

public void setPadding(float padding) 

Source Link

Document

Sets the padding of the contents in the cell (space between content and border).

Usage

From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void headerTable(Document pdfdoc, org.w3c.dom.Document xmldoc) {
    try {/*www. j  ava 2  s.  com*/
        int header_font_size = 10;
        Image png_left = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        Image png_right = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        png_left.setAlignment(Image.LEFT);
        png_right.setAlignment(Image.RIGHT);
        png_left.scalePercent(60);
        png_right.scalePercent(60);
        //png.scaleAbsolute(76, 67);
        //png.setAlignment(Image.MIDDLE);

        PdfPCell cell;

        float[] widths = { 1f, 5f, 1f };
        float[] widths1 = { 1f };
        PdfPTable table = new PdfPTable(widths);
        PdfPTable table1 = new PdfPTable(widths1);

        table.setWidthPercentage(100);

        cell = new PdfPCell();
        cell.setMinimumHeight(70);
        cell.addElement(new Chunk(png_left, +14, -40));
        table.addCell(cell);

        String Text = "";
        try {

            Text = findNodeValue(xml_QMRF_number, xmldoc);
            Chunk ident_title = new Chunk("QMRF identifier (JRC Inventory):");
            Chunk ident_text = new Chunk(Text);

            Font bi_font = new Font(baseFont, header_font_size, Font.BOLDITALIC);
            Font i_font = new Font(baseFont, header_font_size, Font.ITALIC);

            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            Paragraph p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            ident_title = new Chunk("QMRF Title:");
            Phrase textPhrase = new Phrase();
            createNodePhrase("QSAR_title", xmldoc, textPhrase, i_font);
            ident_title.setFont(bi_font);

            p = new Paragraph();
            p.add(ident_title);
            p.add(textPhrase);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            java.util.Date now = new java.util.Date();
            java.text.DateFormat df = java.text.DateFormat.getDateInstance();
            String date = df.format(now);
            ident_title = new Chunk("Printing Date:");
            ident_text = new Chunk(date);
            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);

            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            p = new Paragraph("");
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);
            cell = new PdfPCell(table1);
            cell.setPadding(0f);
            table.addCell(cell);

        } catch (Throwable x) {
            x.printStackTrace();

        }

        //table.addCell(new PdfPCell(png, true));
        cell.addElement(new Chunk(png_right, +14, -40));
        table.addCell(cell);
        pdfdoc.add(table);
        pdfdoc.add(new Paragraph(16));

    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:ambit2.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void headerTable(Document pdfdoc, org.w3c.dom.Document xmldoc) {
    try {/*from   www . j ava2  s .c  o m*/
        int header_font_size = 10;
        Image png_left = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        Image png_right = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        png_left.setAlignment(Image.LEFT);
        png_right.setAlignment(Image.RIGHT);
        png_left.scalePercent(60);
        png_right.scalePercent(60);
        //png.scaleAbsolute(76, 67);
        //png.setAlignment(Image.MIDDLE);

        PdfPCell cell;

        float[] widths = { 1f, 5f, 1f };
        float[] widths1 = { 1f };
        PdfPTable table = new PdfPTable(widths);
        PdfPTable table1 = new PdfPTable(widths1);

        table.setWidthPercentage(100);

        cell = new PdfPCell();
        cell.setMinimumHeight(70);
        cell.addElement(new Chunk(png_left, +14, -40));
        table.addCell(cell);

        String Text = "";
        try {

            Text = findNodeValue(xml_QMRF_number, xmldoc);
            Chunk ident_title = new Chunk("QMRF identifier (ECB Inventory):");
            Chunk ident_text = new Chunk(Text);

            Font bi_font = new Font(baseFont, header_font_size, Font.BOLDITALIC);
            Font i_font = new Font(baseFont, header_font_size, Font.ITALIC);

            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            Paragraph p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            ident_title = new Chunk("QMRF Title:");
            Phrase textPhrase = new Phrase();
            createNodePhrase("QSAR_title", xmldoc, textPhrase, i_font);
            ident_title.setFont(bi_font);

            p = new Paragraph();
            p.add(ident_title);
            p.add(textPhrase);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            java.util.Date now = new java.util.Date();
            java.text.DateFormat df = java.text.DateFormat.getDateInstance();
            String date = df.format(now);
            ident_title = new Chunk("Printing Date:");
            ident_text = new Chunk(date);
            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);

            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            p = new Paragraph("");
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);
            cell = new PdfPCell(table1);
            cell.setPadding(0f);
            table.addCell(cell);

        } catch (Throwable x) {
            x.printStackTrace();

        }

        //table.addCell(new PdfPCell(png, true));
        cell.addElement(new Chunk(png_right, +14, -40));
        table.addCell(cell);
        pdfdoc.add(table);
        pdfdoc.add(new Paragraph(16));

    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:at.htlpinkafeld.beans.JahresuebersichtBean.java

/**
 * Factory-Method for a PdfCell// w  ww .jav a  2 s .  c o  m
 *
 * @param text Text for the cell
 * @param alignment alignment for the cell content
 * @return the created Cell
 */
private PdfPCell getCell(String text, int alignment) {
    PdfPCell cell = new PdfPCell(new Phrase(text));
    cell.setPadding(0);
    cell.setHorizontalAlignment(alignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    return cell;
}

From source file:at.htlpinkafeld.beans.UserDetailsBean.java

private PdfPCell getCell(String text, int alignment) {
        PdfPCell cell = new PdfPCell(new Phrase(text));
        cell.setPadding(0);
        cell.setHorizontalAlignment(alignment);
        cell.setBorder(PdfPCell.NO_BORDER);
        return cell;
    }/*from  w w w . j  a va 2  s. co  m*/

From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.formbuilder.ITextInnerTable.java

License:Open Source License

private PdfPCell getCell() {
    PdfPCell cell = new PdfPCell();
    cell.setPadding(0);
    cell.setBorderWidth(0);
    return cell;
}

From source file:bucks.AuditSheet.java

License:Open Source License

void generateSheet(HttpServletResponse res, List<Batch> batches) {

    ///*w  w w. j  a v  a2s . co m*/
    // paper size legal (A4) 8.5 x 11
    // page 1-inch = 72 points
    //
    String spacer = "   \n";
    ServletOutputStream out = null;
    String filename = "marketbucks_audit_sheet.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();
        URL imgUrl = new URL(imageUrl);
        Image image = Image.getInstance(imgUrl);
        image.scalePercent(20f);
        // image.scaleAbsolute(100f, 100f);// width, height
        // image.setRotation(3.1f); // in radians
        // image.setRotationDegrees(90f); // degrees
        // image.setSpacingBefore(10f);
        // image.setSpacingAfter(10f);
        // image.setWidthPercentage(25.0f);
        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 = { 25f, 75f }; // percentages
        PdfPTable headTable = new PdfPTable(widths);
        headTable.setWidthPercentage(100);
        headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        headTable.addCell(cell);

        Phrase phrase = new Phrase();
        ch = new Chunk("Printed Market Bucks Audit Sheet\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);
        //
        document.add(spacePhrase);
        document.add(spacePhrase);
        //
        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(" Date: ", fntb);
        phrase.add(ch);
        ch = new Chunk(Helper.getToday() + "\n\n\n", 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(" ", fntb); // empty cell
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //         
        document.add(table);
        //
        phrase = new Phrase(new Chunk("\n", fnt));
        document.add(phrase);
        //
        float[] widths2 = { 15f, 10f, 15f, 15f, 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("Count of MB/GC", 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_BOTTOM);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Total Dollars", 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("Printed By", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Start 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("End 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("Printed Date", 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);
        //
        // next rows
        //
        for (Batch one : batches) {
            phrase = new Phrase();
            ch = new Chunk(one.getBatch_size(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);

            phrase = new Phrase();
            ch = new Chunk("$" + one.getValue() + ".00", fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);
            //
            phrase = new Phrase();
            ch = new Chunk(moneyFormat.format(one.getTotal()), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);
            //
            phrase = new Phrase();
            ch = new Chunk(one.getUser().toString(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);

            phrase = new Phrase();
            ch = new Chunk(one.getStart_seq(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);

            phrase = new Phrase();
            ch = new Chunk(one.getEnd_seq(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);

            phrase = new Phrase();
            ch = new Chunk(one.getDate(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);
        }
        document.add(table);
        //
        document.add(spacePhrase);
        document.add(spacePhrase);
        //
        ch = new Chunk("Audit By:____________________________________________________________________\n\n",
                fnt);
        phrase = new Phrase();
        phrase.add(ch);
        document.add(phrase);
        ch = new Chunk("           :_______________________________________)_____________________________\n\n",
                fnt);
        phrase = new Phrase();
        phrase.add(ch);
        document.add(phrase);
        ch = new Chunk("           :_____________________________________________________________________\n\n",
                fnt);
        phrase = new Phrase();
        phrase.add(ch);
        document.add(phrase);
        //
        document.add(spacePhrase);
        document.add(spacePhrase);
        //
        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:bucks.GenerateChecks.java

License:Open Source License

void generate_mb(Document document, int seq, String value, Image image, PdfWriter writer) {
    try {//  www .jav a 2  s . c o m
        float[] widths = { 15f, 40f, 45f }; // percentages         
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        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 BUCKS\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);
        //
        // document.add(table);
        //
        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("eligible food items ", fntb);
        phrase.add(ch);
        ch = new Chunk("at the Bloomington Community Farmers' Market. ", fnt);
        phrase.add(ch);
        ch = new Chunk("No change allowed. \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.setFixedHeight(48f);
        cell.setColspan(3);
        table.addCell(cell);

        document.add(table);
        //
        float[] widths2 = { 60f, 25f, 10f, 5f };
        table = new PdfPTable(widths2);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        //table.getDefaultCell().setPadding(0);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        //
        phrase = new Phrase();
        ch = new Chunk(
                "Customers shall redeem this certificate at Farmers' Market\nby December 1st of the year 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, false);
        // barcode text has problem, so we turned off
        // and decided to add it ourselves.
        barcode.setDrawingText(false);
        // barcode.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 16));
        // barcode.setLabel(""+seq);
        BufferedImage bi = BarcodeImageHandler.getImage(barcode);
        /*
        int width = bi.getWidth();
        int height = bi.getHeight();
        Graphics2D g2 = bi.createGraphics();
        g2.setColor(Color.BLACK);
        g2.drawString(""+seq, 60, 70);
        g2.dispose();
        */
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //
        // added this hack to get rid of underline in the barcode
        // this worked on windows, but the text did not show up on linux
        // that is why we decided to abandon the text all the way
        // and add it ourselves
        /*
        BarcodeImageHandler.writePNG(barcode, baos);
        File bcImg = File.createTempFile("bc-", ".png");
        bcImg.deleteOnExit();
        byte[] imageBytes = baos.toByteArray();
        FileOutputStream fos = new FileOutputStream(bcImg);
        BarcodeImageHandler.writePNG(barcode, fos);
        */
        //
        // old
        ImageIO.write(bi, "png", baos);
        byte[] imageBytes = baos.toByteArray();
        //
        Image barCodeImage = Image.getInstance(imageBytes);

        barCodeImage.setRotationDegrees(90f);
        // barCodeImage.scalePercent(35f);
        barCodeImage.scalePercent(35f, 50f);
        // float widthf = barCodeImage.getWidth();
        // float heightf = barCodeImage.getHeight();

        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);
        // cell.setFixedHeight(81f);
        table.addCell(cell);
        //
        // the barcode text that we added 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",
                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(34f);
        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[] widths4 = { 40f, 60f }; // percentages         
        table = new PdfPTable(widths4);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setSpacingBefore(0f);
        table.setSpacingAfter(0f);
        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.setFixedHeight(40f); // 40
        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 ISSUED\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);
    } catch (Exception ex) {
        System.err.println(ex);
    }

}

From source file:bucks.GenerateChecks.java

License:Open Source License

void generate_gc(Document document, int seq, String value, Image image, PdfWriter writer) {
    try {//  www  .j  av a 2s.co  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 www  .j  av  a 2  s.  c o  m*/
    // 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:classroom.filmfestival_b.Movies13.java

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

    // step 1/*from w ww.  jav a 2  s. c o 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;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        for (FilmTitle movie : results) {
            f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
            if (f.exists()) {
                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);
    }
}