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

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

Introduction

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

Prototype

public void setBorder(int border) 

Source Link

Document

Enables/Disables the border on the specified sides.

Usage

From source file:org.unitime.timetable.export.PDFPrinter.java

License:Open Source License

@Override
public void printLine(String... fields) {
    PdfPCellEvent setLineDashEvent = new PdfPCellEvent() {
        @Override//from  w ww. j a  va  2s .c  o m
        public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
            PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
            cb.setLineDash(new float[] { 2, 2 }, 0);
        }
    };

    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        String f = fields[idx];
        if (f == null || f.isEmpty() || (iCheckLast
                && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx])))
            f = "";

        boolean number = sNumber.matcher(f).matches();

        Font font = PdfFont.getFont();
        Phrase p = new Phrase(f, PdfFont.getSmallFont());

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(iLastLine == null ? Rectangle.TOP : Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(number ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT);
        cell.setPaddingBottom(4f);
        cell.setCellEvent(setLineDashEvent);
        if (number)
            cell.setPaddingRight(10f);
        iTable.addCell(cell);

        float width = 0;
        if (f.indexOf('\n') >= 0) {
            for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();)
                width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
        } else
            width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize()));
        iMaxWidth[idx] = Math.max(iMaxWidth[idx], width + (number ? 10 : 0));
    }
    iLastLine = fields;
}

From source file:org.unitime.timetable.webutil.PdfWebTable.java

License:Open Source License

private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color,
        boolean borderTop, boolean borderBottom, boolean borderLeft, boolean borderRight, Color borderColor,
        Color bgColor) {/*w ww  .  j av  a 2  s  .  co  m*/

    cell.setBorderWidth(1);

    if (borderTop) {
        cell.setBorder(PdfPCell.TOP);
        if (borderColor == null)
            cell.setBorderColorTop(Color.BLACK);
        else
            cell.setBorderColorTop(borderColor);
    }

    if (borderBottom) {
        cell.setBorder(PdfPCell.BOTTOM);
        if (borderColor == null)
            cell.setBorderColorBottom(Color.BLACK);
        else
            cell.setBorderColorBottom(borderColor);
    }

    if (borderLeft) {
        cell.setBorder(PdfPCell.LEFT);
        if (borderColor == null)
            cell.setBorderColorLeft(Color.BLACK);
        else
            cell.setBorderColorLeft(borderColor);
    }

    if (borderRight) {
        cell.setBorder(PdfPCell.RIGHT);
        if (borderColor == null)
            cell.setBorderColorRight(Color.BLACK);
        else
            cell.setBorderColorRight(borderColor);
    }

    return addText(cell, text, bold, italic, underline, color, bgColor);
}

From source file:org.unitime.timetable.webutil.PdfWebTable.java

License:Open Source License

private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color,
        boolean border, Color borderColor, Color bgColor) {

    if (border) {
        cell.setBorderWidth(1);/*from w  w w. ja v a2s.c  om*/
        cell.setBorder(PdfPCell.RIGHT | PdfPCell.LEFT | PdfPCell.TOP | PdfPCell.BOTTOM);
        if (borderColor == null)
            cell.setBorderColor(Color.BLACK);
        else
            cell.setBorderColor(borderColor);
    }

    return addText(cell, text, bold, italic, underline, color, bgColor);
}

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

License:Open Source License

/**
 * Creates and adds the table at the top of the document
 * which contains the consultation request.
 *///from w  ww  . j a va  2  s . com
private void createConsultationRequest() throws DocumentException {

    float[] tableWidths = { 1f, 1f };
    PdfPTable table = new PdfPTable(1);
    PdfPCell cell;
    PdfPTable border, border2, border1;
    table.setWidthPercentage(95);

    // Creating a border for the entire request.
    border = new PdfPTable(1);
    addToTable(table, border, true);

    if (props.getProperty("faxLogoInConsultation") != null) {
        // Creating container for logo and clinic information table.
        border1 = new PdfPTable(tableWidths);
        addTable(border, border1);

        // Adding fax logo
        PdfPTable infoTable = createLogoHeader();
        addToTable(border1, infoTable, false);

        // Adding clinic information to the border.
        infoTable = createClinicInfoHeader();
        addToTable(border1, infoTable, false);

    } else {
        // Adding clinic information to the border.
        PdfPTable infoTable = createClinicInfoHeader();
        addTable(border, infoTable);
    }

    // Add reply info 
    PdfPTable infoTable = createReplyHeader();
    addTable(border, infoTable);

    // Creating container for specialist and patient table.
    border2 = new PdfPTable(tableWidths);
    addTable(border, border2);

    // Adding specialist info to container.
    infoTable = createSpecialistTable();
    addToTable(border2, infoTable, true);

    // Adding patient info to main table.
    infoTable = createPatientTable();
    addToTable(border2, infoTable, true);

    // Creating a table with details for the consultation request.
    infoTable = createConsultDetailTable();

    // Adding promotional information if appropriate.
    if (props.getProperty("FORMS_PROMOTEXT") != null) {
        cell = new PdfPCell(new Phrase(props.getProperty(""), font));
        cell.setBorder(0);
        infoTable.addCell(cell);
        cell.setPhrase(new Phrase(props.getProperty("FORMS_PROMOTEXT"), font));
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        infoTable.addCell(cell);
    }

    // Adding details and promotional information.
    addTable(border, infoTable);

    document.add(table);
}

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

License:Open Source License

/**
 * Add's the table 'add' to the table 'main'.
 * @param main the host table//from   w  w  w .j  a  v a 2  s. co m
 * @param add the table being added
 * @param border true if a border should surround the table being added
 * @return the cell containing the table being added to the main table.    *
 */
private PdfPCell addToTable(PdfPTable main, PdfPTable add, boolean border) {
    PdfPCell cell;
    cell = new PdfPCell(add);
    if (!border) {
        cell.setBorder(0);
    }
    cell.setPadding(3);
    cell.setColspan(1);
    main.addCell(cell);
    return cell;
}

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

License:Open Source License

private PdfPTable createLogoHeader() {
    float[] tableWidths;
    PdfPCell cell = new PdfPCell();
    //tableWidths = new float[]{ 1.5f, 2.5f };
    //PdfPTable infoTable = new PdfPTable(tableWidths);
    PdfPTable infoTable = new PdfPTable(1);
    try {//  w  w  w  .  ja  va2 s  . c  o m
        String filename = "";
        if (props.getProperty("multisites") != null && "on".equalsIgnoreCase(props.getProperty("multisites"))) {
            DocumentDAO documentDao = (DocumentDAO) SpringUtils.getBean("documentDAO");
            SiteDao siteDao = (SiteDao) SpringUtils.getBean("siteDao");
            Site site = siteDao.getByLocation(reqFrm.siteName);
            if (site != null) {
                if (site.getSiteLogoId() != null) {
                    org.oscarehr.document.model.Document d = documentDao
                            .getDocument(String.valueOf(site.getSiteLogoId()));
                    String dir = props.getProperty("DOCUMENT_DIR");
                    filename = dir.concat(d.getDocfilename());
                } else {
                    //If no logo file uploaded for this site, use the default one defined in oscar properties file.
                    filename = props.getProperty("faxLogoInConsultation");
                }
            }
        } else {
            filename = props.getProperty("faxLogoInConsultation");
        }

        FileInputStream fileInputStream = new FileInputStream(filename);
        byte[] faxLogImage = new byte[1024 * 256];
        fileInputStream.read(faxLogImage);
        Image image = Image.getInstance(faxLogImage);
        image.scalePercent(80f);
        image.setBorder(0);
        cell = new PdfPCell(image);
        cell.setBorder(0);
        infoTable.addCell(cell);
    } catch (Exception e) {
        logger.error("Unexpected error.", e);
    }

    // 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.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java

License:Open Source License

private PdfPTable createReplyHeader() {

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

    cell = new PdfPCell(new Phrase("", headerFont));
    cell.setBorder(0);
    cell.setPaddingLeft(25);//from w ww . j a v  a2s . c o m
    infoTable.addCell(cell);

    cell.setPhrase(new Phrase(getResource("msgConsReq"), bigBoldFont));
    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.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/*ww w  .  j  av  a  2 s  .co  m*/
 */
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.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java

License:Open Source License

/**
 * Creates the table containing information about the specialist.
 * @return the table produced/* w  ww .j a  v  a 2  s.  c  o m*/
 */
private PdfPTable createSpecialistTable() {
    float[] tableWidths;
    PdfPCell cell = new PdfPCell();
    tableWidths = new float[] { 1.5f, 2.5f };
    PdfPTable infoTable = new PdfPTable(tableWidths);

    infoTable.addCell(setInfoCell(cell, getResource("msgDate")));
    infoTable.addCell(setDataCell(cell, reqFrm.pwb.equals("1") ? getResource("pwb") : reqFrm.referalDate));

    infoTable.addCell(setInfoCell(cell, getResource("msgStatus")));
    infoTable.addCell(setDataCell(cell,
            (reqFrm.urgency.equals("1") ? getResource("msgUrgent")
                    : (reqFrm.urgency.equals("2") ? getResource("msgNUrgent")
                            : (reqFrm.urgency.equals("3")) ? getResource("msgReturn") : "  "))));

    infoTable.addCell(setInfoCell(cell, getResource("msgService")));
    infoTable.addCell(setDataCell(cell, reqFrm.getServiceName(reqFrm.service)));

    infoTable.addCell(setInfoCell(cell, getResource("msgConsultant")));
    infoTable.addCell(setDataCell(cell, reqFrm.getSpecailistsName(reqFrm.specialist)));

    infoTable.addCell(setInfoCell(cell, getResource("msgPhone")));
    if ((reqFrm.getSpecailistsName(reqFrm.specialist).equals("-1"))
            || (reqFrm.getSpecailistsName(reqFrm.specialist).equals(null))
            || (reqFrm.getSpecailistsName(reqFrm.specialist).equals(""))) {
        infoTable.addCell(setDataCell(cell, ""));
    } else {
        infoTable.addCell(setDataCell(cell, reqFrm.specPhone));
    }

    infoTable.addCell(setInfoCell(cell, getResource("msgFax")));
    if ((reqFrm.getSpecailistsName(reqFrm.specialist).equals("-1"))
            || (reqFrm.getSpecailistsName(reqFrm.specialist).equals(null))
            || (reqFrm.getSpecailistsName(reqFrm.specialist).equals(""))) {
        infoTable.addCell(setDataCell(cell, ""));
    } else {
        infoTable.addCell(setDataCell(cell, reqFrm.specFax));
    }

    infoTable.addCell(setInfoCell(cell, getResource("msgAddr")));
    if ((reqFrm.getSpecailistsName(reqFrm.specialist).equals("-1"))
            || (reqFrm.getSpecailistsName(reqFrm.specialist).equals(null))
            || (reqFrm.getSpecailistsName(reqFrm.specialist).equals(""))) {
        infoTable.addCell(setDataCell(cell, ""));
    } else {
        infoTable.addCell(setDataCell(cell, divy(reqFrm.specAddr)));
    }

    // 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.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java

License:Open Source License

/**
 * Creates the table containing information about the patient.
 * @return the table produced//  w  w  w . j  av a2s .  c  o  m
 */
private PdfPTable createPatientTable() {
    float[] tableWidths;
    PdfPCell cell;
    tableWidths = new float[] { 2, 2.5f };
    PdfPTable infoTable = new PdfPTable(tableWidths);
    cell = new PdfPCell();
    infoTable.addCell(setInfoCell(cell, getResource("msgPat")));
    infoTable.addCell(setDataCell(cell, reqFrm.patientName));

    infoTable.addCell(setInfoCell(cell, getResource("msgAddr")));
    infoTable.addCell(setDataCell(cell, divy(reqFrm.patientAddress)));

    infoTable.addCell(setInfoCell(cell, getResource("msgPhone")));
    infoTable.addCell(setDataCell(cell, reqFrm.patientPhone));

    infoTable.addCell(setInfoCell(cell, getResource("msgWPhone")));
    infoTable.addCell(setDataCell(cell, reqFrm.patientWPhone));

    infoTable.addCell(setInfoCell(cell, getResource("msgBirth")));
    infoTable.addCell(setDataCell(cell, reqFrm.patientDOB + " (y/m/d)"));

    infoTable.addCell(setInfoCell(cell, getResource("msgCard")));
    infoTable.addCell(setDataCell(cell, String.format("(%s) %s %s", reqFrm.patientHealthCardType,
            reqFrm.patientHealthNum, reqFrm.patientHealthCardVersionCode)));

    if (!reqFrm.pwb.equals("1")) {
        infoTable.addCell(setInfoCell(cell, getResource("msgappDate")));
        if (!StringUtils.isBlank(reqFrm.appointmentYear)) {
            infoTable.addCell(setDataCell(cell,
                    reqFrm.pwb.equals("1") ? getResource("pwb")
                            : String.format("%s/%s/%s (y/m/d)", reqFrm.appointmentYear, reqFrm.appointmentMonth,
                                    reqFrm.appointmentDay)));
        } else {
            infoTable.addCell(setDataCell(cell, reqFrm.pwb.equals("1") ? getResource("pwb") : ""));
        }
        infoTable.addCell(setInfoCell(cell, getResource("msgTime")));
        if (!StringUtils.isBlank(reqFrm.appointmentHour)) {
            infoTable.addCell(setDataCell(cell, String.format("%s:%s %s", reqFrm.appointmentHour,
                    reqFrm.appointmentMinute, reqFrm.appointmentPm)));
        } else {
            infoTable.addCell(setDataCell(cell, ""));
        }

    }

    infoTable.addCell(setInfoCell(cell, getResource("msgChart")));
    infoTable.addCell(setDataCell(cell, reqFrm.patientChartNo));

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