Example usage for com.lowagie.text Element ALIGN_LEFT

List of usage examples for com.lowagie.text Element ALIGN_LEFT

Introduction

In this page you can find the example usage for com.lowagie.text Element ALIGN_LEFT.

Prototype

int ALIGN_LEFT

To view the source code for com.lowagie.text Element ALIGN_LEFT.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:org.unitime.timetable.webutil.timegrid.PdfExamGridTable.java

License:Open Source License

private void addLegendRow(String color, String text) {
    PdfPCell c = createCellNoBorder();/*from w  w w . j  av  a 2 s.c  o  m*/
    c.setBorderWidth(1);
    c.setBackgroundColor(getColor(color));
    iPdfTable.addCell(c);
    c = createCellNoBorder();
    addText(c, "  " + text);
    c.setHorizontalAlignment(Element.ALIGN_LEFT);
    iPdfTable.addCell(c);
}

From source file:org.unitime.timetable.webutil.timegrid.PdfExamGridTable.java

License:Open Source License

public void printLegend() throws Exception {
    iPdfTable = new PdfPTable(2);
    iPdfTable.setWidths(new float[] { 10f, 200f });
    iPdfTable.getDefaultCell().setPadding(3);
    iPdfTable.getDefaultCell().setBorderWidth(1);
    iPdfTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    iPdfTable.setSplitRows(false);/*from  ww  w .  j  a  v  a2s.  c  o  m*/
    iPdfTable.setSpacingBefore(10);
    iPdfTable.setKeepTogether(true);

    if (iForm.getBackground() != sBgNone) {
        PdfPCell c = createCellNoBorder();
        c.setColspan(2);
        addText(c, "Assigned examinations:");
        c.setHorizontalAlignment(Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (iForm.getBackground() == sBgPeriodPref) {
        addLegendRow(pref2color(PreferenceLevel.sRequired), "Required period");
        addLegendRow(pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred period");
        addLegendRow(pref2color(PreferenceLevel.sPreferred), "Preferred period");
        addLegendRow(pref2color(PreferenceLevel.sNeutral), "No period preference");
        addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "Discouraged period");
        addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged period");
        addLegendRow(pref2color(PreferenceLevel.sProhibited), "Prohibited period");
    } else if (iForm.getBackground() == sBgRoomPref) {
        addLegendRow(pref2color(PreferenceLevel.sRequired), "Required room");
        addLegendRow(pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred room");
        addLegendRow(pref2color(PreferenceLevel.sPreferred), "Preferred room");
        addLegendRow(pref2color(PreferenceLevel.sNeutral), "No room preference");
        addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "Discouraged room");
        addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged room");
        addLegendRow(pref2color(PreferenceLevel.sProhibited), "Prohibited room");
    } else if (iForm.getBackground() == sBgInstructorConfs) {
        addLegendRow(pref2color(PreferenceLevel.sNeutral), "No instructor conflict");
        addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "One or more instructor back-to-back conflicts");
        addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged),
                "One or more instructor three or more exams a day conflicts");
        addLegendRow(pref2color(PreferenceLevel.sProhibited), "One or more instructor direct conflicts");
    } else if (iForm.getBackground() == sBgStudentConfs) {
        addLegendRow(pref2color(PreferenceLevel.sNeutral), "No student conflict");
        addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "One or more student back-to-back conflicts");
        addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged),
                "One or more student three or more exams a day student conflicts");
        addLegendRow(pref2color(PreferenceLevel.sProhibited), "One or more student direct conflicts");
    } else if (iForm.getBackground() == sBgDirectInstructorConfs) {
        for (int nrConflicts = 0; nrConflicts <= 6; nrConflicts++) {
            String color = lessConflicts2color(nrConflicts);
            addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 6 ? "or more " : "")
                    + "instructor direct conflicts");
        }
    } else if (iForm.getBackground() == sBgMoreThanTwoADayInstructorConfs) {
        for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) {
            String color = conflicts2color(nrConflicts);
            addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "")
                    + "instructor more than two exams a day conflicts");
        }
    } else if (iForm.getBackground() == sBgBackToBackInstructorConfs) {
        for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) {
            String color = conflicts2color(nrConflicts);
            addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "")
                    + "instructor back to back conflicts");
        }
    } else if (iForm.getBackground() == sBgDirectStudentConfs) {
        for (int nrConflicts = 0; nrConflicts <= 6; nrConflicts++) {
            String color = lessConflicts2color(nrConflicts);
            addLegendRow(color,
                    "" + nrConflicts + " " + (nrConflicts == 6 ? "or more " : "") + "student direct conflicts");
        }
    } else if (iForm.getBackground() == sBgMoreThanTwoADayStudentConfs) {
        for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) {
            String color = conflicts2color(nrConflicts);
            addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "")
                    + "student more than two exams a day conflicts");
        }
    } else if (iForm.getBackground() == sBgBackToBackStudentConfs) {
        for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) {
            String color = conflicts2color(nrConflicts);
            addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "")
                    + "student back to back conflicts");
        }
    } else if (iForm.getBackground() == sBgDistPref) {
        addLegendRow(pref2color(PreferenceLevel.sNeutral), "No violated constraint<i>(distance=0)</i>");
        addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "Discouraged/preferred constraint violated");
        addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged),
                "Strongly discouraged/preferred constraint violated</i>");
        addLegendRow(pref2color(PreferenceLevel.sProhibited), "Required/prohibited constraint violated</i>");
    }
    PdfPCell c = createCellNoBorder();
    c.setColspan(2);
    addText(c, "Free times:");
    c.setHorizontalAlignment(Element.ALIGN_LEFT);
    iPdfTable.addCell(c);
    addLegendRow(sBgColorNotAvailable, "Period not available");
    if (iForm.getBgPreferences() && iForm.getBackground() == sBgPeriodPref) {
        addLegendRow(pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred period");
        addLegendRow(pref2color(PreferenceLevel.sPreferred), "Preferred period");
    }
    addLegendRow(pref2color(PreferenceLevel.sNeutral), "No period preference");
    if (iForm.getBgPreferences() && iForm.getBackground() == sBgPeriodPref) {
        addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "Discouraged period");
        addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged period");
        addLegendRow(pref2color(PreferenceLevel.sProhibited), "Prohibited period");
    }

    iDocument.add(iPdfTable);
}

From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java

License:Open Source License

public void printLegend() throws Exception {
    iPdfTable = new PdfPTable(2);
    iPdfTable.setWidths(new float[] { 10f, 200f });
    iPdfTable.getDefaultCell().setPadding(3);
    iPdfTable.getDefaultCell().setBorderWidth(1);
    iPdfTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    iPdfTable.setSplitRows(false);//from  w w w.j av a  2 s . co m
    iPdfTable.setSpacingBefore(10);
    iPdfTable.setKeepTogether(true);

    if (iTable.getBgMode() != TimetableGridModel.sBgModeNone) {
        PdfPCell c = createCellNoBorder();
        c.setColspan(2);
        addText(c, "Assigned classes:");
        c.setHorizontalAlignment(Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (iTable.getBgMode() == TimetableGridModel.sBgModeTimePref) {
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required time");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred),
                "Strongly preferred time");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred), "Preferred time");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No time preference");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged time");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged),
                "Strongly discouraged time");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Prohibited time");
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModeRoomPref) {
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred),
                "Strongly preferred room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred), "Preferred room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No room preference");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged),
                "Strongly discouraged room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Prohibited room");
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModeStudentConf) {
        for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) {
            String color = TimetableGridCell.conflicts2color(nrConflicts);
            addLegendRow(color,
                    "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "") + "student conflicts");
        }
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModeInstructorBtbPref) {
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral),
                "No instructor back-to-back preference (distance=0)");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged),
                "Discouraged back-to-back (0<distance<=5)");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged),
                "Strongly discouraged back-to-back (5<distance<=20)");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited),
                "Prohibited back-to-back (20<distance)");
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModeDistributionConstPref) {
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral),
                "No violated constraint(distance=0)");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged),
                "Discouraged/preferred constraint violated");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged),
                "Strongly discouraged/preferred constraint violated");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited),
                "Required/prohibited constraint violated");
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModePerturbations) {
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "No change");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No initial assignment");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Room changed");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Time changed");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Both time and room changed");
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModePerturbationPenalty) {
        for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) {
            String color = TimetableGridCell.conflicts2color(nrConflicts);
            addLegendRow(color,
                    "" + (nrConflicts == 0 ? "Zero perturbation penalty"
                            : nrConflicts == 15 ? "Perturbation penalty above 15"
                                    : "Perturbation penalty below or equal to " + nrConflicts)
                            + "");
        }
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModeHardConflicts) {
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required time and room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred),
                "Can be moved in room with no hard conflict");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred),
                "Can be moved in room (but there is a hard conflict), can be moved in time with no conflict");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral),
                "Can be moved in room (but there is a hard conflict)");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged),
                "Can be moved in time with no hard conflict, cannot be moved in room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged),
                "Can be moved in time (but there is a hard conflict), cannot be moved in room");
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModeDepartmentalBalancing) {
        for (int nrConflicts = 0; nrConflicts <= 3; nrConflicts++) {
            String color = TimetableGridCell.conflicts2colorFast(nrConflicts);
            addLegendRow(color,
                    "" + (nrConflicts == 0 ? "Zero penalty"
                            : nrConflicts == 3 ? "Penalty equal or above 3" : "Penalty equal to " + nrConflicts)
                            + "");
        }
    } else if (iTable.getBgMode() == TimetableGridModel.sBgModeTooBigRooms) {
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired),
                "Assigned room is smaller than room limit of a class");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral),
                "Assigned room is not more than 25% bigger than the smallest avaialable room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged),
                "Assigned room is not more than 50% bigger than the smallest avaialable room");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged),
                "Assigned room is more than 50% bigger than the smallest avaialable room");
    }
    PdfPCell c = createCellNoBorder();
    c.setColspan(2);
    addText(c, "Free times:");
    c.setHorizontalAlignment(Element.ALIGN_LEFT);
    iPdfTable.addCell(c);
    addLegendRow(TimetableGridCell.sBgColorNotAvailable, "Time not available");
    addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No preference");
    if (iTable.getShowUselessTimes()) {
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged),
                "Standard (MWF or TTh) time pattern is broken (time cannot be used for MW, WF, MF or TTh class)");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Useless half-hour");
        addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited),
                "Useless half-hour and broken standard time pattern");
    }

    if (iTable.isDispModePerWeekVertical())
        iDocument.newPage();

    iDocument.add(iPdfTable);
}

From source file:org.webguitoolkit.ui.util.export.PDFEvent.java

License:Apache License

public void onEndPage(PdfWriter writer, Document document) {
    TableExportOptions exportOptions = wgtTable.getExportOptions();
    try {/*from w ww . j  ava2s. c o  m*/
        Rectangle page = document.getPageSize();
        if (exportOptions.isShowDefaultHeader() || StringUtils.isNotEmpty(exportOptions.getHeaderImage())) {
            PdfPTable head = new PdfPTable(3);
            head.getDefaultCell().setBorder(Rectangle.NO_BORDER);
            Paragraph title = new Paragraph(wgtTable.getTitle());
            title.setAlignment(Element.ALIGN_LEFT);
            head.addCell(title);

            Paragraph empty = new Paragraph("");
            head.addCell(empty);
            if (StringUtils.isNotEmpty(exportOptions.getHeaderImage())) {
                try {
                    URL absoluteFileUrl = wgtTable.getPage().getClass()
                            .getResource("/" + exportOptions.getHeaderImage());
                    if (absoluteFileUrl != null) {
                        String path = absoluteFileUrl.getPath();
                        Image jpg = Image.getInstance(path);
                        jpg.scaleAbsoluteHeight(40);
                        jpg.scaleAbsoluteWidth(200);
                        head.addCell(jpg);
                    }
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    Paragraph noImage = new Paragraph("Image not found!");
                    head.addCell(noImage);
                }
            } else {
                head.addCell(empty);
            }
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin(),
                    page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());
        }

        if (exportOptions.isShowDefaultFooter() || StringUtils.isNotEmpty(exportOptions.getFooterText())
                || exportOptions.isShowPageNumber()) {
            PdfPTable foot = new PdfPTable(3);
            String footerText = exportOptions.getFooterText() != null ? exportOptions.getFooterText() : "";

            if (!exportOptions.isShowDefaultFooter()) {
                foot.addCell(new Paragraph(footerText));
                foot.addCell(new Paragraph(""));
            } else {
                foot.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                String leftText = "";
                if (StringUtils.isNotEmpty(exportOptions.getFooterText())) {
                    leftText = exportOptions.getFooterText();
                }
                Paragraph left = new Paragraph(leftText);
                left.setAlignment(Element.ALIGN_LEFT);
                foot.addCell(left);

                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM,
                        TextService.getLocale());
                Date today = new Date();
                String date = df.format(today);
                Paragraph center = new Paragraph(date);
                center.setAlignment(Element.ALIGN_CENTER);
                foot.addCell(center);
            }

            if (exportOptions.isShowPageNumber()) {
                Paragraph right = new Paragraph(
                        TextService.getString("pdf.page@Page:") + " " + writer.getPageNumber());
                right.setAlignment(Element.ALIGN_LEFT);
                foot.addCell(right);

                foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                        writer.getDirectContent());
            } else {
                foot.addCell(new Paragraph(""));
            }
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:oscar.eform.util.EFormPDFServlet.java

License:Open Source License

private void writeContent(Properties printCfg, Properties props, Properties measurements, float height,
        PdfContentByte cb) throws Exception {
    for (Enumeration e = printCfg.propertyNames(); e.hasMoreElements();) {
        StringBuilder temp = new StringBuilder(e.nextElement().toString());
        String[] cfgVal = printCfg.getProperty(temp.toString()).split(" *, *");

        String[] fontType = null;
        int fontFlags = 0;
        if (cfgVal[4].indexOf(";") > -1) {
            fontType = cfgVal[4].split(";");
            if (fontType[1].trim().equals("italic"))
                fontFlags = Font.ITALIC;
            else if (fontType[1].trim().equals("bold"))
                fontFlags = Font.BOLD;
            else if (fontType[1].trim().equals("bolditalic"))
                fontFlags = Font.BOLDITALIC;
            else//from www .ja  v  a 2  s  .  co  m
                fontFlags = Font.NORMAL;
        } else {
            fontFlags = Font.NORMAL;
            fontType = new String[] { cfgVal[4].trim() };
        }

        String encoding = null;
        if (fontType[0].trim().equals("BaseFont.HELVETICA")) {
            fontType[0] = BaseFont.HELVETICA;
            encoding = BaseFont.CP1252; //latin1 encoding
        } else if (fontType[0].trim().equals("BaseFont.HELVETICA_OBLIQUE")) {
            fontType[0] = BaseFont.HELVETICA_OBLIQUE;
            encoding = BaseFont.CP1252;
        } else if (fontType[0].trim().equals("BaseFont.ZAPFDINGBATS")) {
            fontType[0] = BaseFont.ZAPFDINGBATS;
            encoding = BaseFont.ZAPFDINGBATS;
        } else {
            fontType[0] = BaseFont.COURIER;
            encoding = BaseFont.CP1252;
        }

        BaseFont bf = BaseFont.createFont(fontType[0], encoding, BaseFont.NOT_EMBEDDED);
        String propValue = props.getProperty(temp.toString());
        //if not in regular config then check measurements
        if (propValue == null) {
            propValue = measurements.getProperty(temp.toString(), "");
        }

        ColumnText ct = new ColumnText(cb);
        // write in a rectangle area
        if (cfgVal.length >= 9) {
            Font font = new Font(bf, Integer.parseInt(cfgVal[5].trim()), fontFlags);
            ct.setSimpleColumn(Integer.parseInt(cfgVal[1].trim()),
                    (height - Integer.parseInt(cfgVal[2].trim())), Integer.parseInt(cfgVal[7].trim()),
                    (height - Integer.parseInt(cfgVal[8].trim())), Integer.parseInt(cfgVal[9].trim()),
                    (cfgVal[0].trim().equals("left") ? Element.ALIGN_LEFT
                            : (cfgVal[0].trim().equals("right") ? Element.ALIGN_RIGHT : Element.ALIGN_CENTER)));

            ct.setText(new Phrase(12, propValue, font));
            ct.go();
            continue;
        }

        // draw line directly
        if (temp.toString().startsWith("__$line")) {
            cb.setRGBColorStrokeF(0f, 0f, 0f);
            cb.setLineWidth(Float.parseFloat(cfgVal[4].trim()));
            cb.moveTo(Float.parseFloat(cfgVal[0].trim()), Float.parseFloat(cfgVal[1].trim()));
            cb.lineTo(Float.parseFloat(cfgVal[2].trim()), Float.parseFloat(cfgVal[3].trim()));
            cb.stroke();

        } else if (temp.toString().startsWith("__")) {
            cb.beginText();
            cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim()));
            cb.showTextAligned(
                    (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT
                            : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT
                                    : PdfContentByte.ALIGN_CENTER)),
                    (cfgVal.length >= 7 ? (cfgVal[6].trim()) : propValue), Integer.parseInt(cfgVal[1].trim()),
                    (height - Integer.parseInt(cfgVal[2].trim())), 0);
            cb.endText();
        } else { // write prop text
            cb.beginText();
            cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim()));
            cb.showTextAligned(
                    (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT
                            : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT
                                    : PdfContentByte.ALIGN_CENTER)),
                    (cfgVal.length >= 7 ? ((propValue.equals("") ? "" : cfgVal[6].trim())) : propValue),
                    Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0);

            cb.endText();
        }
    }
}

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

License:Open Source License

/**
 * Creates the table containing additional information
 * about the reason for the consultation request.
 * @return the table produced//from   w  w  w  . j a  v  a2s. c o  m
 */
private PdfPTable createConsultDetailTable() {
    PdfPTable infoTable;
    PdfPCell cell;
    infoTable = new PdfPTable(1);
    cell = new PdfPCell();

    infoTable.addCell(setInfoCell2(cell, getResource("msgReason")));
    infoTable.addCell(setDataCell2(cell, reqFrm.reasonForConsultation));

    if (getlen(reqFrm.clinicalInformation) > 1) {
        infoTable.addCell(setInfoCell(cell, getResource("msgClinicalInfom")));
        infoTable.addCell(setDataCell(cell, divy(reqFrm.clinicalInformation)));
    }

    if (getlen(reqFrm.concurrentProblems) > 1) {
        if (props.getProperty("significantConcurrentProblemsTitle", "").length() > 1) {
            infoTable.addCell(setInfoCell(cell, props.getProperty("significantConcurrentProblemsTitle", "")));
        } else {
            infoTable.addCell(setInfoCell(cell, getResource("msgSigProb")));
        }
        infoTable.addCell(setDataCell(cell, divy(reqFrm.concurrentProblems)));
    }

    if (getlen(reqFrm.currentMedications) > 1) {
        if (props.getProperty("currentMedicationsTitle", "").length() > 1) {
            infoTable.addCell(setInfoCell(cell, props.getProperty("currentMedicationsTitle", "")));
        } else {
            infoTable.addCell(setInfoCell(cell, getResource("msgCurrMed")));
        }
        infoTable.addCell(setDataCell(cell, divy(reqFrm.currentMedications)));
    }

    if (getlen(reqFrm.allergies) > 1) {
        infoTable.addCell(setInfoCell(cell, getResource("msgAllergies")));
        infoTable.addCell(setDataCell(cell, divy(reqFrm.allergies)));
    }

    if (getlen(reqFrm.ocularExamination) > 1) {
        infoTable.addCell(setInfoCell(cell, getResource("msgOcularExamination")));
        infoTable.addCell(setDataCell(cell, divy(reqFrm.ocularExamination)));
    }

    ProviderDao proDAO = (ProviderDao) SpringUtils.getBean("providerDao");
    org.oscarehr.common.model.Provider pro = proDAO.getProvider(reqFrm.providerNo);
    String billingNo = pro.getBillingNo();
    DemographicDao demoDAO = (DemographicDao) SpringUtils.getBean("demographicDao");
    Demographic demo = demoDAO.getDemographic(reqFrm.demoNo);
    pro = proDAO.getProvider(demo.getProviderNo());
    String famDocBillingNo = pro.getBillingNo();
    //infoTable.addCell(setFooterCell(cell, getResource("msgAssociated2"), reqFrm.getProviderName(reqFrm.providerNo) + ((getlen(billingNo) > 0) ? " (" + billingNo + ")" : "")));
    //infoTable.addCell(setFooterCell(cell, getResource("msgFamilyDoc2"), reqFrm.getFamilyDoctor() + ((getlen(famDocBillingNo) > 0) ? " (" + famDocBillingNo + ")" : "")));
    if (props.getProperty("CONSULTATION_SIGNATURE_LINE1") != null) {
        cell.setPadding(0);
        cell.setBorder(0);
        cell.setPhrase(new Phrase(props.getProperty("CONSULTATION_SIGNATURE_LINE1")));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        infoTable.addCell(cell);

        if (props.getProperty("CONSULTATION_SIGNATURE_LINE2") != null) {
            cell.setPadding(0);
            cell.setBorder(0);
            cell.setPhrase(new Phrase(props.getProperty("CONSULTATION_SIGNATURE_LINE2")));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            infoTable.addCell(cell);
        }
        if (props.getProperty("CONSULTATION_SIGNATURE_LINE3") != null) {
            cell.setPadding(0);
            cell.setBorder(0);
            cell.setPhrase(new Phrase(props.getProperty("CONSULTATION_SIGNATURE_LINE3")));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            infoTable.addCell(cell);
        }
    } else {
        infoTable.addCell(setFooterCell(cell, getResource("msgAssociated2"), reqFrm.getFamilyDoctor()
                + ((getlen(famDocBillingNo) > 0) ? " (" + famDocBillingNo + ")" : "")));
        infoTable.addCell(
                setFooterCell(cell, getResource("msgCreatedBy"), reqFrm.getProviderName(reqFrm.providerNo)
                        + ((getlen(billingNo) > 0) ? " (" + billingNo + ")" : "")));
    }

    if (getlen(reqFrm.signatureImg) > 0) {
        addSignature(infoTable);
    }
    return infoTable;
}

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

License:Open Source License

private float addDynamicPositionedText(String name, String text, float dynamicHeight,
        EctConsultationFormRequestUtil reqForm) throws DocumentException, IOException {
    if (text != null && text.length() > 0) {
        Font boldFont = new Font(bf, FONTSIZE, Font.BOLD);
        Font font = new Font(bf, FONTSIZE, Font.NORMAL);
        float lineCount = (name.length() + text.length()) / 100;

        // if there is not enough room on the page for the text start on the next page
        if ((height - 264 - dynamicHeight - lineCount * LINEHEIGHT) < LINEHEIGHT * 3) {
            nextPage(reqForm);/*from w w  w  . j a  va2  s. co m*/
            dynamicHeight = LINEHEIGHT - 152;
        }

        ct.setSimpleColumn(new Float(85), height - 264 - dynamicHeight - lineCount * LINEHEIGHT, new Float(526),
                height - 250 - dynamicHeight, LINEHEIGHT, Element.ALIGN_LEFT);
        ct.addText(new Phrase(name, boldFont));
        ct.addText(new Phrase(text, font));
        ct.go();
        dynamicHeight += lineCount * LINEHEIGHT + LINEHEIGHT * 2;
    }

    return dynamicHeight;
}

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

License:Open Source License

private void setAppointmentInfo(EctConsultationFormRequestUtil reqForm) throws DocumentException {

    printClinicData(reqForm);// ww w.  j av  a2s . co m
    Font font = new Font(bf, FONTSIZE, Font.NORMAL);

    // Set consultant info
    cb.beginText();
    cb.setFontAndSize(bf, FONTSIZE);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.referalDate, 190, height - 112, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT,
            reqForm.urgency.equals("1") ? "Urgent" : (reqForm.urgency.equals("2") ? "Non-Urgent" : "Return"),
            190, height - 125, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.getServiceName(reqForm.service), 190, height - 139,
            0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.getSpecailistsName(reqForm.specialist), 190,
            height - 153, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.specPhone, 190, height - 166, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.specFax, 190, height - 181, 0);
    cb.endText();
    ct.setSimpleColumn(new Float(190), height - 223, new Float(290), height - 181, LINEHEIGHT,
            Element.ALIGN_LEFT);
    ct.addText(new Phrase(reqForm.specAddr.replaceAll("<br>", "\n"), font));
    ct.go();

    // Set patient info
    cb.beginText();
    cb.setFontAndSize(bf, FONTSIZE);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientName, 385, height - 112, 0);
    cb.endText();
    ct.setSimpleColumn(new Float(385), height - 153, new Float(585), height - 112, LINEHEIGHT,
            Element.ALIGN_LEFT);
    ct.addText(new Phrase(reqForm.patientAddress.replaceAll("<br>", " "), font));
    ct.go();

    cb.beginText();
    cb.setFontAndSize(bf, FONTSIZE);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientPhone, 385, height - 166, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientDOB, 385, height - 181, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, (reqForm.patientHealthCardType + " "
            + reqForm.patientHealthNum + " " + reqForm.patientHealthCardVersionCode).trim(), 440, height - 195,
            0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT,
            reqForm.appointmentHour + ":" + reqForm.appointmentMinute + " " + reqForm.appointmentPm + " "
                    + reqForm.appointmentDay + "/" + reqForm.appointmentMonth + "/" + reqForm.appointmentYear,
            440, height - 208, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientChartNo, 385, height - 222, 0);
    cb.endText();
}

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);//  w ww.j a v a  2 s  .  c  om
    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:permit.InvoicePdf.java

License:Open Source License

/**
 * handles the letter header//w w  w.ja v a  2  s .  c  om
 */
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;
}