Example usage for com.lowagie.text Paragraph add

List of usage examples for com.lowagie.text Paragraph add

Introduction

In this page you can find the example usage for com.lowagie.text Paragraph add.

Prototype

public boolean add(Object o) 

Source Link

Document

Adds an Object to the Paragraph.

Usage

From source file:org.mapfish.print.config.layout.LegendsBlock.java

License:Open Source License

private PdfPCell createLine(RenderingContext context, double indent, PJsonObject node, Font pdfFont,
        PJsonObject params) throws DocumentException {
    final String name = node.getString("name");
    final String icon = node.optString("icon");
    final PJsonArray icons = node.optJSONArray("icons");

    final Paragraph result = new Paragraph();
    result.setFont(pdfFont);/*from   w  ww  .j a v a  2  s .co m*/
    if (icon != null) {
        result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(icon), 0.0f));
        result.add(" ");
    }
    if (icons != null) {
        for (int i = 0; i < icons.size(); ++i) {
            String iconItem = icons.getString(i);
            try {
                result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(iconItem),
                        0.0f));
                result.add(" ");
            } catch (InvalidValueException e) {
                LOGGER.warn("Failed to create image chunk: " + e.getMessage());
            }
        }
    }
    result.add(name);

    final PdfPCell cell = new PdfPCell(result);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPadding(0f);
    cell.setPaddingLeft((float) indent);

    if (getBackgroundColorVal(context, params) != null) {
        cell.setBackgroundColor(getBackgroundColorVal(context, params));
    }

    return cell;
}

From source file:org.mapfish.print.config.layout.TextBlock.java

License:Open Source License

public void render(PJsonObject params, PdfElement target, final RenderingContext context)
        throws DocumentException {
    Paragraph paragraph = new Paragraph();

    final Font pdfFont = getPdfFont();
    paragraph.setFont(pdfFont);//from w w  w. j  a v  a 2  s.c  o  m

    final Phrase text = PDFUtils.renderString(context, params, this.text, pdfFont);
    paragraph.add(text);

    if (getAlign() != null)
        paragraph.setAlignment(getAlign().getCode());
    paragraph.setSpacingAfter((float) spacingAfter);
    target.add(paragraph);
}

From source file:org.nuxeo.dam.pdf.export.PDFCreator.java

License:Open Source License

public boolean createPDF(String title, OutputStream out) throws ClientException {
    try {/*from  w  w  w .  jav a 2 s .  co  m*/
        Document document = new Document();
        PdfWriter.getInstance(document, out);

        document.addTitle(title);
        document.addAuthor(Functions.principalFullName(currentUser));
        document.addCreator(Functions.principalFullName(currentUser));

        document.open();

        document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n"));
        Font titleFont = new Font(Font.HELVETICA, 36, Font.BOLD);
        Paragraph titleParagraph = new Paragraph(title, titleFont);
        titleParagraph.setAlignment(Element.ALIGN_CENTER);
        document.add(titleParagraph);
        Font authorFont = new Font(Font.HELVETICA, 20);
        Paragraph authorParagraph = new Paragraph("By " + Functions.principalFullName(currentUser), authorFont);
        authorParagraph.setAlignment(Element.ALIGN_CENTER);
        document.add(authorParagraph);

        document.newPage();

        boolean foundOnePicture = false;
        for (DocumentModel doc : docs) {
            if (!doc.hasSchema(PICTURE_SCHEMA)) {
                continue;
            }
            foundOnePicture = true;

            PictureResourceAdapter picture = doc.getAdapter(PictureResourceAdapter.class);
            Blob blob = picture.getPictureFromTitle(ORIGINAL_JPEG_VIEW);
            Rectangle pageSize = document.getPageSize();
            if (blob != null) {
                Paragraph imageTitle = new Paragraph(doc.getTitle(), font);
                imageTitle.setAlignment(Paragraph.ALIGN_CENTER);
                document.add(imageTitle);

                Image image = Image.getInstance(blob.getByteArray());
                image.scaleToFit(pageSize.getWidth() - 20, pageSize.getHeight() - 100);
                image.setAlignment(Image.MIDDLE);
                Paragraph imageParagraph = new Paragraph();
                imageParagraph.add(image);
                imageParagraph.setAlignment(Paragraph.ALIGN_MIDDLE);
                document.add(imageParagraph);

                document.newPage();
            }
        }
        if (foundOnePicture) {
            document.close();
            return true;
        }
    } catch (Exception e) {
        throw ClientException.wrap(e);
    }
    return false;
}

From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java

License:Open Source License

public void printMasterRecord() throws DocumentException {
    if (newPage) {
        document.newPage();/*w  ww.  ja  v a  2 s  .c  om*/
        newPage = false;
    }

    Font obsfont = new Font(bf, FONTSIZE, Font.UNDERLINE);

    Paragraph p = null;
    Phrase phrase = null;

    p = new Paragraph();
    p.setAlignment(Paragraph.ALIGN_LEFT);
    phrase = new Phrase(LEADING, "Patient Information", boldFont);
    phrase.add("\n");
    p.add(phrase);
    document.add(p);

    p = new Paragraph();
    phrase = new Phrase(LEADING, "", font);
    phrase.add("Title: " + demographic.getTitle() + "\n");
    phrase.add("Last Name: " + demographic.getLastName() + "\n");
    phrase.add("First Name: " + demographic.getFirstName() + "\n");
    phrase.add("Gender: " + demographic.getSex() + "\n");
    phrase.add("Date of Birth: " + demographic.getFormattedDob() + "\n");
    phrase.add("Offical Language: " + demographic.getOfficialLanguage() + "\n");
    phrase.add("Spoken Language: " + demographic.getSpokenLanguage() + "\n");
    phrase.add("\n");
    p.add(phrase);
    document.add(p);

    p = new Paragraph();
    phrase = new Phrase(LEADING, "", font);
    phrase.add("Roster Status: " + demographic.getRosterStatus() + "\n");
    phrase.add("Date Rostered: " + "\n");
    phrase.add("Patient Status: " + demographic.getPatientStatus() + "\n");
    phrase.add("Chart No (MRN): " + demographic.getChartNo() + "\n");
    if (demographic.getDateJoined() != null) {
        phrase.add("Date Joined: " + formatter.format(demographic.getDateJoined()) + "\n");
    }
    if (demographic.getEndDate() != null) {
        phrase.add("End Date: " + formatter.format(demographic.getEndDate()) + "\n");
    }
    phrase.add("\n");
    p.add(phrase);
    document.add(p);

    p = new Paragraph();
    phrase = new Phrase(LEADING, "", font);
    phrase.add("Address: " + demographic.getAddress() + "\n");
    phrase.add("City: " + demographic.getCity() + "\n");
    phrase.add("Province: " + demographic.getProvince() + "\n");
    phrase.add("Postal Code: " + demographic.getPostal() + "\n");
    phrase.add("Email: " + demographic.getEmail() + "\n");
    phrase.add("Phone: " + demographic.getPhone() + "\n");

    List<DemographicExt> exts = demographicExtDao
            .getDemographicExtByDemographicNo(demographic.getDemographicNo());
    String phoneExt = null;
    String cell = null;
    for (DemographicExt ext : exts) {
        if (ext.getKey().equals("wPhoneExt")) {
            phoneExt = ext.getValue();
        }
        if (ext.getKey().equals("demo_cell")) {
            cell = ext.getValue();
        }
    }

    phrase.add("Work Phone: " + demographic.getPhone2());
    if (phoneExt != null) {
        phrase.add(" ext:" + phoneExt + "\n");
    } else {
        phrase.add("\n");
    }

    if (cell != null) {
        phrase.add("Cell Phone: " + cell + "\n");
    }

    phrase.add("\n");
    p.add(phrase);
    document.add(p);

    p = new Paragraph();
    phrase = new Phrase(LEADING, "", font);
    phrase.add("Health Insurance #: " + demographic.getHin() + "\n");
    phrase.add("HC Type: " + demographic.getHcType() + "\n");
    if (demographic.getEffDate() != null) {
        phrase.add("Eff Date: " + formatter.format(demographic.getEffDate()) + "\n");
    }
    phrase.add("\n");
    p.add(phrase);
    document.add(p);

    DemographicCust demographicCust = demographicCustDao.find(demographic.getDemographicNo());

    p = new Paragraph();
    phrase = new Phrase(LEADING, "", font);
    phrase.add("Physician: " + getProviderName(demographic.getProviderNo()) + "\n");
    if (demographicCust != null) {
        phrase.add("Nurse: " + getProviderName(demographicCust.getNurse()) + "\n");
        phrase.add("Midwife: " + getProviderName(demographicCust.getMidwife()) + "\n");
        phrase.add("Resident: " + getProviderName(demographicCust.getResident()) + "\n");
    }
    phrase.add("Referral Doctor: " + getReferralDoctor(demographic.getFamilyDoctor()) + "\n");
    phrase.add("\n");
    p.add(phrase);
    document.add(p);

    p = new Paragraph();
    phrase = new Phrase(LEADING, "", font);
    //alerts & notes
    if (demographicCust != null) {
        phrase.add("Alerts: " + demographicCust.getAlert() + "\n");
        if (demographicCust.getNotes().length() > 0) {
            phrase.add("Notes: " + SxmlMisc.getXmlContent(demographicCust.getNotes(), "unotes") + "\n");
        }
    }
    phrase.add("\n");
    p.add(phrase);
    document.add(p);

    //relationships
    p = new Paragraph();
    phrase = new Phrase(LEADING, "", font);

    DemographicRelationship demoRel = new DemographicRelationship();
    @SuppressWarnings("unchecked")
    ArrayList<HashMap<String, String>> demoR = demoRel
            .getDemographicRelationships(String.valueOf(demographic.getDemographicNo()));
    for (int j = 0; j < demoR.size(); j++) {
        HashMap<String, String> r = demoR.get(j);
        String relationDemographicNo = r.get("demographic_no");
        Demographic relationDemographic = demographicDao
                .getClientByDemographicNo(Integer.parseInt(relationDemographicNo));
        String relation = r.get("relation");
        String subDecisionMaker = r.get("sub_decision_maker");
        String emergencyContact = r.get("emergency_contact");
        String notes = r.get("notes");

        phrase.add(relation + " - " + relationDemographic.getFormattedName() + " - " + subDecisionMaker + " - "
                + emergencyContact + " - " + notes + "\n");
    }
    phrase.add("\n");
    p.add(phrase);
    document.add(p);

}

From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java

License:Open Source License

public void printCPPItem(String heading, Collection<CaseManagementNote> notes) throws DocumentException {
    if (newPage)//ww  w  .  ja  va  2s.  c  o  m
        document.newPage();
    //  else
    //      newPage = true;

    Font obsfont = new Font(bf, FONTSIZE, Font.UNDERLINE);

    Paragraph p = null;
    Phrase phrase = null;

    p = new Paragraph();
    p.setAlignment(Paragraph.ALIGN_LEFT);
    phrase = new Phrase(LEADING, heading, obsfont);
    p.add(phrase);
    document.add(p);
    newPage = false;
    this.printNotes(notes, true);

    cb.endText();

}

From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java

License:Open Source License

public void printNotes(Collection<CaseManagementNote> notes, boolean compact) throws DocumentException {

    CaseManagementNote note;/*  w  w  w . j  a v a  2s . c  o  m*/
    Font obsfont = new Font(bf, FONTSIZE, Font.UNDERLINE);
    Paragraph p;
    Phrase phrase;
    Chunk chunk;

    //if( newPage )
    //     document.newPage();
    // else
    //     newPage = true;

    //Print notes
    Iterator<CaseManagementNote> notesIter = notes.iterator();
    while (notesIter.hasNext()) {
        note = notesIter.next();
        p = new Paragraph();
        //p.setSpacingBefore(font.leading(LINESPACING)*2f);
        phrase = new Phrase(LEADING, "", font);

        if (compact) {
            phrase.add(new Chunk(formatter.format(note.getObservation_date()) + ":"));
        } else {
            chunk = new Chunk("Impression/Plan: (" + formatter.format(note.getObservation_date()) + ")\n",
                    obsfont);
            phrase.add(chunk);
        }
        if (compact) {
            phrase.add(note.getNote() + "\n");
        } else {
            phrase.add(note.getNote() + "\n\n");
        }
        p.add(phrase);
        document.add(p);
    }
}

From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java

License:Open Source License

public void printBlankLine() throws DocumentException {
    Paragraph p = new Paragraph();
    p.add(new Phrase("\n"));
    document.add(p);/*from   w  ww.  j a  v a 2 s  .  c o  m*/

}

From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java

License:Open Source License

public void printAllergies(List<Allergy> allergies) throws DocumentException {
    ProviderDao providerDao = (ProviderDao) SpringUtils.getBean("providerDao");

    /*//from w w w. j  a  va  2 s .co m
         if( getNewPage() )
    getDocument().newPage();
           else
    setNewPage(true);
    */
    Font obsfont = new Font(getBaseFont(), FONTSIZE, Font.UNDERLINE);

    Paragraph p = new Paragraph();
    p.setAlignment(Paragraph.ALIGN_LEFT);
    Phrase phrase = new Phrase(LEADING, "\n", getFont());
    p.add(phrase);
    phrase = new Phrase(LEADING, "Allergies", obsfont);
    p.add(phrase);
    getDocument().add(p);

    for (Allergy allergy : allergies) {
        p = new Paragraph();
        phrase = new Phrase(LEADING, "", getFont());
        Chunk chunk = new Chunk(allergy.getDescription());
        phrase.add(chunk);
        p.add(phrase);
        getDocument().add(p);
    }
    getDocument().add(new Phrase("\n", getFont()));
}

From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java

License:Open Source License

public void printRx(String demoNo, List<CaseManagementNote> cpp) throws DocumentException {
    if (demoNo == null)
        return;/*from   w w  w. j  a v  a 2 s  .  co  m*/
    /*
    if( newPage )
    document.newPage();
    else
    newPage = true;
    */
    oscar.oscarRx.data.RxPrescriptionData prescriptData = new oscar.oscarRx.data.RxPrescriptionData();
    oscar.oscarRx.data.RxPrescriptionData.Prescription[] arr = {};
    arr = prescriptData.getUniquePrescriptionsByPatient(Integer.parseInt(demoNo));

    if (arr.length == 0) {
        return;
    }

    Paragraph p = new Paragraph();
    Font obsfont = new Font(bf, FONTSIZE, Font.UNDERLINE);
    Phrase phrase = new Phrase(LEADING, "", obsfont);
    p.setAlignment(Paragraph.ALIGN_LEFT);
    phrase.add("Prescriptions");
    p.add(phrase);
    document.add(p);

    Font normal = new Font(bf, FONTSIZE, Font.NORMAL);

    Font curFont;
    for (int idx = 0; idx < arr.length; ++idx) {
        oscar.oscarRx.data.RxPrescriptionData.Prescription drug = arr[idx];
        p = new Paragraph();
        p.setAlignment(Paragraph.ALIGN_LEFT);
        if (drug.isCurrent() && !drug.isArchived()) {
            curFont = normal;
            phrase = new Phrase(LEADING, "", curFont);
            phrase.add(formatter.format(drug.getRxDate()) + " - ");
            phrase.add(drug.getFullOutLine().replaceAll(";", " "));
            p.add(phrase);
            document.add(p);
        }
    }

}

From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java

License:Open Source License

public void printPreventions() throws DocumentException {
    List<Prevention> preventions = preventionDao.findNotDeletedByDemographicId(demographic.getDemographicNo());

    if (preventions.size() == 0) {
        return;//from w  ww  . j av a  2  s  .  c o m
    }

    Paragraph p = new Paragraph();
    Font obsfont = new Font(bf, FONTSIZE, Font.UNDERLINE);
    Phrase phrase = new Phrase(LEADING, "", obsfont);
    p.setAlignment(Paragraph.ALIGN_LEFT);
    phrase.add("Preventions");
    p.add(phrase);
    document.add(p);

    for (Prevention prevention : preventions) {
        String type = prevention.getPreventionType();
        Date date = prevention.getPreventionDate();

        p = new Paragraph();
        phrase = new Phrase(LEADING, "", getFont());
        Chunk chunk = new Chunk(type + " " + formatter.format(date) + "\n");
        phrase.add(chunk);
        p.add(phrase);
        getDocument().add(p);
    }

}