Example usage for com.lowagie.text.pdf PdfContentByte ALIGN_LEFT

List of usage examples for com.lowagie.text.pdf PdfContentByte ALIGN_LEFT

Introduction

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

Prototype

int ALIGN_LEFT

To view the source code for com.lowagie.text.pdf PdfContentByte ALIGN_LEFT.

Click Source Link

Document

The alignment is left

Usage

From source file:org.openconcerto.erp.core.finance.accounting.report.PdfGenerator.java

License:Open Source License

protected void addText(String code, String string, int i, int j, int k) {
    addText(PdfContentByte.ALIGN_LEFT, code, string, i, j, k);

}

From source file:org.oscarehr.phr.web.PHRUserManagementAction.java

License:Open Source License

public ByteArrayOutputStream generateUserRegistrationLetter(String demographicNo, String username,
        String password) throws Exception {
    log.debug("Demographic " + demographicNo + " username " + username + " password " + password);
    DemographicDao demographicDao = (DemographicDao) SpringUtils.getBean("demographicDao");
    Demographic demographic = demographicDao.getDemographic(demographicNo);

    final String PAGESIZE = "printPageSize";
    Document document = new Document();

    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfWriter writer = null;/* w w w .j  a  va 2 s . c om*/

    try {
        writer = PdfWriter.getInstance(document, baosPDF);

        String title = "TITLE";
        String template = "MyOscarLetterHead.pdf";

        Properties printCfg = getCfgProp();

        String[] cfgVal = null;
        StringBuilder tempName = null;

        // get the print prop values

        Properties props = new Properties();
        props.setProperty("letterDate", UtilDateUtilities.getToday("yyyy-MM-dd"));
        props.setProperty("name", demographic.getFirstName() + " " + demographic.getLastName());
        props.setProperty("dearname", demographic.getFirstName() + " " + demographic.getLastName());
        props.setProperty("address", demographic.getAddress());
        props.setProperty("city", demographic.getCity() + ", " + demographic.getProvince());
        props.setProperty("postalCode", demographic.getPostal());
        props.setProperty("credHeading", "MyOscar User Account Details");
        props.setProperty("username", "Username: " + username);
        props.setProperty("password", "Password: " + password);
        //Temporary - the intro will change to be dynamic
        props.setProperty("intro",
                "We are pleased to provide you with a log in and password for your new MyOSCAR Personal Health Record. This account will allow you to connect electronically with our clinic. Please take a few minutes to review the accompanying literature for further information.We look forward to you benefiting from this service.");

        document.addTitle(title);
        document.addSubject("");
        document.addKeywords("pdf, itext");
        document.addCreator("OSCAR");
        document.addAuthor("");
        document.addHeader("Expires", "0");

        Rectangle pageSize = PageSize.LETTER;

        document.setPageSize(pageSize);
        document.open();

        // create a reader for a certain document
        String propFilename = oscar.OscarProperties.getInstance().getProperty("pdfFORMDIR", "") + "/"
                + template;
        PdfReader reader = null;
        try {
            reader = new PdfReader(propFilename);
            log.debug("Found template at " + propFilename);
        } catch (Exception dex) {
            log.debug("change path to inside oscar from :" + propFilename);
            reader = new PdfReader("/oscar/form/prop/" + template);
            log.debug("Found template at /oscar/form/prop/" + template);
        }

        // retrieve the total number of pages
        int n = reader.getNumberOfPages();
        // retrieve the size of the first page
        Rectangle pSize = reader.getPageSize(1);
        float width = pSize.getWidth();
        float height = pSize.getHeight();
        log.debug("Width :" + width + " Height: " + height);

        PdfContentByte cb = writer.getDirectContent();
        ColumnText ct = new ColumnText(cb);
        int fontFlags = 0;

        document.newPage();
        PdfImportedPage page1 = writer.getImportedPage(reader, 1);
        cb.addTemplate(page1, 1, 0, 0, 1, 0, 0);

        BaseFont bf; // = normFont;
        String encoding;

        cb.setRGBColorStroke(0, 0, 255);

        String[] fontType;
        for (Enumeration e = printCfg.propertyNames(); e.hasMoreElements();) {
            tempName = new StringBuilder(e.nextElement().toString());
            cfgVal = printCfg.getProperty(tempName.toString()).split(" *, *");

            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
                    fontFlags = Font.NORMAL;
            } else {
                fontFlags = Font.NORMAL;
                fontType = new String[] { cfgVal[4].trim() };
            }

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

            bf = BaseFont.createFont(fontType[0], encoding, BaseFont.NOT_EMBEDDED);

            // 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, props.getProperty(tempName.toString(), ""), font));
                ct.go();
                continue;
            }

            // draw line directly
            if (tempName.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()));
                // stroke the lines
                cb.stroke();
                // write text directly

            } else if (tempName.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()) : props.getProperty(tempName.toString(), "")),
                        Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0);

                cb.endText();
            } else if (tempName.toString().equals("forms_promotext")) {
                if (OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null) {
                    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)),
                            OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"),
                            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 ? ((props.getProperty(tempName.toString(), "").equals("") ? ""
                                : cfgVal[6].trim())) : props.getProperty(tempName.toString(), "")),
                        Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0);

                cb.endText();
            }
        }

    } catch (DocumentException dex) {
        baosPDF.reset();
        throw dex;
    } finally {
        if (document != null)
            document.close();
        if (writer != null)
            writer.close();
    }
    return baosPDF;
}

From source file:org.unitime.timetable.util.PdfEventHandler.java

License:Open Source License

/**
 * Print footer string on each page//from   w  w w . j  av a2  s.  c  o  m
 * @param writer
 * @param document
 */
public void onEndPage(PdfWriter writer, Document document) {

    if (getDateTime() == null) {
        setDateTime(new Date());
    }

    PdfContentByte cb = writer.getDirectContent();
    cb.beginText();
    cb.setFontAndSize(getBaseFont(), getFontSize());
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()), document.left(), 20,
            0);
    cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()), document.right(),
            20, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()),
            (document.left() + document.right()) / 2, 20, 0);
    cb.endText();

    return;
}

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 w ww.j ava 2 s .c o 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.EctConsultationFormRequestPrintPdf.java

License:Open Source License

private void setAppointmentInfo(EctConsultationFormRequestUtil reqForm) throws DocumentException {

    printClinicData(reqForm);//w ww.j a  va2 s  .com
    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.oscarEncounter.oscarConsultationRequest.pageUtil.EctConsultationFormRequestPrintPdf.java

License:Open Source License

private void nextPage(EctConsultationFormRequestUtil reqForm) throws DocumentException, IOException {
    PdfImportedPage page2 = writer.getImportedPage(reader, 2);
    document.newPage();//from   w ww.ja  v  a  2 s.c om
    cb.addTemplate(page2, 1, 0, 0, 1, 0, 0);

    printClinicData(reqForm);
    cb.beginText();
    cb.setFontAndSize(bf, FONTSIZE);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientName, 110, height - 82, 0);
    cb.endText();

    PAGENUM++;
    addFooter();

}

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

License:Open Source License

private void printClinicData(EctConsultationFormRequestUtil reqForm) {
    cb.beginText();/*from w  ww  .  jav a 2  s.  c  o  m*/

    if (IsPropertiesOn.isMultisitesEnable()) {
        Provider letterheadNameProvider = (reqForm.letterheadName != null
                ? new RxProviderData().getProvider(reqForm.letterheadName)
                : null);
        String letterheadNameParam = (letterheadNameProvider == null ? reqForm.letterheadName
                : letterheadNameProvider.getFirstName() + " " + letterheadNameProvider.getSurname());

        cb.setFontAndSize(bf, 16);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, letterheadNameParam, 90, height - 70, 0);

        cb.setFontAndSize(bf, FONTSIZE);
        cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, reqForm.letterheadAddress, 533, height - 70, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.letterheadPhone, 360, height - 82, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.letterheadFax, 471, height - 82, 0);
    } else {
        ClinicData clinic = new ClinicData();
        clinic.refreshClinicData();

        cb.beginText();

        cb.setFontAndSize(bf, 16);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, clinic.getClinicName(), 90, height - 70, 0);

        cb.setFontAndSize(bf, FONTSIZE);
        cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, clinic.getClinicAddress() + ", " + clinic.getClinicCity()
                + ", " + clinic.getClinicProvince() + ", " + clinic.getClinicPostal(), 533, height - 70, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, clinic.getClinicPhone(), 360, height - 82, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, clinic.getClinicFax(), 471, height - 82, 0);

    }

    cb.endText();
}