Example usage for com.lowagie.text Element ALIGN_RIGHT

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

Introduction

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

Prototype

int ALIGN_RIGHT

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

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

private PdfPCell pdfBuildPrefGroupProjectedDemand(PreferenceGroup prefGroup, boolean isEditable) {
    PdfPCell cell = createCell();//  w  w w  .ja va2s.c  om
    if (prefGroup instanceof Class_) {
        Class_ c = (Class_) prefGroup;
        SectioningInfo i = c.getSectioningInfo();
        if (i != null && i.getNbrExpectedStudents() != null) {
            addText(cell,
                    String.valueOf(Math.round(Math.max(0.0, c.getEnrollment() + i.getNbrExpectedStudents()))));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        }
    }
    return cell;
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

private PdfPCell pdfBuildLimit(ClassAssignmentProxy classAssignment, PreferenceGroup prefGroup,
        boolean isEditable) {
    Color color = (isEditable ? sEnableColor : sDisableColor);

    PdfPCell cell = createCell();/* w w  w  .j  a  v  a  2 s  . c  om*/

    if (prefGroup instanceof SchedulingSubpart) {
        SchedulingSubpart ss = (SchedulingSubpart) prefGroup;
        boolean unlimited = ss.getInstrOfferingConfig().isUnlimitedEnrollment().booleanValue();
        if (!unlimited) {
            int limit = (ss.getLimit() == null ? 0 : ss.getLimit().intValue());
            int maxExpCap = ss.getMaxExpectedCapacity();
            if (limit == maxExpCap)
                addText(cell, String.valueOf(limit), false, false, Element.ALIGN_RIGHT, color, true);
            else
                addText(cell, limit + "-" + maxExpCap, false, false, Element.ALIGN_RIGHT, color, true);
        }
    } else if (prefGroup instanceof Class_) {
        Class_ aClass = (Class_) prefGroup;
        boolean unlimited = aClass.getSchedulingSubpart().getInstrOfferingConfig().isUnlimitedEnrollment()
                .booleanValue();
        if (!unlimited) {
            String limitString = null;
            Assignment a = null;
            try {
                if (classAssignment != null)
                    a = classAssignment.getAssignment(aClass);
            } catch (Exception e) {
            }
            if (a == null) {
                if (aClass.getExpectedCapacity() != null) {
                    limitString = aClass.getExpectedCapacity().toString();
                    if (aClass.getMaxExpectedCapacity() != null
                            && !aClass.getMaxExpectedCapacity().equals(aClass.getExpectedCapacity())) {
                        limitString = limitString + "-" + aClass.getMaxExpectedCapacity().toString();
                    }
                } else {
                    limitString = "0";
                    if (aClass.getMaxExpectedCapacity() != null
                            && aClass.getMaxExpectedCapacity().intValue() != 0) {
                        limitString = limitString + "-" + aClass.getMaxExpectedCapacity().toString();
                    }
                }
            } else {
                limitString = "" + aClass.getClassLimit(classAssignment);
            }
            addText(cell, limitString, false, false, Element.ALIGN_RIGHT, color, true);
        }
    }

    return cell;
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

private PdfPCell pdfBuildDivisionSection(CourseOffering co, PreferenceGroup prefGroup, boolean isEditable) {
    Color color = (isEditable ? sEnableColor : sDisableColor);
    PdfPCell cell = createCell();//  ww  w  . j a  v  a2 s .  c om

    if (prefGroup instanceof Class_) {
        Class_ aClass = (Class_) prefGroup;
        // String divSec = aClass.getDivSecNumber();
        String divSec = aClass.getClassSuffix(co);
        if (divSec != null)
            addText(cell, divSec, false, false, Element.ALIGN_RIGHT, color, true);
    }

    return cell;
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

private PdfPCell pdfBuildMinPerWeek(PreferenceGroup prefGroup, boolean isEditable) {
    Color color = (isEditable ? sEnableColor : sDisableColor);
    PdfPCell cell = createCell();/*from w  w  w . j a v  a 2 s  . c om*/

    if (prefGroup instanceof Class_) {
        Class_ aClass = (Class_) prefGroup;
        addText(cell, aClass.getSchedulingSubpart().getMinutesPerWk().toString(), false, false,
                Element.ALIGN_RIGHT, color, true);
    } else if (prefGroup instanceof SchedulingSubpart) {
        SchedulingSubpart aSchedulingSubpart = (SchedulingSubpart) prefGroup;
        addText(cell, aSchedulingSubpart.getMinutesPerWk().toString(), false, false, Element.ALIGN_RIGHT, color,
                true);
    }

    return cell;
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

private PdfPCell pdfBuildRoomLimit(PreferenceGroup prefGroup, boolean isEditable, boolean classLimitDisplayed) {
    Color color = (isEditable ? sEnableColor : sDisableColor);
    PdfPCell cell = createCell();//from w  w w .j a  va 2 s  .  c om

    if (prefGroup instanceof Class_) {
        Class_ aClass = (Class_) prefGroup;
        if (aClass.getNbrRooms() != null && aClass.getNbrRooms().intValue() != 1) {
            if (aClass.getNbrRooms().intValue() == 0)
                addText(cell, "N/A", false, true, Element.ALIGN_RIGHT, color, true);
            else {
                String text = aClass.getNbrRooms().toString();
                text += " at ";
                if (aClass.getRoomRatio() != null)
                    text += sRoomRatioFormat.format(aClass.getRoomRatio().floatValue());
                else
                    text += "0";
                addText(cell, text, false, false, Element.ALIGN_RIGHT, color, true);
            }
        } else {
            if (aClass.getRoomRatio() != null) {
                if (classLimitDisplayed && aClass.getRoomRatio().equals(new Float(1.0))) {
                    addText(cell, "", false, false, Element.ALIGN_RIGHT, color, true);
                } else {
                    addText(cell, sRoomRatioFormat.format(aClass.getRoomRatio().floatValue()), false, false,
                            Element.ALIGN_RIGHT, color, true);
                }
            } else {
                if (aClass.getExpectedCapacity() == null) {
                    addText(cell, "", false, false, Element.ALIGN_RIGHT, color, true);
                } else {
                    addText(cell, "0", false, false, Element.ALIGN_RIGHT, color, true);
                }
            }
        }
    }

    return cell;
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

protected void pdfBuildConfigRow(Vector subpartIds, ClassAssignmentProxy classAssignment,
        ExamAssignmentProxy examAssignment, CourseOffering co, InstrOfferingConfig ioc, SessionContext context,
        boolean printConfigLine) {
    iBgColor = sBgColorConfig;//from w w  w .  j  av  a 2 s  . c  om
    boolean isEditable = context.hasPermission(ioc.getInstructionalOffering(),
            Right.InstructionalOfferingDetail);
    Color color = (isEditable ? sEnableColor : sDisableColor);
    String configName = ioc.getName();
    boolean unlimited = ioc.isUnlimitedEnrollment().booleanValue();
    boolean hasConfig = false;
    if (printConfigLine) {
        if (isShowLabel()) {
            if (configName == null || configName.trim().length() == 0)
                configName = ioc.getUniqueId().toString();
            PdfPCell cell = createCell();
            addText(cell, indent + "Configuration " + configName, false, false, Element.ALIGN_LEFT, color,
                    true);
            iPdfTable.addCell(cell);
        }
        if (isShowDivSec()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowDemand()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowProjectedDemand()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowLimit()) {
            PdfPCell cell = createCell();
            addText(cell, (unlimited ? "inf" : ioc.getLimit().toString()), false, false, Element.ALIGN_RIGHT,
                    color, true);
            iPdfTable.addCell(cell);
        }
        if (isShowRoomRatio()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowManager()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowDatePattern()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowMinPerWk()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowTimePattern()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowPreferences()) {
            for (int j = 0; j < PREFERENCE_COLUMN_ORDER.length
                    + (getDisplayDistributionPrefs() ? 0 : -1); j++) {
                iPdfTable.addCell(createCell());
            }
        }
        if (isShowInstructor()) {
            iPdfTable.addCell(createCell());
        }
        if (getDisplayTimetable() && isShowTimetable()) {
            for (int j = 0; j < TIMETABLE_COLUMN_ORDER.length; j++) {
                iPdfTable.addCell(createCell());
            }
        }
        if (isShowTitle()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowCredit()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowSubpartCredit()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowConsent()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowSchedulePrintNote()) {
            iPdfTable.addCell(createCell());
        }
        if (isShowNote()) {
            iPdfTable.addCell(createCell());
        }

        if (isShowExam()) {
            TreeSet exams = new TreeSet(Exam.findAll(ExamOwner.sOwnerTypeConfig, ioc.getUniqueId()));
            if (isShowExamName()) {
                iPdfTable.addCell(pdfBuildExamName(exams, isEditable));
            }
            if (isShowExamTimetable()) {
                iPdfTable.addCell(pdfBuildExamPeriod(examAssignment, exams, isEditable));
                iPdfTable.addCell(pdfBuildExamRoom(examAssignment, exams, isEditable));
            }
        }

        hasConfig = true;
    }

    ArrayList subpartList = new ArrayList(ioc.getSchedulingSubparts());
    Collections.sort(subpartList, new SchedulingSubpartComparator());
    Iterator it = subpartList.iterator();
    SchedulingSubpart ss = null;
    while (it.hasNext()) {
        ss = (SchedulingSubpart) it.next();
        if (ss.getParentSubpart() == null) {
            pdfBuildSchedulingSubpartRows(subpartIds, classAssignment, examAssignment, co, ss,
                    (hasConfig ? indent + indent : indent), context);
        }
    }
    it = subpartList.iterator();
    int ct = 0;
    String prevLabel = null;
    while (it.hasNext()) {
        ss = (SchedulingSubpart) it.next();
        if (ss.getParentSubpart() == null) {
            if (ss.getClasses() != null) {
                Vector classes = new Vector(ss.getClasses());
                Collections.sort(classes, getClassComparator());
                Iterator cIt = classes.iterator();
                Class_ c = null;
                while (cIt.hasNext()) {
                    c = (Class_) cIt.next();
                    pdfBuildClassRows(classAssignment, examAssignment, ++ct, co, c, indent, context, prevLabel);
                    prevLabel = c.htmlLabel();
                }
            }
        }
    }
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

private void pdfAddInstrOffrRowsToTable(ClassAssignmentProxy classAssignment,
        ExamAssignmentProxy examAssignment, InstructionalOffering io, Long subjectAreaId,
        SessionContext context) {/*from w  w  w  .  j a va 2 s  . co m*/
    iBgColor = sBgColorOffering;
    CourseOffering co = io.findSortCourseOfferingForSubjectArea(subjectAreaId);
    boolean isEditable = context.hasPermission(co.getInstructionalOffering(),
            Right.InstructionalOfferingDetail);
    boolean isManagedAs = !co.isIsControl().booleanValue();
    Color color = (isEditable ? sEnableColor : sDisableColor);

    if (isShowLabel()) {
        iPdfTable.addCell(pdfSubjectAndCourseInfo(io, co));
    }
    if (isShowDivSec()) {
        iPdfTable.addCell(createCell());
    }
    if (isShowDemand()) {
        PdfPCell cell = createCell();
        if (StudentClassEnrollment.sessionHasEnrollments(io.getSessionId())) {
            addText(cell, (io.getEnrollment() != null ? io.getEnrollment().toString() : "0"), false, false,
                    Element.ALIGN_RIGHT, (co.isIsControl() ? color : sDisableColor), true);
        } else {
            addText(cell, (io.getDemand() != null ? io.getDemand().toString() : "0"), false, false,
                    Element.ALIGN_RIGHT, (co.isIsControl() ? color : sDisableColor), true);
        }
        iPdfTable.addCell(cell);
    }
    if (isShowProjectedDemand()) {
        PdfPCell cell = createCell();
        addText(cell, (io.getProjectedDemand() != null ? io.getProjectedDemand().toString() : "0"), false,
                false, Element.ALIGN_RIGHT, (co.isIsControl() ? color : sDisableColor), true);
        iPdfTable.addCell(cell);
    }
    if (isShowLimit()) {
        boolean unlimited = false;
        for (Iterator x = io.getInstrOfferingConfigs().iterator(); !unlimited && x.hasNext();)
            if ((((InstrOfferingConfig) x.next())).isUnlimitedEnrollment().booleanValue())
                unlimited = true;
        PdfPCell cell = createCell();
        addText(cell, (unlimited ? "inf" : io.getLimit() == null ? "0" : io.getLimit().toString()), false,
                false, Element.ALIGN_RIGHT, (co.isIsControl() ? color : sDisableColor), true);
        iPdfTable.addCell(cell);
    }
    int emptyCels = 0;
    if (isShowRoomRatio()) {
        emptyCels++;
    }
    if (isShowManager()) {
        emptyCels++;
    }
    if (isShowDatePattern()) {
        emptyCels++;
    }
    if (isShowMinPerWk()) {
        emptyCels++;
    }
    if (isShowTimePattern()) {
        emptyCels++;
    }
    if (isShowPreferences()) {
        emptyCels += PREFERENCE_COLUMN_ORDER.length + (getDisplayDistributionPrefs() ? 0 : -1);
    }
    if (isShowInstructor()) {
        emptyCels++;
    }
    if (getDisplayTimetable() && isShowTimetable()) {
        emptyCels += TIMETABLE_COLUMN_ORDER.length;
    }
    if (emptyCels > 0) {
        PdfPCell managedCell = createCell();
        if (isManagedAs) {
            if (!isShowTitle() && io.getControllingCourseOffering().getTitle() != null) {
                if (co.getTitle() != null && co.getTitle().length() > 0) {
                    addText(managedCell,
                            "     " + co.getTitle() + " (Managed As "
                                    + io.getControllingCourseOffering().getCourseName() + ")",
                            true, false, Element.ALIGN_LEFT, sDisableColor, false);
                } else {
                    addText(managedCell, "     Managed As " + io.getControllingCourseOffering().getCourseName(),
                            true, false, Element.ALIGN_LEFT, sDisableColor, true);
                }
                for (Iterator it = io
                        .courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId())
                        .iterator(); it.hasNext();) {
                    CourseOffering x = (CourseOffering) it.next();
                    addText(managedCell, (x.getTitle() == null ? "" : "     " + x.getTitle()), false, false,
                            Element.ALIGN_LEFT, sDisableColor, true);
                }
            } else {
                addText(managedCell, "     Managed As " + io.getControllingCourseOffering().getCourseName(),
                        true, false, Element.ALIGN_LEFT, sDisableColor, true);
            }
        } else {
            if (!isShowTitle() && io.getControllingCourseOffering().getTitle() != null) {
                addText(managedCell, (co.getTitle() == null ? "" : "      " + co.getTitle()), true, false,
                        Element.ALIGN_LEFT, color, true);
                for (Iterator it = io
                        .courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId())
                        .iterator(); it.hasNext();) {
                    CourseOffering x = (CourseOffering) it.next();
                    addText(managedCell, (x.getTitle() == null ? "" : "      " + x.getTitle()), false, false,
                            Element.ALIGN_LEFT, sDisableColor, true);
                }
            }
        }
        managedCell.setColspan(emptyCels);
        iPdfTable.addCell(managedCell);

    }
    if (isShowTitle()) {
        PdfPCell titleCell = createCell();
        addText(titleCell,
                (io.getControllingCourseOffering().getTitle() != null
                        ? "      " + io.getControllingCourseOffering().getTitle()
                        : ""),
                false, false, Element.ALIGN_LEFT, color, true);
        iPdfTable.addCell(titleCell);
    }
    if (isShowCredit()) {
        PdfPCell cell = createCell();
        addText(cell, (co.getCredit() != null ? co.getCredit().creditAbbv() : ""), true, false,
                Element.ALIGN_LEFT, isManagedAs ? sDisableColor : color, true);
        for (Iterator it = io
                .courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId())
                .iterator(); it.hasNext();) {
            CourseOffering x = (CourseOffering) it.next();
            addText(cell, (x.getCredit() != null ? x.getCredit().creditAbbv() : ""), false, false,
                    Element.ALIGN_LEFT, sDisableColor, true);
        }
        iPdfTable.addCell(cell);
    }
    if (isShowSubpartCredit()) {
        iPdfTable.addCell(createCell());
    }
    if (isShowConsent()) {
        PdfPCell cell = createCell();
        addText(cell, co.getConsentType() != null ? co.getConsentType().getAbbv() : MSG.noConsentRequired(),
                true, false, Element.ALIGN_LEFT, isManagedAs ? sDisableColor : color, true);
        for (Iterator it = io
                .courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId())
                .iterator(); it.hasNext();) {
            CourseOffering x = (CourseOffering) it.next();
            addText(cell, (x.getConsentType() != null ? x.getConsentType().getAbbv() : MSG.noConsentRequired()),
                    false, false, Element.ALIGN_LEFT, sDisableColor, true);
        }
        iPdfTable.addCell(cell);
    }
    if (isShowSchedulePrintNote()) {
        iPdfTable.addCell(pdfBuildSchedulePrintNote(io, isEditable, context.getUser()));
    }
    if (isShowNote()) {
        iPdfTable.addCell(createCell());
    }
    if (isShowExam()) {
        TreeSet exams = new TreeSet(Exam.findAll(ExamOwner.sOwnerTypeOffering, io.getUniqueId()));
        for (Iterator i = io.getCourseOfferings().iterator(); i.hasNext();) {
            CourseOffering cox = (CourseOffering) i.next();
            exams.addAll(Exam.findAll(ExamOwner.sOwnerTypeCourse, cox.getUniqueId()));
        }
        if (io.getInstrOfferingConfigs().size() == 1) {
            for (Iterator i = io.getInstrOfferingConfigs().iterator(); i.hasNext();) {
                InstrOfferingConfig ioc = (InstrOfferingConfig) i.next();
                exams.addAll(Exam.findAll(ExamOwner.sOwnerTypeConfig, ioc.getUniqueId()));
            }
        }
        if (isShowExamName()) {
            iPdfTable.addCell(pdfBuildExamName(exams, isEditable));
        }
        if (isShowExamTimetable()) {
            iPdfTable.addCell(pdfBuildExamPeriod(examAssignment, exams, isEditable));
            iPdfTable.addCell(pdfBuildExamRoom(examAssignment, exams, isEditable));
        }
    }

    if (io.getInstrOfferingConfigs() != null & !io.getInstrOfferingConfigs().isEmpty()) {
        TreeSet configs = new TreeSet(new InstrOfferingConfigComparator(
                io.getControllingCourseOffering().getSubjectArea().getUniqueId()));
        configs.addAll(io.getInstrOfferingConfigs());
        pdfBuildConfigRows(classAssignment, examAssignment, io.getControllingCourseOffering(), configs, context,
                true);
    }
}

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

License:Open Source License

/**
 * Prints pdf table. By default does not split table across
 * page boundaries //from w w w  .  j a  va2 s .  co m
 * @param ordCol
 * @param keepTogether true does not split table across pages
 * @return
 */
public PdfPTable printPdfTable(int ordCol, boolean keepTogether) {
    PdfPTable table = new PdfPTable(getNrColumns());
    table.setWidthPercentage(100);
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setBorderWidth(0);
    table.setSplitRows(false);
    table.setKeepTogether(keepTogether);

    boolean asc = (ordCol == 0 || iAsc == null || iAsc.length <= Math.abs(ordCol) - 1 ? true
            : iAsc[Math.abs(ordCol) - 1]);
    if (ordCol < 0)
        asc = !asc;

    widths = new float[iColumns];
    for (int i = 0; i < iColumns; i++)
        widths[i] = 0f;

    String lastLine[] = new String[Math.max(iColumns, (iHeaders == null ? 0 : iHeaders.length))];

    if (iHeaders != null) {
        for (int i = 0; i < iColumns; i++) {
            if (isFiltered(i))
                continue;
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            float width = addText(c, iHeaders[i] == null ? "" : iHeaders[i], true);
            widths[i] = Math.max(widths[i], width);
            String align = (iAlign != null ? iAlign[i] : "left");
            if ("left".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_LEFT);
            if ("right".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if ("center".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(c);
        }
        table.setHeaderRows(1);
    }
    if (ordCol != 0) {
        Collections.sort(iLines, new WebTableComparator(Math.abs(ordCol) - 1, asc));
    }
    for (int el = 0; el < iLines.size(); el++) {
        WebTableLine wtline = (WebTableLine) iLines.elementAt(el);
        String[] line = wtline.getLine();
        boolean blank = iBlankWhenSame;
        for (int i = 0; i < iColumns; i++) {
            if (isFiltered(i))
                continue;
            if (blank && line[i] != null && !line[i].equals(lastLine[i]))
                blank = false;
            PdfPCell c = createCell();
            float width = addText(c, blank || line[i] == null ? "" : line[i], false);
            widths[i] = Math.max(widths[i], width);
            String align = (iAlign != null ? iAlign[i] : "left");
            if ("left".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_LEFT);
            if ("right".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if ("center".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_CENTER);
            applyPdfStyle(c, wtline, (el + 1 < iLines.size() ? (WebTableLine) iLines.elementAt(el + 1) : null),
                    ordCol);
            table.addCell(c);
            lastLine[i] = line[i];
        }
    }

    try {
        if (getNrFilteredColumns() < 0) {
            table.setWidths(widths);
        } else {
            float[] x = new float[getNrColumns()];
            int idx = 0;
            for (int i = 0; i < iColumns; i++) {
                if (isFiltered(i))
                    continue;
                x[idx++] = widths[i];
            }
            table.setWidths(x);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return table;
}

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

License:Open Source License

public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception {
    if (text == null)
        return;//from  w  w w  .  j a v a  2  s  .  co m
    if (text.indexOf("<span") >= 0)
        text = text.replaceAll("</span>", "").replaceAll("<span .*>", "");
    Font font = PdfFont.getFont(bold);
    BaseFont bf = font.getBaseFont();
    float width = bf.getWidthPoint(text, font.getSize());
    PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
    template.beginText();
    template.setColorFill(Color.BLACK);
    template.setFontAndSize(bf, font.getSize());
    template.setTextMatrix(0, 2);
    template.showText(text);
    template.endText();
    template.setWidth(width);
    template.setHeight(font.getSize() + 2);
    //make an Image object from the template
    Image img = Image.getInstance(template);
    img.setRotationDegrees(270);
    //embed the image in a Chunk
    Chunk ck = new Chunk(img, 0, 0);

    if (cell.getPhrase() == null) {
        cell.setPhrase(new Paragraph(ck));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    } else {
        cell.getPhrase().add(ck);
    }
}

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  ww  w.ja  va  2s.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();
        }
    }
}