Example usage for com.lowagie.text.pdf PdfPTable setWidthPercentage

List of usage examples for com.lowagie.text.pdf PdfPTable setWidthPercentage

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setWidthPercentage.

Prototype

public void setWidthPercentage(float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java

License:Open Source License

/**
 * Creates a table and populates it with the clinic information for the header.
 * @return the table produced//w ww . ja  v a  2s . c om
 */
private PdfPTable createClinicInfoHeader() {
    float[] tableWidths;
    PdfPCell cell;
    //tableWidths = new float[]{ 2, 2.5f };
    //PdfPTable infoTable = new PdfPTable(tableWidths);
    PdfPTable infoTable = new PdfPTable(1);
    infoTable.setWidthPercentage(100);
    //cell = new PdfPCell();

    String letterheadName = null;

    if (reqFrm.letterheadName != null && reqFrm.letterheadName.startsWith("prog_")) {
        ProgramDao programDao = (ProgramDao) SpringUtils.getBean("programDao");
        Integer programNo = Integer.parseInt(reqFrm.letterheadName.substring(5));
        letterheadName = programDao.getProgramName(programNo);
    } else if (!reqFrm.letterheadName.equals("-1")) {
        Provider letterheadNameProvider = (reqFrm.letterheadName != null
                ? new RxProviderData().getProvider(reqFrm.letterheadName)
                : null);
        if (letterheadNameProvider != null)
            letterheadName = letterheadNameProvider.getFirstName() + " " + letterheadNameProvider.getSurname();
    } else {
        letterheadName = clinic.getClinicName();
    }

    //PdfPCell cell;
    //PdfPTable infoTable = new PdfPTable(1);

    cell = new PdfPCell(new Phrase(letterheadName, headerFont));

    cell.setBorder(0);
    cell.setPaddingLeft(25);
    infoTable.addCell(cell);

    cell.setPhrase(new Phrase((reqFrm.letterheadAddress != null && reqFrm.letterheadAddress.trim().length() > 0
            ? String.format("%s", reqFrm.letterheadAddress)
            : String.format("%s, %s, %s %s", clinic.getClinicAddress(), clinic.getClinicCity(),
                    clinic.getClinicProvince(), clinic.getClinicPostal())),
            font));
    infoTable.addCell(cell);

    cell.setPhrase(new Phrase(String.format("Tel: %s Fax: %s",
            (reqFrm.letterheadPhone != null && reqFrm.letterheadPhone.trim().length() > 0
                    ? reqFrm.letterheadPhone
                    : clinic.getClinicPhone()),
            (reqFrm.letterheadFax != null && reqFrm.letterheadFax.trim().length() > 0 ? reqFrm.letterheadFax
                    : clinic.getClinicFax())),
            font));
    infoTable.addCell(cell);

    /*
    cell.setPhrase(new Phrase(getResource("msgConsReq"), font));
    cell.setPadding(0);
    cell.setBorder(0);
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    infoTable.addCell(cell);
            
    if (reqFrm.pwb.equals("1")){
       cell.setPhrase(new Phrase(getResource("msgPleaseReplyPatient"), boldFont));
    }
            
    else if (org.oscarehr.common.IsPropertiesOn.isMultisitesEnable()) {
       cell.setPhrase(new Phrase("", boldFont));
    }
    else {
       cell.setPhrase(new Phrase(
       String.format("%s %s %s", getResource("msgPleaseReplyPart1"),
                           clinic.getClinicName(),
                           getResource("msgPleaseReplyPart2")), boldFont));
    }
    infoTable.addCell(cell);
    */
    // The last cell in the table is extended to the maximum available height;
    // inserting a blank cell here prevents the last border used to underline text from
    // being displaced to the bottom of this table.
    cell.setPhrase(new Phrase(" ", font));
    cell.setBorder(0);
    cell.setColspan(2);
    infoTable.addCell(cell);

    return infoTable;
}

From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java

License:Open Source License

public void printPdf() throws IOException, DocumentException {

    // check that we have data to print
    if (handler == null)
        throw new DocumentException();

    //response.setContentType("application/pdf");  //octet-stream
    //response.setHeader("Content-Disposition", "attachment; filename=\""+handler.getPatientName().replaceAll("\\s", "_")+"_LabReport.pdf\"");

    //Create the document we are going to write to
    document = new Document();
    //PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
    PdfWriter writer = PdfWriter.getInstance(document, os);

    //Set page event, function onEndPage will execute each time a page is finished being created
    writer.setPageEvent(this);

    document.setPageSize(PageSize.LETTER);
    document.addTitle("Title of the Document");
    document.addCreator("OSCAR");
    document.open();/*w  w w  .j  a  v  a2  s  . co  m*/

    //Create the fonts that we are going to use
    bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, 9, Font.NORMAL);
    boldFont = new Font(bf, 10, Font.BOLD);
    redFont = new Font(bf, 9, Font.NORMAL, Color.RED);

    // add the header table containing the patient and lab info to the document
    createInfoTable();

    // add the tests and test info for each header
    ArrayList<String> headers = handler.getHeaders();
    for (int i = 0; i < headers.size(); i++)
        addLabCategory(headers.get(i));

    // add end of report table
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100);
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPhrase(new Phrase("  "));
    table.addCell(cell);
    cell.setBorder(15);
    cell.setBackgroundColor(new Color(210, 212, 255));
    cell.setPhrase(new Phrase("END OF REPORT", boldFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    document.add(table);

    document.close();

    os.flush();
}

From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java

License:Open Source License

private void addLabCategory(String header) throws DocumentException {

    float[] mainTableWidths = { 5f, 3f, 1f, 3f, 2f, 4f, 2f };
    PdfPTable table = new PdfPTable(mainTableWidths);
    table.setHeaderRows(3);/*from   w  w  w .  ja v a2 s  .co  m*/
    table.setWidthPercentage(100);

    PdfPCell cell = new PdfPCell();
    // category name
    cell.setPadding(3);
    cell.setPhrase(new Phrase("  "));
    cell.setBorder(0);
    cell.setColspan(7);
    table.addCell(cell);
    cell.setBorder(15);
    cell.setPadding(3);
    cell.setColspan(2);
    cell.setPhrase(new Phrase(header.replaceAll("<br\\s*/*>", "\n"), new Font(bf, 12, Font.BOLD)));
    table.addCell(cell);
    cell.setPhrase(new Phrase("  "));
    cell.setBorder(0);
    cell.setColspan(5);
    table.addCell(cell);

    // table headers
    cell.setColspan(1);
    cell.setBorder(15);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(new Color(210, 212, 255));
    cell.setPhrase(new Phrase("Test Name(s)", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Result", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Abn", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Reference Range", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Units", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Date/Time Completed", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Status", boldFont));
    table.addCell(cell);

    // add test results
    int obrCount = handler.getOBRCount();
    int linenum = 0;
    cell.setBorder(12);
    cell.setBorderColor(Color.BLACK); // cell.setBorderColor(Color.WHITE);
    cell.setBackgroundColor(new Color(255, 255, 255));

    if (handler.getMsgType().equals("MEDVUE")) {

        //cell.setBackgroundColor(getHighlightColor(linenum));
        linenum++;
        cell.setPhrase(new Phrase(handler.getRadiologistInfo(), boldFont));
        cell.setColspan(7);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell.setPaddingLeft(100);
        cell.setColspan(7);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setPhrase(new Phrase(handler.getOBXComment(1, 1, 1).replaceAll("<br\\s*/*>", "\n"), font));
        table.addCell(cell);

    } else {
        for (int j = 0; j < obrCount; j++) {
            boolean obrFlag = false;
            int obxCount = handler.getOBXCount(j);
            for (int k = 0; k < obxCount; k++) {
                String obxName = handler.getOBXName(j, k);

                if (!handler.getOBXResultStatus(j, k).equals("TDIS")) {

                    // ensure that the result is a real result
                    if ((!handler.getOBXResultStatus(j, k).equals("DNS") && !obxName.equals("")
                            && handler.getObservationHeader(j, k).equals(header))
                            || (handler.getMsgType().equals("EPSILON")
                                    && handler.getOBXIdentifier(j, k).equals(header) && !obxName.equals(""))
                            || (handler.getMsgType().equals("PFHT") && !obxName.equals("")
                                    && handler.getObservationHeader(j, k).equals(header))) { // <<-- DNS only needed for
                        // MDS messages
                        String obrName = handler.getOBRName(j);

                        // add the obrname if necessary
                        if (!obrFlag && !obrName.equals("") && !(obxName.contains(obrName) && obxCount < 2)) {
                            // cell.setBackgroundColor(getHighlightColor(linenum));
                            linenum++;
                            cell.setPhrase(new Phrase(obrName, boldFont));
                            cell.setColspan(7);
                            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                            table.addCell(cell);
                            cell.setColspan(1);
                            obrFlag = true;
                        }

                        // add the obx results and info
                        Font lineFont = new Font(bf, 8, Font.NORMAL,
                                getTextColor(handler.getOBXAbnormalFlag(j, k)));
                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        cell.setPhrase(new Phrase((obrFlag ? "   " : "") + obxName, lineFont));
                        table.addCell(cell);
                        cell.setPhrase(new Phrase(handler.getOBXResult(j, k).replaceAll("<br\\s*/*>", "\n"),
                                lineFont));
                        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        table.addCell(cell);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setPhrase(new Phrase(
                                (handler.isOBXAbnormal(j, k) ? handler.getOBXAbnormalFlag(j, k) : "N"),
                                lineFont));
                        table.addCell(cell);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        cell.setPhrase(new Phrase(handler.getOBXReferenceRange(j, k), lineFont));
                        table.addCell(cell);
                        cell.setPhrase(new Phrase(handler.getOBXUnits(j, k), lineFont));
                        table.addCell(cell);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setPhrase(new Phrase(handler.getTimeStamp(j, k), lineFont));
                        table.addCell(cell);
                        cell.setPhrase(new Phrase(handler.getOBXResultStatus(j, k), lineFont));
                        table.addCell(cell);

                        if (!handler.getMsgType().equals("PFHT")) {
                            // add obx comments
                            if (handler.getOBXCommentCount(j, k) > 0) {
                                // cell.setBackgroundColor(getHighlightColor(linenum));
                                linenum++;
                                cell.setPaddingLeft(100);
                                cell.setColspan(7);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) {

                                    cell.setPhrase(new Phrase(
                                            handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"),
                                            font));
                                    table.addCell(cell);

                                }
                                cell.setPadding(3);
                                cell.setColspan(1);
                            }
                        }
                        // if (DNS)
                    } else if ((handler.getMsgType().equals("EPSILON")
                            && handler.getOBXIdentifier(j, k).equals(header) && obxName.equals(""))
                            || (handler.getMsgType().equals("PFHT") && obxName.equals("")
                                    && handler.getObservationHeader(j, k).equals(header))) {
                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setPaddingLeft(100);
                        cell.setColspan(7);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        cell.setPhrase(
                                new Phrase(handler.getOBXResult(j, k).replaceAll("<br\\s*/*>", "\n"), font));
                        table.addCell(cell);
                        cell.setPadding(3);
                        cell.setColspan(1);

                    }
                    if (handler.getMsgType().equals("PFHT") && !handler.getNteForOBX(j, k).equals("")
                            && handler.getNteForOBX(j, k) != null) {
                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setPaddingLeft(100);
                        cell.setColspan(7);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        cell.setPhrase(
                                new Phrase(handler.getNteForOBX(j, k).replaceAll("<br\\s*/*>", "\n"), font));
                        table.addCell(cell);
                        cell.setPadding(3);
                        cell.setColspan(1);

                        if (handler.getOBXCommentCount(j, k) > 0) {
                            // cell.setBackgroundColor(getHighlightColor(linenum));
                            linenum++;
                            cell.setPaddingLeft(100);
                            cell.setColspan(7);
                            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                            for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) {

                                cell.setPhrase(new Phrase(
                                        handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"), font));
                                table.addCell(cell);

                            }
                            cell.setPadding(3);
                            cell.setColspan(1);
                        }
                    }
                } else {
                    if (handler.getOBXCommentCount(j, k) > 0) {
                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setPaddingLeft(100);
                        cell.setColspan(7);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) {

                            cell.setPhrase(new Phrase(
                                    handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"), font));
                            table.addCell(cell);

                        }
                        cell.setPadding(3);
                        cell.setColspan(1);
                    }
                } // if (!handler.getOBXResultStatus(j, k).equals("TDIS"))

            }

            if (!handler.getMsgType().equals("PFHT")) {
                // add obr comments
                if (handler.getObservationHeader(j, 0).equals(header)) {
                    cell.setColspan(7);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    for (int k = 0; k < handler.getOBRCommentCount(j); k++) {
                        // the obrName should only be set if it has not been
                        // set already which will only have occured if the
                        // obx name is "" or if it is the same as the obr name
                        if (!obrFlag && handler.getOBXName(j, 0).equals("")) {
                            // cell.setBackgroundColor(getHighlightColor(linenum));
                            linenum++;

                            cell.setPhrase(new Phrase(handler.getOBRName(j), boldFont));
                            table.addCell(cell);
                            obrFlag = true;
                        }

                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setPaddingLeft(100);
                        cell.setPhrase(
                                new Phrase(handler.getOBRComment(j, k).replaceAll("<br\\s*/*>", "\n"), font));
                        table.addCell(cell);
                        cell.setPadding(3);
                    }
                    cell.setColspan(1);
                }
            }
        } // for (j)

    } // if (isMEDVUE)

    document.add(table);

}

From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java

License:Open Source License

private void createInfoTable() throws DocumentException {

    //Create patient info table
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);/* w ww .j a  v  a2 s  .  c  o m*/
    float[] pInfoWidths = { 2f, 4f, 3f, 2f };
    PdfPTable pInfoTable = new PdfPTable(pInfoWidths);
    cell.setPhrase(new Phrase("Patient Name: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getPatientName(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Home Phone: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getHomePhone(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Date of Birth: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getDOB(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Work Phone: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getWorkPhone(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Age: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getAge(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Sex: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getSex(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Health #: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getHealthNum(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Patient Location: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getPatientLocation(), font));
    pInfoTable.addCell(cell);

    //Create results info table
    PdfPTable rInfoTable = new PdfPTable(2);
    cell.setPhrase(new Phrase("Date of Service: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getServiceDate(), font));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Date Received: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(dateLabReceived, font));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Report Status: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase((handler.getOrderStatus().equals("F") ? "Final"
            : (handler.getOrderStatus().equals("C") ? "Corrected" : "Partial")), font));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Client Ref. #: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getClientRef(), font));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Accession #: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getAccessionNum(), font));
    rInfoTable.addCell(cell);

    //Create client table
    float[] clientWidths = { 2f, 3f };
    Phrase clientPhrase = new Phrase();
    PdfPTable clientTable = new PdfPTable(clientWidths);
    clientPhrase.add(new Chunk("Requesting Client:  ", boldFont));
    clientPhrase.add(new Chunk(handler.getDocName(), font));
    cell.setPhrase(clientPhrase);
    clientTable.addCell(cell);

    clientPhrase = new Phrase();
    clientPhrase.add(new Chunk("cc: Client:  ", boldFont));
    clientPhrase.add(new Chunk(handler.getCCDocs(), font));
    cell.setPhrase(clientPhrase);
    clientTable.addCell(cell);

    //Create header info table
    float[] tableWidths = { 2f, 1f };
    PdfPTable table = new PdfPTable(tableWidths);
    if (multiID.length > 1) {
        cell = new PdfPCell(new Phrase("Version: " + versionNum + " of " + multiID.length, boldFont));
        cell.setBackgroundColor(new Color(210, 212, 255));
        cell.setPadding(3);
        cell.setColspan(2);
        table.addCell(cell);
    }
    cell = new PdfPCell(new Phrase("Detail Results: Patient Info", boldFont));
    cell.setBackgroundColor(new Color(210, 212, 255));
    cell.setPadding(3);
    table.addCell(cell);
    cell.setPhrase(new Phrase("Results Info", boldFont));
    table.addCell(cell);

    // add the created tables to the document
    table = addTableToTable(table, pInfoTable, 1);
    table = addTableToTable(table, rInfoTable, 1);
    table = addTableToTable(table, clientTable, 2);

    table.setWidthPercentage(100);

    document.add(table);
}

From source file:permit.InvoicePdf.java

License:Open Source License

/**
 * handles the letter header//from   w w w .j av a  2  s.com
 */
PdfPTable getHeader() {
    //
    String str = "";
    String spacer = "   ";
    PdfPTable headTable = null;
    try {
        //
        // for http url use
        //
        Image image = Image.getInstance(url + "js/images/city_logo3.jpg");
        Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL);
        Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
        float[] widths = { 25f, 40f, 35f }; // percentages
        headTable = new PdfPTable(widths);
        headTable.setWidthPercentage(100);
        headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        image.scalePercent(15f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        headTable.addCell(cell);
        //
        float[] width = { 33f };
        PdfPTable midTable = new PdfPTable(width);
        midTable.setWidthPercentage(33);
        midTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        midTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("City of Bloomington ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Planning and Transportation Department ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("bloomington.in.gov", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        headTable.addCell(midTable);
        //
        PdfPTable rightTable = new PdfPTable(width);
        rightTable.setWidthPercentage(33);
        rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        rightTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        phrase = new Phrase();
        ch = new Chunk("401 N Morton St Suite 130 ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("PO Box 100 \nBloomington, IN 47404", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\n Phone: (812) 349-3423\nFax (812) 349-3520\nEmail: planning@bloomington.in.gov",
                fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        headTable.addCell(rightTable);
    } catch (Exception ex) {
        logger.error(ex);
    }
    return headTable;
}

From source file:permit.InvoicePdf.java

License:Open Source License

void writePages(HttpServletResponse res, Invoice invoice) {
    ////from   w w  w  .j ava 2  s.c  o  m
    // paper size legal (A4) 8.5 x 11
    // page 1-inch = 72 points
    //
    String fileName = "row_invoice_" + invoice.getInvoice_num() + ".pdf";
    Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11"
    Document document = new Document(pageSize, 36, 36, 18, 18);
    ServletOutputStream out = null;
    Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL);
    Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);
    Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
    String spacer = "   ";
    PdfPTable header = getHeader();
    Company company = invoice.getCompany();
    Contact contact = null;
    if (invoice.hasContact()) {
        contact = invoice.getContact();
    }
    List<Page> pages = invoice.getPages();

    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        String str = "";
        document.open();
        document.add(header);
        //
        // title
        float[] width = { 100f }; // one cell
        PdfPTable table = new PdfPTable(width);
        table.setWidthPercentage(100.0f);
        PdfPCell cell = new PdfPCell(new Phrase("INVOICE", fntb));
        //         
        cell.setBorder(Rectangle.BOTTOM);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        document.add(table);
        //
        // we need these later
        Paragraph pp = new Paragraph();
        Chunk ch = new Chunk(" ", fntb);
        Phrase phrase = new Phrase();
        //
        float[] widths = { 35f, 30f, 35f }; // percentages
        table = new PdfPTable(widths);
        table.setWidthPercentage(100.0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //
        // first row
        float[] widthOne = { 100f };
        PdfPTable leftTable = new PdfPTable(widthOne);
        leftTable.setWidthPercentage(35.0f);
        leftTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //
        if (company != null) {
            ch = new Chunk("Company\n", fntb);
            phrase = new Phrase();
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
            phrase = new Phrase();
            ch = new Chunk(company.getName() + "\n", fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
        }
        if (contact != null) {
            phrase = new Phrase();
            ch = new Chunk(contact.getFullName(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
            phrase = new Phrase();
            ch = new Chunk(contact.getAddress(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
            ch = new Chunk(contact.getCityStateZip(), fnt);
            phrase = new Phrase();
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
        }
        table.addCell(leftTable);
        //
        // middle cell
        //
        cell = new PdfPCell(new Phrase(spacer, fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //
        float[] widths2 = { 50f, 50f }; // percentages
        PdfPTable rightTable = new PdfPTable(widths2);
        rightTable.setWidthPercentage(35.0f);
        rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //
        ch = new Chunk("Invoice No.", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk(invoice.getInvoice_num(), fnt);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk("Status", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk(invoice.getStatus(), fnt);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk("Invoice Date", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk(invoice.getDate(), fnt);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk("From ", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        ch = new Chunk(invoice.getStart_date(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk("To ", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        ch = new Chunk(invoice.getEnd_date(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        table.addCell(rightTable);
        //
        //
        document.add(table);
        //
        phrase = new Phrase(new Chunk(spacer, fnt));
        document.add(phrase);
        //
        int jj = 0;
        if (pages != null) {
            for (Page page : pages) {
                jj++;
                // float[] widthOne = {100f};
                PdfPTable borderTable = new PdfPTable(widthOne);
                borderTable.setWidthPercentage(100.0f);
                borderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                float[] widthTwo = { 50f, 50f };
                PdfPTable titleTable = new PdfPTable(widthTwo);
                titleTable.setWidthPercentage(75.0f);
                titleTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                phrase = new Phrase("Invoice No. ", fntb);
                ch = new Chunk(invoice.getInvoice_num(), fnt);
                phrase.add(ch);
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
                cell.setBorder(Rectangle.NO_BORDER);
                titleTable.addCell(cell);
                //
                phrase = new Phrase(page.getPage_num(), fnt);
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
                cell.setBorder(Rectangle.NO_BORDER);
                titleTable.addCell(cell);
                //
                borderTable.addCell(titleTable);
                float[] width4 = { 25f, 40f, 25f, 10f };
                PdfPTable contTable = new PdfPTable(width4);
                cell = new PdfPCell(new Phrase("Excavation Permit Number", fntb));
                contTable.addCell(cell);
                cell = new PdfPCell(new Phrase("Project", fntb));
                contTable.addCell(cell);
                cell = new PdfPCell(new Phrase("Date Issued", fntb));
                contTable.addCell(cell);
                cell = new PdfPCell(new Phrase("Permit Fee", fntb));
                contTable.addCell(cell);
                List<Permit> permits = page.getPermits();
                if (permits != null) {
                    for (Permit permit : permits) {
                        cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt));
                        contTable.addCell(cell);
                        phrase = new Phrase(permit.getProject() + "\n", fnt);
                        List<Excavation> cuts = permit.getExcavations();
                        if (cuts != null) {
                            for (Excavation one : cuts) {
                                ch = new Chunk(one.getAddress() + " (" + one.getCut_type() + ")", fnt);
                                phrase.add(ch);
                            }
                        }
                        cell = new PdfPCell(phrase);
                        contTable.addCell(cell);
                        cell = new PdfPCell(new Phrase(permit.getDate(), fnt));
                        contTable.addCell(cell);
                        cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt));
                        cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
                        contTable.addCell(cell);
                        cell = new PdfPCell(new Phrase(spacer, fnt));
                        //
                        // space line
                        cell.setColspan(4);
                        contTable.addCell(cell);
                    }
                }
                if (page.getNeededLines() > 0) { // first page 
                    for (int j = 0; j < page.getNeededLines(); j++) {
                        cell = new PdfPCell(new Phrase(spacer, fnt));
                        contTable.addCell(cell);
                        contTable.addCell(cell);
                        contTable.addCell(cell);
                        contTable.addCell(cell);
                    }
                }
                if (jj == pages.size()) {
                    cell = new PdfPCell(new Phrase("Total Invoice Amount\n" + invoice.getTotal(), fntb));
                    cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
                    cell.setColspan(4);
                    contTable.addCell(cell);
                }
                borderTable.addCell(contTable);
                cell = new PdfPCell(new Phrase(
                        "Payment due upon receipt. Please Make check payable to 'City of Bloomington'. Thank You.",
                        fnt));

                cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
                cell.setBorder(Rectangle.NO_BORDER);
                borderTable.addCell(cell);
                borderTable.addCell(titleTable); // invoice and date
                document.add(borderTable);
                if (jj < pages.size()) {
                    document.newPage();
                }
            }
        }
        //
        document.close();
        writer.close();
        res.setHeader("Expires", "0");
        res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        //
        // if you want for users to download, uncomment the following line
        //
        // res.setHeader("Content-Disposition","attachment; filename="+fileName);         
        res.setHeader("Pragma", "public");
        //
        // setting the content type
        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) {
        logger.error(ex);
    }

}

From source file:permit.PermitPdf.java

License:Open Source License

/**
 * handles the letter header//  ww w . j ava2s .  co  m
 */
PdfPTable getHeader() {
    //
    String str = "";
    String spacer = "   ";
    //
    PdfPTable headTable = null;
    try {
        //
        // for http url use
        //
        Image image = Image.getInstance(url + "js/images/city_logo3.jpg");

        Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL);
        Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
        float[] widths = { 25f, 40f, 35f }; // percentages
        headTable = new PdfPTable(widths);
        headTable.setWidthPercentage(100);
        headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        // image.setWidthPercentage(33.0f);
        image.scalePercent(15f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        headTable.addCell(cell);
        //
        float[] width = { 33f };
        PdfPTable midTable = new PdfPTable(width);
        midTable.setWidthPercentage(33);
        midTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        midTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("City of Bloomington ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Planning and Transportation Department ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("bloomington.in.gov", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        headTable.addCell(midTable);
        //
        PdfPTable rightTable = new PdfPTable(width);
        rightTable.setWidthPercentage(33);
        rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        rightTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        phrase = new Phrase();
        ch = new Chunk("401 N Morton St Suite 130 ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("PO Box 100 \nBloomington, IN 47404", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\n Phone: (812) 349-3423\nFax (812) 349-3520\nEmail: planning@bloomington.in.gov",
                fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        headTable.addCell(rightTable);
    } catch (Exception ex) {
        logger.error(ex);
    }
    return headTable;
}

From source file:permit.PermitPdf.java

License:Open Source License

void writePage(HttpServletResponse res, Permit permit) {
    ////  www.  ja  v a 2s .c o m
    // paper size legal (A4) 8.5 x 11
    // page 1-inch = 72 points
    //
    String fileName = "row_permit_" + permit.getId() + ".pdf";
    Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11"
    Document document = new Document(pageSize, 36, 36, 18, 18);
    ServletOutputStream out = null;
    Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL);
    Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);
    Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
    String spacer = "   ";
    PdfPTable header = getHeader();
    Bond bond = permit.getBond();
    Invoice invoice = permit.getInvoice();
    if (bond == null)
        bond = new Bond();
    if (invoice == null)
        invoice = new Invoice();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        String str = "";
        document.open();
        document.add(header);
        //
        // title
        float[] width = { 100f }; // one cell
        PdfPTable table = new PdfPTable(width);
        table.setWidthPercentage(100.0f);
        PdfPCell cell = new PdfPCell(new Phrase("Right Of Way Excavation Permit", fntb));
        //         
        cell.setBorder(Rectangle.BOTTOM);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        document.add(table);
        //
        // we need these later
        Paragraph pp = new Paragraph();
        Chunk ch = new Chunk(" ", fntb);
        Phrase phrase = new Phrase();
        //
        float[] widths = { 14f, 20f, 17f, 18f, 13f, 20f }; // percentages
        table = new PdfPTable(widths);
        table.setWidthPercentage(100.0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //
        // first row
        cell = new PdfPCell(new Phrase("Company", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getCompany().getName(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Status", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getStatus(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Permit", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //
        // 2nd row
        //
        cell = new PdfPCell(new Phrase("Responsible", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getContact().getFullName(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Inspector", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getReviewer().getFullName(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Date Issued", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getDate(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //
        // 3rd row
        cell = new PdfPCell(new Phrase("Project", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getProject(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Permit Fee", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Start Date", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getStart_date(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //
        // 4th row
        cell = new PdfPCell(new Phrase("Bond Amount", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("$" + bond.getAmount(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Expiration Date", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(bond.getExpire_date(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Invoice", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(invoice.getStatus(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        document.add(table);
        //
        phrase = new Phrase(new Chunk(spacer, fnt));
        document.add(phrase);
        //
        float[] widths2 = { 25f, 15f, 15f, 25f, 10f, 10f };
        table = new PdfPTable(widths2);
        table.setWidthPercentage(100.0f);
        cell = new PdfPCell(new Phrase("Address", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Cut Type", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Utility", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Description", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Width", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Length", fntb));
        table.addCell(cell);
        List<Excavation> list = permit.getExcavations();
        if (list != null && list.size() > 0) {
            for (Excavation one : list) {
                cell = new PdfPCell(new Phrase(one.getAddress().getAddress(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getCut_type(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getUtility_type().getName(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getCut_description(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getWidth(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getLength(), fnt));
                table.addCell(cell);
            }
        }
        document.add(table);
        //
        pp = new Paragraph();
        pp.setIndentationLeft(12);
        pp.setAlignment(Element.ALIGN_LEFT);
        pp.setLeading(0f, 1f);
        ch = new Chunk("\nSpecial Provisions\n", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        ch = new Chunk(permit.getNotes() + "\n", fnt);
        phrase.add(ch);
        pp.add(phrase);
        document.add(pp);
        //
        pp = new Paragraph();
        pp.setIndentationLeft(12);
        pp.setAlignment(Element.ALIGN_LEFT);
        ch = new Chunk("Standards Conditions of Approval\n", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        pp.add(phrase);
        document.add(pp);
        //
        pp = new Paragraph();
        pp.setIndentationLeft(12);
        pp.setAlignment(Element.ALIGN_LEFT);
        pp.setLeading(0f, 1f);
        ch = new Chunk("1 - " + conditions[0] + "\n", fntbs);
        phrase = new Phrase();
        phrase.add(ch);
        pp.add(phrase);
        document.add(pp);
        //
        int jj = 1;
        for (int j = 1; j < conditions.length; j++) {
            jj = j + 1;
            pp = new Paragraph();
            pp.setLeading(0f, 1f);
            pp.setIndentationLeft(12);
            pp.setAlignment(Element.ALIGN_LEFT);
            ch = new Chunk(jj + " - " + conditions[j] + "\n", fnts);
            phrase = new Phrase();
            phrase.add(ch);
            pp.add(phrase);
            document.add(pp);
        }

        pp = new Paragraph();
        pp.setIndentationLeft(20);
        pp.setAlignment(Element.ALIGN_RIGHT);
        ch = new Chunk("\n\n___________________\n", fnt);
        phrase = new Phrase();
        phrase.add(ch);
        pp.add(phrase);
        ch = new Chunk(permit.getReviewer().getFullName(), fnt);
        phrase = new Phrase();
        phrase.add(ch);
        pp.add(phrase);
        document.add(pp);
        document.close();
        writer.close();
        res.setHeader("Expires", "0");
        res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        res.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        res.setHeader("Pragma", "public");
        //
        // setting the content type
        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) {
        logger.error(ex);
    }

}

From source file:permit.ReceiptPdf.java

License:Open Source License

void writePages(HttpServletResponse res, Receipt receipt) {
    ///*from   w w  w .  j a  v a  2s  .  c o m*/
    // paper size legal (A4) 8.5 x 11
    // page 1-inch = 72 points
    //
    Invoice invoice = receipt.getInvoice();
    String fileName = "row_receipt_" + receipt.getId() + ".pdf";
    Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11"
    Document document = new Document(pageSize, 36, 36, 18, 18);
    ServletOutputStream out = null;
    Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL);
    Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);
    Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
    String spacer = "   ";
    PdfPTable header = getHeader();
    Company company = invoice.getCompany();
    Contact contact = null;
    if (invoice.hasContact()) {
        contact = invoice.getContact();
    }
    List<Page> pages = invoice.getPages();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        String str = "";
        document.open();
        document.add(header);
        //
        // title
        float[] width = { 100f }; // one cell
        PdfPTable table = new PdfPTable(width);
        table.setWidthPercentage(100.0f);
        PdfPCell cell = new PdfPCell(new Phrase("RECEIPT", fntb));
        //         
        cell.setBorder(Rectangle.BOTTOM);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        document.add(table);
        //
        // we need these later
        Paragraph pp = new Paragraph();
        Chunk ch = new Chunk(" ", fntb);
        Phrase phrase = new Phrase();
        //
        float[] widths = { 35f, 30f, 35f }; // percentages
        table = new PdfPTable(widths);
        table.setWidthPercentage(100.0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //
        // first row
        float[] widthOne = { 100f };
        PdfPTable leftTable = new PdfPTable(widthOne);
        leftTable.setWidthPercentage(35.0f);
        leftTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //
        if (company != null) {
            ch = new Chunk("Company\n", fntb);
            phrase = new Phrase();
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
            phrase = new Phrase();
            ch = new Chunk(company.getName() + "\n", fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
        }
        if (contact != null) {
            phrase = new Phrase();
            ch = new Chunk(contact.getFullName(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
            phrase = new Phrase();
            ch = new Chunk(contact.getAddress(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
            ch = new Chunk(contact.getCityStateZip(), fnt);
            phrase = new Phrase();
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorder(Rectangle.NO_BORDER);
            leftTable.addCell(cell);
        }
        table.addCell(leftTable);
        //
        // middle cell
        //
        cell = new PdfPCell(new Phrase(spacer, fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //
        float[] widths2 = { 50f, 50f }; // percentages
        PdfPTable rightTable = new PdfPTable(widths2);
        rightTable.setWidthPercentage(35.0f);
        rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //
        ch = new Chunk("Receipt No.", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk(receipt.getId(), fnt);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk("Invoice No.", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk(invoice.getInvoice_num(), fnt);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk("Receipt Date", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk(receipt.getDate(), fnt);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk("Amount Paid $", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("$" + receipt.getAmount_paid(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        ch = new Chunk("Payment Method ", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk(receipt.getPayment_type(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        table.addCell(rightTable);
        //
        document.add(table);
        //
        phrase = new Phrase(new Chunk(spacer, fnt));
        document.add(phrase);
        //
        int jj = 0;
        if (pages != null) {
            for (Page page : pages) {
                jj++;
                PdfPTable borderTable = new PdfPTable(widthOne);
                borderTable.setWidthPercentage(100.0f);
                borderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                float[] widthTwo = { 50f, 50f };
                PdfPTable titleTable = new PdfPTable(widthTwo);
                titleTable.setWidthPercentage(75.0f);
                titleTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                phrase = new Phrase("Receipt Number ", fntb);
                ch = new Chunk(receipt.getId(), fnt);
                phrase.add(ch);
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
                cell.setBorder(Rectangle.NO_BORDER);
                titleTable.addCell(cell);
                //
                phrase = new Phrase(page.getPage_num(), fnt);
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
                cell.setBorder(Rectangle.NO_BORDER);
                titleTable.addCell(cell);
                //
                borderTable.addCell(titleTable);
                float[] width4 = { 25f, 40f, 25f, 10f };
                PdfPTable contTable = new PdfPTable(width4);
                cell = new PdfPCell(new Phrase("Excavation Permit Number", fntb));
                contTable.addCell(cell);
                cell = new PdfPCell(new Phrase("Project", fntb));
                contTable.addCell(cell);
                cell = new PdfPCell(new Phrase("Date Issued", fntb));
                contTable.addCell(cell);
                cell = new PdfPCell(new Phrase("Permit Fee", fntb));
                contTable.addCell(cell);
                List<Permit> permits = page.getPermits();
                if (permits != null) {
                    for (Permit permit : permits) {
                        cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt));
                        contTable.addCell(cell);
                        phrase = new Phrase(permit.getProject() + "\n", fnt);
                        List<Excavation> cuts = permit.getExcavations();
                        if (cuts != null) {
                            for (Excavation one : cuts) {
                                ch = new Chunk(one.getAddress() + " (" + one.getCut_type() + ")", fnt);
                                phrase.add(ch);
                            }
                        }
                        cell = new PdfPCell(phrase);
                        contTable.addCell(cell);
                        cell = new PdfPCell(new Phrase(permit.getDate(), fnt));
                        contTable.addCell(cell);
                        cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt));
                        cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
                        contTable.addCell(cell);
                        cell = new PdfPCell(new Phrase(spacer, fnt));
                        //
                        // space line
                        //
                        cell.setColspan(4);
                        contTable.addCell(cell);
                    }
                }
                if (page.getNeededLines() > 0) { // first page 
                    for (int j = 0; j < page.getNeededLines(); j++) {
                        cell = new PdfPCell(new Phrase(spacer, fnt));
                        contTable.addCell(cell);
                        contTable.addCell(cell);
                        contTable.addCell(cell);
                        contTable.addCell(cell);
                    }
                }
                if (jj == pages.size()) {
                    cell = new PdfPCell(new Phrase("Total Invoice Amount\n" + invoice.getTotal(), fntb));
                    cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
                    cell.setColspan(4);
                    contTable.addCell(cell);
                }
                borderTable.addCell(contTable);
                cell = new PdfPCell(new Phrase("Thank You.", fnt));

                cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
                cell.setBorder(Rectangle.NO_BORDER);
                borderTable.addCell(cell);
                borderTable.addCell(titleTable); // receipt and date
                document.add(borderTable);
                if (jj < pages.size()) {
                    document.newPage();
                }
            }
        }
        //
        document.close();
        writer.close();
        res.setHeader("Expires", "0");
        res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        // res.setHeader("Content-Disposition","attachment; filename="+fileName);         
        res.setHeader("Pragma", "public");
        //
        // setting the content type
        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) {
        logger.error(ex);
    }

}

From source file:pruebareportes.rptEmpleadosSinMarcar.java

public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException {
    /**//  w  ww . j a  v a  2s  . c  o m
     * Procesamiento para info para generar tablas
     */
    //List<RegistroAsistencia> registros = rg.buscarXEmpleadoXFecha1(dnis, fechaInicio, fechaFin);
    Calendar fechaInicioC = Calendar.getInstance();
    Calendar fechaFinC = Calendar.getInstance();
    fechaInicioC.setTime(fechaInicio);
    fechaFinC.setTime(fechaFin);

    int diaMesInicio, diaMesFin;
    diaMesInicio = fechaInicioC.get(Calendar.DAY_OF_MONTH);
    diaMesFin = fechaFinC.get(Calendar.DAY_OF_MONTH);
    //Definir numero de columnas de dias
    //        ArrayList<Integer> listaInt = new ArrayList<Integer>();
    //        Calendar fechaRegistro = Calendar.getInstance();
    //        for(RegistroAsistencia registro:registros){
    //            fechaRegistro.setTime(registro.getFecha());
    //            Integer diaRegistro = fechaRegistro.get(Calendar.DAY_OF_MONTH);
    //            if(listaInt.contains(diaRegistro)!=true){
    //                if(diaRegistro>=diaMesInicio && diaRegistro<=diaMesFin){
    //                    listaInt.add(diaRegistro);
    //                }
    //            }
    //        }
    //Ordenamos arraylist
    //        int indice,menor,aux;
    //        for (int i = 0; i < listaInt.size(); i++) {
    //            menor = listaInt.get(i);
    //            indice = i;
    //            aux=0;
    //            for (int j = i+1; j < listaInt.size(); j++) {
    //                aux = listaInt.get(j);
    //                indice = aux < menor ? j : indice;
    //                menor = aux < menor ? aux : menor;
    //            }
    //            listaInt.set(indice, listaInt.get(i));
    //            listaInt.set(i,menor);
    //        }
    /**
     * Procesamiento para elaborar tabla con datos
     */
    int nroColumnas = 1;
    PdfPTable tabla = new PdfPTable(nroColumnas);
    tabla.setWidthPercentage(100);
    //Asignamos los tamaos a las columnas
    //        int[] widthColumna = new int[nroColumnas];
    //        for (int i = 0; i < nroColumnas; i++) {
    //            if(i==0){
    //                widthColumna[i]=6;
    //            }else if(i==(nroColumnas-1)){
    //                widthColumna[i]=2;
    //            }else{
    //                widthColumna[i]=1;
    //            }
    //        }
    //        tabla.setWidths(widthColumna);
    //Definimos celdas iniciales
    Font fontCabecera = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Font fontCelda = new Font(Font.TIMES_ROMAN, 9);
    PdfPCell h1 = new PdfPCell(new Phrase("Nombre del empleado", fontCabecera));
    h1.setHorizontalAlignment(3);
    h1.setGrayFill(0.7f);
    h1.setRowspan(1);
    h1.setColspan(1);
    tabla.addCell(h1);

    //        PdfPCell h2 = new PdfPCell(new Phrase("Das Hbiles",fontCabecera));
    //        h2.setHorizontalAlignment(1);
    //        h2.setGrayFill(0.7f);
    //        h2.setColspan(nroColumnas-2);
    //        tabla.addCell(h2);
    //        
    //        PdfPCell h3 = new PdfPCell(new Phrase("Total (minutos)",fontCabecera));
    //        h3.setHorizontalAlignment(3);
    //        h3.setGrayFill(0.7f);
    //        h3.setColspan(1);
    //        h3.setRowspan(2);
    //        tabla.addCell(h3);

    //        PdfPCell diaColumna = new PdfPCell();
    //        for (int i = 0; i < (nroColumnas-2); i++) {
    //            String celda = (listaInt.get(i).toString());
    //            diaColumna.setPhrase(new Phrase(celda,fontCabecera));
    //            diaColumna.setHorizontalAlignment(1);
    //            tabla.addCell(diaColumna);
    //        }
    Calendar cal = Calendar.getInstance();
    List<Integer> conteoDias = new ArrayList<Integer>();

    //        for (int i = 0; i < dnis.size(); i++) {
    //            
    //            List<Empleado> listaEmpleado = new ArrayList<Empleado>();
    //            listaEmpleado = em.buscarXPatron(dnis.get(i));
    //            Empleado empleado = new Empleado();
    //            empleado = listaEmpleado.get(0);
    //            BigDecimal totalTardanza= new BigDecimal(0.00);
    //            PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getApellidoPaterno()+" "+empleado.getApellidoMaterno()+" "+empleado.getNombre(),fontCelda));
    //            celdaNombre.setHorizontalAlignment(0);
    //            tabla.addCell(celdaNombre);
    //            List<RegistroAsistencia> registrosDni = rg.buscarXEmpleadoXFecha2(dnis.get(i), fechaInicio, fechaFin);
    //            System.out.println("Numero de registros: "+registrosDni.size());
    //            
    ////            for (RegistroAsistencia registro : registrosDni) {
    ////                cal.setTime(registro.getFecha());
    ////                for (int j = 0; j < listaInt.size(); j++) {
    ////                    if(cal.get(Calendar.DAY_OF_MONTH)==listaInt.get(j)){
    ////                        if(registro.getMinTardanza()!=null){
    ////                            int numero = registro.getMinTardanza().intValue();
    ////                            String celda = ""+numero;
    ////                            celdaNombre.setPhrase(new Phrase(celda,fontCelda));
    ////                            celdaNombre.setHorizontalAlignment(1);
    ////                            tabla.addCell(celdaNombre);                       
    ////                            totalTardanza = totalTardanza.add(registro.getMinTardanza());
    ////                        }else{
    ////                            String celda = "0.0";
    ////                            celdaNombre.setPhrase(new Phrase(celda,fontCelda));
    ////                            celdaNombre.setHorizontalAlignment(1);
    ////                            tabla.addCell(celdaNombre);
    ////                        }
    ////                        conteoDias.add(listaInt.get(j));
    ////                        break;
    ////                    }else{
    ////                        if(conteoDias.contains(listaInt.get(j))){
    ////                            
    ////                        }else{
    ////                            String celda = "n.r";
    ////                            celdaNombre.setPhrase(new Phrase(celda,fontCelda));
    ////                            celdaNombre.setHorizontalAlignment(1);
    ////                            tabla.addCell(celdaNombre);
    ////                            conteoDias.add(listaInt.get(j));
    ////                        }                       
    ////                    }
    ////                }
    ////            }
    ////            if(registrosDni.size()<(nroColumnas-2)){
    ////                int dfNumRegistros = (nroColumnas-2)-registrosDni.size();
    ////                for (int j = 0; j < dfNumRegistros; j++) {
    ////                    String celda = "n.r";
    ////                    celdaNombre.setPhrase(new Phrase(celda,fontCelda));
    ////                    celdaNombre.setHorizontalAlignment(1);
    ////                    tabla.addCell(celdaNombre);
    ////                }
    ////            }
    //           
    //            
    ////            System.out.println("ConteoDias: "+conteoDias.size());
    ////            System.out.println("Total tardanzas: "+totalTardanza);
    ////            conteoDias.clear();
    ////            String tardanzaTotal = totalTardanza.toString();
    ////            celdaNombre.setPhrase(new Phrase(tardanzaTotal,fontCelda));
    ////            celdaNombre.setHorizontalAlignment(1);
    ////            tabla.addCell(celdaNombre);
    //        }
    return tabla;
}