Example usage for com.lowagie.text Font Font

List of usage examples for com.lowagie.text Font Font

Introduction

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

Prototype


public Font(int family, float size, int style) 

Source Link

Document

Constructs a Font.

Usage

From source file:org.oscarehr.common.service.PdfRecordPrinter.java

License:Open Source License

public void printSpecsHistory(List<EyeformSpecsHistory> specsHistory) throws DocumentException {
    ProviderDao providerDao = (ProviderDao) SpringUtils.getBean("providerDao");

    /*//ww w  .ja va2  s .  c o  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, "Specs History", obsfont);
    p.add(phrase);
    getDocument().add(p);

    PdfPTable table = new PdfPTable(2);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);
    table.setTotalWidth(new float[] { 10f, 60f });
    table.setTotalWidth(5f);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);

    for (EyeformSpecsHistory specs : specsHistory) {
        PdfPCell cell1 = new PdfPCell(new Phrase(getFormatter().format(specs.getDate()), getFont()));
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell1);

        PdfPCell cell2 = new PdfPCell(new Phrase(specs.toString2(), getFont()));
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell2);
    }

    getDocument().add(table);
}

From source file:org.oscarehr.common.service.PdfRecordPrinter.java

License:Open Source License

public void printEyeformMeasurements(MeasurementFormatter mf) throws DocumentException {
    /*//from   ww  w  . j  a  va  2s  . com
    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, "Ocular Examination", obsfont);
    p.add(phrase);
    getDocument().add(p);

    p = new Paragraph();
    boolean addVisionAssessment = false;
    p.add(new Phrase("VISION ASSESSMENT:  ", getFont()));
    if (mf.getVisionAssessmentAutoRefraction().length() > 0) {
        p.add(new Phrase("Auto-refraction ", boldFont));
        p.add(new Phrase(mf.getVisionAssessmentAutoRefraction(), getFont()));
        addVisionAssessment = true;
    }
    if (mf.getVisionAssessmentKeratometry().length() > 0) {
        p.add(new Phrase(" Keratometry ", boldFont));
        p.add(new Phrase(mf.getVisionAssessmentKeratometry(), getFont()));
        addVisionAssessment = true;
    }
    if (mf.getVisionAssessmentVision("distance", "sc").length() > 0) {
        p.add(new Phrase(" Distance vision (sc) ", boldFont));
        p.add(new Phrase(mf.getVisionAssessmentVision("distance", "sc"), getFont()));
        addVisionAssessment = true;
    }
    if (mf.getVisionAssessmentVision("distance", "cc").length() > 0) {
        p.add(new Phrase(" Distance vision (cc) ", boldFont));
        p.add(new Phrase(mf.getVisionAssessmentVision("distance", "cc"), getFont()));
        addVisionAssessment = true;
    }
    if (mf.getVisionAssessmentVision("distance", "ph").length() > 0) {
        p.add(new Phrase(" Distance vision (ph) ", boldFont));
        p.add(new Phrase(mf.getVisionAssessmentVision("distance", "ph"), getFont()));
        addVisionAssessment = true;
    }
    if (mf.getVisionAssessmentVision("near", "sc").length() > 0) {
        p.add(new Phrase(" Near vision (sc) ", boldFont));
        p.add(new Phrase(mf.getVisionAssessmentVision("near", "sc"), getFont()));
        addVisionAssessment = true;
    }
    if (mf.getVisionAssessmentVision("near", "cc").length() > 0) {
        p.add(new Phrase(" Near vision (cc) ", boldFont));
        p.add(new Phrase(mf.getVisionAssessmentVision("near", "cc"), getFont()));
        addVisionAssessment = true;
    }
    p.add(new Phrase("\n\n"));
    if (addVisionAssessment) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addManifestVision = false;
    p.add(new Phrase("MANIFEST VISION:  ", getFont()));
    if (mf.getManifestDistance().length() > 0) {
        p.add(new Phrase("Manifest distance ", boldFont));
        p.add(new Phrase(mf.getManifestDistance(), getFont()));
        addManifestVision = true;
    }
    if (mf.getManifestNear().length() > 0) {
        p.add(new Phrase(" Manifest near ", boldFont));
        p.add(new Phrase(mf.getManifestNear(), getFont()));
        addManifestVision = true;
    }
    if (mf.getCycloplegicRefraction().length() > 0) {
        p.add(new Phrase(" Cycloplegic refraction ", boldFont));
        p.add(new Phrase(mf.getCycloplegicRefraction(), getFont()));
        addManifestVision = true;
    }
    p.add(new Phrase("\n\n"));
    if (addManifestVision) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addIop = false;
    p.add(new Phrase("INTRAOCULAR PRESSURE:  ", getFont()));
    if (mf.getNCT().length() > 0) {
        p.add(new Phrase("NCT ", boldFont));
        p.add(new Phrase(mf.getNCT(), getFont()));
        addIop = true;
    }
    if (mf.getApplanation().length() > 0) {
        p.add(new Phrase(" Applanation ", boldFont));
        p.add(new Phrase(mf.getApplanation(), getFont()));
        addIop = true;
    }
    if (mf.getCCT().length() > 0) {
        p.add(new Phrase(" Central corneal thickness ", boldFont));
        p.add(new Phrase(mf.getCCT(), getFont()));
        addIop = true;
    }
    p.add(new Phrase("\n\n"));
    if (addIop) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addOtherExam = false;
    p.add(new Phrase("OTHER EXAM:  ", getFont()));
    if (mf.getColourVision().length() > 0) {
        p.add(new Phrase("Colour vision ", boldFont));
        p.add(new Phrase(mf.getColourVision(), getFont()));
        addOtherExam = true;
    }
    if (mf.getPupil().length() > 0) {
        p.add(new Phrase(" Pupil ", boldFont));
        p.add(new Phrase(mf.getPupil(), getFont()));
        addOtherExam = true;
    }
    if (mf.getAmslerGrid().length() > 0) {
        p.add(new Phrase(" Amsler grid ", boldFont));
        p.add(new Phrase(mf.getAmslerGrid(), getFont()));
        addOtherExam = true;
    }
    if (mf.getPAM().length() > 0) {
        p.add(new Phrase(" Potential acuity meter ", boldFont));
        p.add(new Phrase(mf.getPAM(), getFont()));
        addOtherExam = true;
    }
    if (mf.getConfrontation().length() > 0) {
        p.add(new Phrase(" Confrontation fields ", boldFont));
        p.add(new Phrase(mf.getConfrontation(), getFont()));
        addOtherExam = true;
    }
    p.add(new Phrase("\n\n"));
    if (addOtherExam) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addEom = false;
    p.add(new Phrase("EOM/STEREO:  ", getFont()));
    if (mf.getEomStereo().length() > 0) {
        p.add(new Phrase(mf.getEomStereo(), getFont()));
        addEom = true;
    }
    p.add(new Phrase("\n\n"));
    if (addEom) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addAnteriorSegment = false;
    p.add(new Phrase("ANTERIOR SEGMENT:  ", getFont()));
    if (mf.getCornea().length() > 0) {
        p.add(new Phrase("Cornea ", boldFont));
        p.add(new Phrase(mf.getCornea(), getFont()));
        addAnteriorSegment = true;
    }
    if (mf.getConjuctivaSclera().length() > 0) {
        p.add(new Phrase(" Conjunctiva/Sclera ", boldFont));
        p.add(new Phrase(mf.getConjuctivaSclera(), getFont()));
        addAnteriorSegment = true;
    }
    if (mf.getAnteriorChamber().length() > 0) {
        p.add(new Phrase(" Anterior chamber ", boldFont));
        p.add(new Phrase(mf.getAnteriorChamber(), getFont()));
        addAnteriorSegment = true;
    }
    if (mf.getAngle().length() > 0) {
        p.add(new Phrase(" Angle ", boldFont));
        p.add(new Phrase(mf.getAngle(), getFont()));
        addAnteriorSegment = true;
    }
    if (mf.getIris().length() > 0) {
        p.add(new Phrase(" Iris ", boldFont));
        p.add(new Phrase(mf.getIris(), getFont()));
        addAnteriorSegment = true;
    }
    if (mf.getLens().length() > 0) {
        p.add(new Phrase(" Lens ", boldFont));
        p.add(new Phrase(mf.getLens(), getFont()));
        addAnteriorSegment = true;
    }
    p.add(new Phrase("\n\n"));
    if (addAnteriorSegment) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addPosteriorSegment = false;
    p.add(new Phrase("POSTERIOR SEGMENT:  ", getFont()));
    if (mf.getDisc().length() > 0) {
        p.add(new Phrase("Optic disc ", boldFont));
        p.add(new Phrase(mf.getDisc(), getFont()));
        addPosteriorSegment = true;
    }
    if (mf.getCdRatio().length() > 0) {
        p.add(new Phrase(" C/D ratio ", boldFont));
        p.add(new Phrase(mf.getCdRatio(), getFont()));
        addPosteriorSegment = true;
    }
    if (mf.getMacula().length() > 0) {
        p.add(new Phrase(" Macula ", boldFont));
        p.add(new Phrase(mf.getMacula(), getFont()));
        addPosteriorSegment = true;
    }
    if (mf.getRetina().length() > 0) {
        p.add(new Phrase(" Retina ", boldFont));
        p.add(new Phrase(mf.getRetina(), getFont()));
        addPosteriorSegment = true;
    }
    if (mf.getVitreous().length() > 0) {
        p.add(new Phrase(" Vitreous ", boldFont));
        p.add(new Phrase(mf.getVitreous(), getFont()));
        addPosteriorSegment = true;
    }
    p.add(new Phrase("\n\n"));
    if (addPosteriorSegment) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addExternal = false;
    p.add(new Phrase("EXTERNAL/ORBIT:  ", getFont()));
    if (mf.getFace().length() > 0) {
        p.add(new Phrase("Face ", boldFont));
        p.add(new Phrase(mf.getFace(), getFont()));
        addExternal = true;
    }
    if (mf.getUpperLid().length() > 0) {
        p.add(new Phrase(" Upper lid ", boldFont));
        p.add(new Phrase(mf.getUpperLid(), getFont()));
        addExternal = true;
    }
    if (mf.getLowerLid().length() > 0) {
        p.add(new Phrase(" Lower lid ", boldFont));
        p.add(new Phrase(mf.getLowerLid(), getFont()));
        addExternal = true;
    }
    if (mf.getPunctum().length() > 0) {
        p.add(new Phrase(" Punctum ", boldFont));
        p.add(new Phrase(mf.getPunctum(), getFont()));
        addExternal = true;
    }
    if (mf.getLacrimalLake().length() > 0) {
        p.add(new Phrase(" Lacrimal lake ", boldFont));
        p.add(new Phrase(mf.getLacrimalLake(), getFont()));
        addExternal = true;
    }
    if (mf.getRetropulsion().length() > 0) {
        p.add(new Phrase(" Retropulsion ", boldFont));
        p.add(new Phrase(mf.getRetropulsion(), getFont()));
        addExternal = true;
    }
    if (mf.getHertel().length() > 0) {
        p.add(new Phrase(" Hertel ", boldFont));
        p.add(new Phrase(mf.getHertel(), getFont()));
        addExternal = true;
    }
    p.add(new Phrase("\n\n"));
    if (addExternal) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addNasolacrimal = false;
    p.add(new Phrase("NASOLACRIMAL DUCT:  ", getFont()));
    if (mf.getLacrimalIrrigation().length() > 0) {
        p.add(new Phrase("Lacrimal irrigation ", boldFont));
        p.add(new Phrase(mf.getLacrimalIrrigation(), getFont()));
        addNasolacrimal = true;
    }
    if (mf.getNLD().length() > 0) {
        p.add(new Phrase(" Nasolacrimal duct ", boldFont));
        p.add(new Phrase(mf.getNLD(), getFont()));
        addNasolacrimal = true;
    }
    if (mf.getDyeDisappearance().length() > 0) {
        p.add(new Phrase(" Dye disappearance ", boldFont));
        p.add(new Phrase(mf.getDyeDisappearance(), getFont()));
        addNasolacrimal = true;
    }
    p.add(new Phrase("\n\n"));
    if (addNasolacrimal) {
        getDocument().add(p);
    }

    p = new Paragraph();
    boolean addEyelidMeasurement = false;
    p.add(new Phrase("EYELID MEASUREMENT:  ", getFont()));
    if (mf.getMarginReflexDistance().length() > 0) {
        p.add(new Phrase("Margin reflex distance ", boldFont));
        p.add(new Phrase(mf.getMarginReflexDistance(), getFont()));
        addEyelidMeasurement = true;
    }
    if (mf.getLevatorFunction().length() > 0) {
        p.add(new Phrase(" Levator function ", boldFont));
        p.add(new Phrase(mf.getLevatorFunction(), getFont()));
        addEyelidMeasurement = true;
    }
    if (mf.getInferiorScleralShow().length() > 0) {
        p.add(new Phrase(" Inferior scleral show ", boldFont));
        p.add(new Phrase(mf.getInferiorScleralShow(), getFont()));
        addEyelidMeasurement = true;
    }
    if (mf.getLagophthalmos().length() > 0) {
        p.add(new Phrase(" Lagophthalmos ", boldFont));
        p.add(new Phrase(mf.getLagophthalmos(), getFont()));
        addEyelidMeasurement = true;
    }
    if (mf.getBlink().length() > 0) {
        p.add(new Phrase(" Blink ", boldFont));
        p.add(new Phrase(mf.getBlink(), getFont()));
        addEyelidMeasurement = true;
    }
    if (mf.getCNVii().length() > 0) {
        p.add(new Phrase(" Cranial Nerve VII function ", boldFont));
        p.add(new Phrase(mf.getCNVii(), getFont()));
        addEyelidMeasurement = true;
    }
    if (mf.getBells().length() > 0) {
        p.add(new Phrase(" Bell's phenonmenon ", boldFont));
        p.add(new Phrase(mf.getBells(), getFont()));
        addEyelidMeasurement = true;
    }
    p.add(new Phrase("\n\n"));
    if (addEyelidMeasurement) {
        getDocument().add(p);
    }

}

From source file:org.oscarehr.common.service.PdfRecordPrinter.java

License:Open Source License

public void printPhotos(String contextPath, List<org.oscarehr.common.model.Document> photos)
        throws DocumentException {
    writer.setStrictImageSequence(true);

    if (photos.size() > 0) {
        Font obsfont = new Font(getBaseFont(), FONTSIZE, Font.UNDERLINE);
        Paragraph p = new Paragraph();
        p.setAlignment(Paragraph.ALIGN_LEFT);
        Phrase phrase = new Phrase(LEADING, "\n\n", getFont());
        p.add(phrase);/*from w  ww .j a  v a 2s. c o  m*/
        phrase = new Phrase(LEADING, "Photos:", obsfont);
        p.add(phrase);
        getDocument().add(p);
    }

    for (org.oscarehr.common.model.Document doc : photos) {
        Image img = null;
        try {
            //             String location = oscar.OscarProperties.getInstance().getProperty("DOCUMENT_DIR").trim() + doc.getDocfilename();
            String location = EDocUtil.getDocumentPath(doc.getDocfilename());
            logger.info("adding image " + location);
            img = Image.getInstance(location);
        } catch (IOException e) {
            MiscUtils.getLogger().error("error:", e);
            continue;
        }
        img.scaleToFit(getDocument().getPageSize().getWidth() - getDocument().leftMargin()
                - getDocument().rightMargin(), getDocument().getPageSize().getHeight());

        Chunk chunk = new Chunk(img, getDocument().getPageSize().getWidth() - getDocument().leftMargin()
                - getDocument().rightMargin(), getDocument().getPageSize().getHeight());

        Paragraph p = new Paragraph();
        p.add(img);
        p.add(new Phrase("Description:" + doc.getDocdesc(), getFont()));
        getDocument().add(p);

    }
}

From source file:org.oscarehr.common.service.PdfRecordPrinter.java

License:Open Source License

public void printDiagrams(List<EFormValue> diagrams) throws DocumentException {
    writer.setStrictImageSequence(true);

    EFormValueDao eFormValueDao = (EFormValueDao) SpringUtils.getBean("EFormValueDao");

    if (diagrams.size() > 0) {
        Font obsfont = new Font(getBaseFont(), FONTSIZE, Font.UNDERLINE);
        Paragraph p = new Paragraph();
        p.setAlignment(Paragraph.ALIGN_LEFT);
        Phrase phrase = new Phrase(LEADING, "\n\n", getFont());
        p.add(phrase);/*  w  w w.j ava 2s  .c om*/
        phrase = new Phrase(LEADING, "Diagrams:", obsfont);
        p.add(phrase);
        getDocument().add(p);
    }

    for (EFormValue value : diagrams) {
        //this is a form from our group, and our appt
        String imgPath = OscarProperties.getInstance().getProperty("eform_image");
        EFormValue imageName = eFormValueDao.findByFormDataIdAndKey(value.getFormDataId(), "image");
        EFormValue drawData = eFormValueDao.findByFormDataIdAndKey(value.getFormDataId(), "DrawData");
        EFormValue subject = eFormValueDao.findByFormDataIdAndKey(value.getFormDataId(), "subject");

        String image = imgPath + File.separator + imageName.getVarValue();
        logger.debug("image for eform is " + image);
        GraphicalCanvasToImage convert = new GraphicalCanvasToImage();
        File tempFile = null;
        try {
            tempFile = File.createTempFile("graphicImg", ".png");
            FileOutputStream fos = new FileOutputStream(tempFile);
            convert.convertToImage(image, drawData.getVarValue(), "PNG", fos);
            logger.debug("converted image is " + tempFile.getName());
            fos.close();
        } catch (IOException e) {
            logger.error("Error", e);
            if (tempFile != null) {
                tempFile.delete();
            }
            continue;
        }

        Image img = null;
        try {
            logger.info("adding diagram " + tempFile.getAbsolutePath());
            img = Image.getInstance(tempFile.getAbsolutePath());
        } catch (IOException e) {
            logger.error("error:", e);
            continue;
        }
        img.scaleToFit(getDocument().getPageSize().getWidth() - getDocument().leftMargin()
                - getDocument().rightMargin(), getDocument().getPageSize().getHeight());
        Paragraph p = new Paragraph();
        p.add(img);
        p.add(new Phrase("Subject:" + subject.getVarValue(), getFont()));
        getDocument().add(p);

        tempFile.deleteOnExit();
    }

}

From source file:org.oscarehr.eyeform.web.OcularProcPrint.java

License:Open Source License

@Override
public void printExt(CaseManagementPrintPdf engine, HttpServletRequest request)
        throws IOException, DocumentException {
    logger.info("ocular procedure print!!!!");
    String startDate = request.getParameter("pStartDate");
    String endDate = request.getParameter("pEndDate");
    String demographicNo = request.getParameter("demographicNo");

    logger.info("startDate = " + startDate);
    logger.info("endDate = " + endDate);
    logger.info("demographicNo = " + demographicNo);

    OcularProcDao dao = (OcularProcDao) SpringUtils.getBean("OcularProcDAO");
    ProviderDao providerDao = (ProviderDao) SpringUtils.getBean("providerDao");

    List<EyeformOcularProcedure> procs = null;

    if (startDate.equals("") && endDate.equals("")) {
        procs = dao.getByDemographicNo(Integer.parseInt(demographicNo));
    } else {//w  w w  . j  a v a  2  s  . c om
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
            Date dStartDate = formatter.parse(startDate);
            Date dEndDate = formatter.parse(endDate);
            procs = dao.getByDateRange(Integer.parseInt(demographicNo), dStartDate, dEndDate);
        } catch (Exception e) {
            logger.error(e);
        }

    }

    if (engine.getNewPage())
        engine.getDocument().newPage();
    else
        engine.setNewPage(true);

    Font obsfont = new Font(engine.getBaseFont(), engine.FONTSIZE, Font.UNDERLINE);

    Paragraph p = new Paragraph();
    p.setAlignment(Paragraph.ALIGN_CENTER);
    Phrase phrase = new Phrase(engine.LEADING, "\n\n", engine.getFont());
    p.add(phrase);
    phrase = new Phrase(engine.LEADING, "Ocular Procedures", obsfont);
    p.add(phrase);
    engine.getDocument().add(p);

    for (EyeformOcularProcedure proc : procs) {
        p = new Paragraph();
        phrase = new Phrase(engine.LEADING, "", engine.getFont());
        Chunk chunk = new Chunk("Documentation Date: " + engine.getFormatter().format(proc.getDate()) + "\n",
                obsfont);
        phrase.add(chunk);
        p.add(phrase);
        p.add("Name:" + proc.getProcedureName() + "\n");
        p.add("Location:" + proc.getLocation() + "\n");
        p.add("Eye:" + proc.getEye() + "\n");
        p.add("Doctor:" + providerDao.getProviderName(proc.getDoctor()) + "\n");
        p.add("Note:" + proc.getProcedureNote() + "\n");

        engine.getDocument().add(p);
    }

}

From source file:org.oscarehr.eyeform.web.SpecsHistoryPrint.java

License:Open Source License

@Override
public void printExt(CaseManagementPrintPdf engine, HttpServletRequest request)
        throws IOException, DocumentException {
    logger.info("specs history print!!!!");
    String startDate = request.getParameter("pStartDate");
    String endDate = request.getParameter("pEndDate");
    String demographicNo = request.getParameter("demographicNo");

    logger.info("startDate = " + startDate);
    logger.info("endDate = " + endDate);
    logger.info("demographicNo = " + demographicNo);

    ProviderDao providerDao = (ProviderDao) SpringUtils.getBean("providerDao");
    SpecsHistoryDao dao = (SpecsHistoryDao) SpringUtils.getBean("SpecsHistoryDAO");

    List<EyeformSpecsHistory> specs = null;

    if (startDate.equals("") && endDate.equals("")) {
        specs = dao.getByDemographicNo(Integer.parseInt(demographicNo));
    } else {//from  ww w. j a  va  2 s.c o m
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
            Date dStartDate = formatter.parse(startDate);
            Date dEndDate = formatter.parse(endDate);
            specs = dao.getByDateRange(Integer.parseInt(demographicNo), dStartDate, dEndDate);
        } catch (Exception e) {
            logger.error(e);
        }

    }

    if (engine.getNewPage())
        engine.getDocument().newPage();
    else
        engine.setNewPage(true);

    Font obsfont = new Font(engine.getBaseFont(), engine.FONTSIZE, Font.UNDERLINE);

    Paragraph p = new Paragraph();
    p.setAlignment(Paragraph.ALIGN_CENTER);
    Phrase phrase = new Phrase(engine.LEADING, "\n\n", engine.getFont());
    p.add(phrase);
    phrase = new Phrase(engine.LEADING, "Specs History", obsfont);
    p.add(phrase);
    engine.getDocument().add(p);

    for (EyeformSpecsHistory spec : specs) {
        p = new Paragraph();
        phrase = new Phrase(engine.LEADING, "", engine.getFont());
        Chunk chunk = new Chunk("Documentation Date: " + engine.getFormatter().format(spec.getDate()) + "\n",
                obsfont);
        phrase.add(chunk);
        p.add(phrase);
        p.add("Type:" + spec.getType() + "\n");
        p.add("Details:" + spec.toString().replaceAll("<br/>", "    ") + "\n");
        p.add("Doctor:" + providerDao.getProviderName(spec.getDoctor()) + "\n");

        engine.getDocument().add(p);
    }

}

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;//from   ww w. j  a  va2s.c  o  m

    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.oscarehr.web.reports.ocan.NeedRatingOverTimeReportGenerator.java

License:Open Source License

private void addSummaryOfNeedsHeader(PdfPTable summaryOfNeedsTable,
        List<OcanNeedRatingOverTimeSummaryOfNeedsBean> currentBeanList, int loopNo) {

    PdfPCell headerCell = new PdfPCell();
    headerCell.setPhrase(new Phrase("Summary of Needs" + (loopNo > 1 ? " (Contd.)" : ""),
            new Font(Font.HELVETICA, 20, Font.BOLD)));

    headerCell.setColspan(currentBeanList.size() * 3);
    headerCell.setVerticalAlignment(Element.ALIGN_TOP);
    headerCell.setBorder(0);/*from  www.j ava  2  s . com*/
    headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    summaryOfNeedsTable.addCell(headerCell);

    Font f = new Font(Font.HELVETICA, 14, Font.BOLD, Color.WHITE);
    //row1
    PdfPCell c2 = null;

    c2 = new PdfPCell();
    c2.setBorder(0);
    summaryOfNeedsTable.addCell(c2);
    if (currentBeanList.size() > 0) {
        c2 = new PdfPCell();
        c2.setColspan(2);
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase(currentBeanList.get(0).getOcanName() + "\n"
                + dateFormatter.format(currentBeanList.get(0).getOcanDate()), f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
    }
    if (currentBeanList.size() > 1) {
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLACK);
        summaryOfNeedsTable.addCell(c2);
        c2 = new PdfPCell();
        c2.setColspan(2);
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase(currentBeanList.get(1).getOcanName() + "\n"
                + dateFormatter.format(currentBeanList.get(1).getOcanDate()), f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
    }
    if (currentBeanList.size() > 2) {
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLACK);
        summaryOfNeedsTable.addCell(c2);
        c2 = new PdfPCell();
        c2.setColspan(2);
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase(currentBeanList.get(2).getOcanName() + "\n"
                + dateFormatter.format(currentBeanList.get(2).getOcanDate()), f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
    }

    //row2
    c2 = new PdfPCell();
    c2.setBorder(0);
    summaryOfNeedsTable.addCell(c2);

    if (currentBeanList.size() > 0) {
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase("Consumer", f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase("Staff", f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
    }
    if (currentBeanList.size() > 1) {
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLACK);
        summaryOfNeedsTable.addCell(c2);
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase("Consumer", f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase("Staff", f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
    }
    if (currentBeanList.size() > 2) {
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLACK);
        summaryOfNeedsTable.addCell(c2);
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase("Consumer", f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
        c2 = new PdfPCell();
        c2.setBackgroundColor(Color.BLUE);
        c2.setPhrase(new Phrase("Staff", f));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        summaryOfNeedsTable.addCell(c2);
    }
}

From source file:org.posterita.businesslogic.performanceanalysis.POSReportManager.java

License:Open Source License

public static String getCompleteOrderPDFReport(Properties ctx, int orderId, String trxName)
        throws OperationException {
    String docStatus = null;// w w  w .ja  va 2  s. c  o  m
    String dateOrdered = null;
    String orderType = null;
    String orgName = null;
    String orgAddress = null;
    String salesRep = null;
    String paymentBy = null;
    String customerName = null;
    String customerAddress = null;
    String documentNo = null;
    String currency = "Rs ";
    NumberFormat formatter = new DecimalFormat("###,###,##0.00");

    currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol() + " ";
    MOrder order = new MOrder(ctx, orderId, trxName);

    // getting payment info
    int[] invoiceIds = MInvoice.getAllIDs(MInvoice.Table_Name,
            "AD_CLIENT_ID=" + Env.getAD_Client_ID(ctx) + " and C_ORDER_ID=" + order.get_ID(), null);
    double paymentByCash = 0.0;
    double paymentByCard = 0.0;
    double paymentByCheque = 0.0;

    MInvoice invoice = null;
    String paymentRule = null;
    boolean isMixed = false;

    for (int i = 0; i < invoiceIds.length; i++) {
        invoice = new MInvoice(ctx, invoiceIds[i], trxName);

        if (i == 0) {
            paymentRule = invoice.getPaymentRule();
        } else {
            if (!paymentRule.equalsIgnoreCase(invoice.getPaymentRule())) {
                isMixed = true;
            }
        }

        if (invoice.getPaymentRule().equals(MOrder.PAYMENTRULE_Cash)) {
            paymentByCash += invoice.getGrandTotal().doubleValue();
            paymentBy = Constants.PAYMENT_RULE_CASH;
        }

        if (invoice.getPaymentRule().equals(MOrder.PAYMENTRULE_CreditCard)) {
            paymentByCard += invoice.getGrandTotal().doubleValue();
            paymentBy = Constants.PAYMENT_RULE_CARD;
        }

        if (invoice.getPaymentRule().equals(MOrder.PAYMENTRULE_DirectDebit)) {
            paymentByCard += invoice.getGrandTotal().doubleValue();
            paymentBy = Constants.PAYMENT_RULE_CARD;
        }

        if (invoice.getPaymentRule().equals(MOrder.PAYMENTRULE_Check)) {
            paymentByCheque += invoice.getGrandTotal().doubleValue();
            paymentBy = Constants.PAYMENT_RULE_CHEQUE;
        }

    } // for

    if (isMixed) {
        paymentBy = "Mixed (Cash:" + formatter.format(paymentByCash) + " Card:"
                + formatter.format(paymentByCard) + " Cheque:" + formatter.format(paymentByCheque) + ")";
    }

    // getting orgInfo
    MOrg org = new MOrg(ctx, order.getAD_Org_ID(), trxName);
    int location_id = org.getInfo().getC_Location_ID();
    MLocation location = new MLocation(ctx, location_id, trxName);

    orgName = org.getName();

    String address1 = (location.getAddress1() == null) ? " " : location.getAddress1();
    String address2 = (location.getAddress2() == null) ? " " : location.getAddress2();
    orgAddress = (address1 + " " + address2).trim();

    // getting order type
    orderType = order.getOrderType();

    // getting orderInfo
    docStatus = order.getDocStatusName();
    documentNo = order.getDocumentNo();

    Date d = new Date(order.getCreated().getTime());
    SimpleDateFormat s = new SimpleDateFormat(TimestampConvertor.DEFAULT_DATE_PATTERN1);
    dateOrdered = s.format(d);

    // getting salesrep
    int saleRep_id = order.getSalesRep_ID();
    MUser user = new MUser(ctx, saleRep_id, trxName);
    salesRep = user.getName();

    // getting customer info
    int bpartner_id = order.getBill_BPartner_ID();
    BPartnerBean bean = BPartnerManager.getBpartner(ctx, bpartner_id, trxName);

    String name1 = (bean.getPartnerName() == null) ? " " : bean.getPartnerName();
    String name2 = (bean.getName2() == null) ? " " : bean.getName2();
    customerName = (name1 + " " + name2).trim();

    address1 = (bean.getAddress1() == null) ? " " : bean.getAddress1();
    address2 = (bean.getAddress2() == null) ? " " : bean.getAddress2();
    customerAddress = (address1 + " " + address2).trim();

    ArrayList<WebOrderLineBean> orderLineList = POSManager.populateOrderLines(ctx, order);

    // ----------------------------------- generating pdf
    // --------------------------------------
    String reportName = RandomStringGenerator.randomstring() + ".pdf";
    String reportPath = ReportManager.getReportPath(reportName);

    Font titleFont = new Font(Font.TIMES_ROMAN, 18, Font.BOLD);
    Font subtitleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD);

    Font headerFont = new Font(Font.TIMES_ROMAN, 11, Font.BOLD);
    Font simpleFont = new Font(Font.TIMES_ROMAN, 10);

    float cellBorderWidth = 0.0f;

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 30, 30, 20, 40);// l,r,t,b
    // document.getPageSize().set;

    System.out.println(document.leftMargin());

    try {
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter.getInstance(document, new FileOutputStream(reportPath));

        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document

        Image logo = null;

        String imageURI = PathInfo.PROJECT_HOME + "images/logo.gif";
        // "images/pos/openBLUE_POS_Logo.gif";

        try {
            byte logoData[] = OrganisationManager.getLogo(ctx, null);
            logo = Image.getInstance(logoData);
        } catch (LogoException ex) {
            logo = Image.getInstance(imageURI);
        }

        logo.setAbsolutePosition(document.left(), document.top() - logo.getHeight());
        document.add(logo);

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = null;

        //
        table.getDefaultCell().setPadding(5.0f);
        table.setWidthPercentage(100.0f);

        // header cell
        Paragraph title = new Paragraph();
        title.add(new Chunk(orgName, subtitleFont));
        title.add(new Chunk("\n"));
        title.add(new Chunk(orgAddress, subtitleFont));

        // cell = new PdfPCell(new Paragraph(new
        // Chunk("Title1",titleFont)));
        cell = new PdfPCell(title);

        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setFixedHeight(logo.getHeight());
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // doc type
        cell = new PdfPCell(new Paragraph(new Chunk(orderType, titleFont)));

        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // row 1
        cell = new PdfPCell(new Paragraph(new Chunk(customerName, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph(new Chunk("Sales Rep: " + salesRep, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 2
        cell = new PdfPCell(new Paragraph(new Chunk(customerAddress, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // row 3
        cell = new PdfPCell(new Paragraph(new Chunk("Ref No: " + documentNo, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 4
        cell = new PdfPCell(new Paragraph(new Chunk("Doc Status: " + docStatus, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 5
        cell = new PdfPCell(new Paragraph(new Chunk("Payment By: " + paymentBy, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 6
        cell = new PdfPCell(new Paragraph(new Chunk("Date: " + dateOrdered, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setColspan(2);
        cell.setFixedHeight(10);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setColspan(2);
        cell.setFixedHeight(10);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // ------------------------------------------------------
        cell = new PdfPCell();
        cell.setColspan(2);
        cell.setBorderWidth(cellBorderWidth);

        PdfPTable t = new PdfPTable(6);
        t.getDefaultCell().setPadding(3.0f);
        t.setWidthPercentage(100.0f);

        int[] widths = { 1, 4, 1, 2, 2, 2 };
        t.setWidths(widths);

        // setting headers
        t.addCell(new Paragraph(new Chunk("SerNo", headerFont)));
        t.addCell(new Paragraph(new Chunk("Name", headerFont)));
        t.addCell(new Paragraph(new Chunk("Qty", headerFont)));
        t.addCell(new Paragraph(new Chunk("Price", headerFont)));
        t.addCell(new Paragraph(new Chunk("VAT", headerFont)));
        t.addCell(new Paragraph(new Chunk("Total", headerFont)));

        // setting table data
        // --------------------------------writing table
        // data------------------------------
        int serNo = 0;
        int totalQty = 0;
        double totalAmt = 0.0;
        double totalTaxAmt = 0.0;
        double grandTotal = 0.0;

        BigDecimal qty = null;
        BigDecimal lineAmt = null;
        BigDecimal taxAmt = null;
        BigDecimal lineTotalAmt = null;

        for (WebOrderLineBean orderlineBean : orderLineList) {
            serNo++;
            qty = orderlineBean.getQtyOrdered();
            lineAmt = orderlineBean.getLineNetAmt();
            taxAmt = orderlineBean.getTaxAmt();
            lineTotalAmt = orderlineBean.getLineTotalAmt();

            totalQty += qty.intValue();
            totalAmt += lineAmt.doubleValue();
            totalTaxAmt += taxAmt.doubleValue();
            grandTotal += lineTotalAmt.doubleValue();

            t.addCell(new Paragraph(new Chunk(serNo + "", simpleFont)));
            t.addCell(new Paragraph(new Chunk(orderlineBean.getProductName(), simpleFont)));
            t.addCell(new Paragraph(new Chunk(qty.intValue() + "", simpleFont)));
            t.addCell(new Paragraph(new Chunk(formatter.format(lineAmt.doubleValue()), simpleFont)));
            t.addCell(new Paragraph(new Chunk(formatter.format(taxAmt.doubleValue()), simpleFont)));
            t.addCell(new Paragraph(new Chunk(formatter.format(lineTotalAmt.doubleValue()), simpleFont)));
        }
        // -----------------------------------------------------------------------------------

        // setting table footer
        t.getDefaultCell().setBackgroundColor(new Color(240, 240, 240));

        PdfPCell c = new PdfPCell(new Paragraph(new Chunk("ORDER TOTAL", headerFont)));
        c.setColspan(2);
        c.setBackgroundColor(new Color(240, 240, 240));
        t.addCell(c);

        t.addCell(new Paragraph(new Chunk(totalQty + "", simpleFont)));
        t.addCell(new Paragraph(new Chunk(currency + formatter.format(totalAmt), simpleFont)));
        t.addCell(new Paragraph(new Chunk(currency + formatter.format(totalTaxAmt), simpleFont)));
        t.addCell(new Paragraph(new Chunk(currency + formatter.format(grandTotal), simpleFont)));

        t.setSplitRows(true);
        cell.addElement(t);
        // ------------------------------------------------------

        // table.addCell(cell);
        table.setSplitRows(true);

        document.add(table);
        document.add(t);

    } catch (Exception e) {
        throw new OperationException(e);
    }

    // step 5: we close the document
    document.close();

    return reportName;
}

From source file:org.posterita.businesslogic.performanceanalysis.POSReportManager.java

License:Open Source License

public static String getShipmentPDFReport(Properties ctx, int minoutId, String trxName)
        throws OperationException {
    String docStatus = null;/*from   www. java2s. co  m*/
    String dateOrdered = null;
    String docType = null;
    String orgName = null;
    String orgAddress = null;
    String salesRep = null;
    String phone = "      ";
    String fax = "       ";

    String customerName = null;
    String customerAddress = null;
    String documentNo = null;

    MInOut minout = MinOutManager.loadMInOut(ctx, minoutId, trxName);

    // getting orgInfo
    MOrg org = new MOrg(ctx, minout.getAD_Org_ID(), trxName);
    int location_id = org.getInfo().getC_Location_ID();
    MLocation location = new MLocation(ctx, location_id, trxName);
    MBPartner orgPartner = new MBPartner(ctx, org.getLinkedC_BPartner_ID(trxName), trxName);
    MBPartnerLocation meLocation[] = MBPartnerLocation.getForBPartner(ctx, orgPartner.get_ID());

    if (meLocation.length != 1)
        throw new OperationException("Should have only 1 location for organisation business partner!!");

    MBPartnerLocation orgLocation = meLocation[0];

    if (orgLocation.getPhone() != null)
        phone = orgLocation.getPhone();

    if (orgLocation.getFax() != null)
        fax = orgLocation.getFax();
    ;

    orgName = org.getName();

    String address1 = (location.getAddress1() == null) ? " " : location.getAddress1();
    String address2 = (location.getAddress2() == null) ? " " : location.getAddress2();
    orgAddress = (address1 + " " + address2).trim();

    // getting order type
    MDocType doctype = MDocType.get(ctx, minout.getC_DocType_ID());
    docType = doctype.getName();

    // getting orderInfo
    docStatus = minout.getDocStatusName();
    documentNo = minout.getDocumentNo();

    Date d = new Date(minout.getCreated().getTime());
    SimpleDateFormat s = new SimpleDateFormat(TimestampConvertor.DEFAULT_DATE_PATTERN1);
    dateOrdered = s.format(d);

    // getting salesrep
    int saleRep_id = minout.getSalesRep_ID();
    MUser user = new MUser(ctx, saleRep_id, trxName);
    salesRep = user.getName();

    // getting customer info
    int bpartner_id = minout.getC_BPartner_ID();
    BPartnerBean bean = BPartnerManager.getBpartner(ctx, bpartner_id, trxName);

    String name1 = (bean.getPartnerName() == null) ? " " : bean.getPartnerName();
    String name2 = (bean.getName2() == null) ? " " : bean.getName2();
    customerName = (name1 + " " + name2).trim();

    address1 = (bean.getAddress1() == null) ? " " : bean.getAddress1();
    address2 = (bean.getAddress2() == null) ? " " : bean.getAddress2();
    customerAddress = (address1 + " " + address2).trim();

    ArrayList<WebMinOutLineBean> orderLineList = MinOutManager.getWebMinOutLines(ctx, minout);

    // ----------------------------------- generating pdf
    // --------------------------------------
    String reportName = RandomStringGenerator.randomstring() + ".pdf";
    String reportPath = ReportManager.getReportPath(reportName);

    Font titleFont = new Font(Font.TIMES_ROMAN, 18, Font.BOLD);
    Font subtitleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD);

    Font headerFont = new Font(Font.TIMES_ROMAN, 11, Font.BOLD);
    Font simpleFont = new Font(Font.TIMES_ROMAN, 10);

    float cellBorderWidth = 0.0f;

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 30, 30, 20, 40);// l,r,t,b
    // document.getPageSize().set;

    System.out.println(document.leftMargin());

    try {
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter.getInstance(document, new FileOutputStream(reportPath));

        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document

        Image logo = null;

        // TODO: make this part dynamic <------------------------------
        // IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!
        String imageURI = PathInfo.PROJECT_HOME + "images/pos/openBLUE_POS_Logo.gif";
        logo = Image.getInstance(imageURI);

        // MAttachment attachment = new
        // MAttachment(ctx,MOrg.Table_ID,org.getID(),null);
        // logo = Image.getInstance(attachment.getEntries()[0].getData());

        try {
            byte logoData[] = OrganisationManager.getLogo(ctx, null);
            logo = Image.getInstance(logoData);
        } catch (LogoException ex) {
            logo = Image.getInstance(imageURI);
        }

        logo.setAbsolutePosition(document.left(), document.top() - logo.getHeight());
        document.add(logo);

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = null;

        //
        table.getDefaultCell().setPadding(5.0f);
        table.setWidthPercentage(100.0f);

        // header cell
        Paragraph title = new Paragraph();
        title.add(new Chunk(orgName, subtitleFont));
        title.add(new Chunk("\n"));
        title.add(new Chunk(orgAddress, subtitleFont));
        title.add(new Chunk("\n"));
        title.add(new Chunk("Phone: " + phone, subtitleFont));
        title.add(new Chunk("\n"));
        title.add(new Chunk("Fax: " + fax, subtitleFont));

        // cell = new PdfPCell(new Paragraph(new
        // Chunk("Title1",titleFont)));
        cell = new PdfPCell(title);

        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setFixedHeight(logo.getHeight());
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // doc type
        cell = new PdfPCell(new Paragraph(new Chunk(docType, titleFont)));

        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // row 1
        cell = new PdfPCell(new Paragraph(new Chunk(customerName, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph(new Chunk("Sales Rep: " + salesRep, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 2
        cell = new PdfPCell(new Paragraph(new Chunk(customerAddress, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // row 3
        cell = new PdfPCell(new Paragraph(new Chunk("No: " + documentNo, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 4
        cell = new PdfPCell(new Paragraph(new Chunk("Doc Status: " + docStatus, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        /*
         * //row 5 cell = new PdfPCell(new Paragraph(new Chunk("Payment By:
         * "+paymentBy,headerFont))); cell.setColspan(2);
         * cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
         * cell.setBorderWidth(cellBorderWidth); table.addCell(cell);
         */

        // row 6
        cell = new PdfPCell(new Paragraph(new Chunk("Date: " + dateOrdered, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setColspan(2);
        cell.setFixedHeight(10);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setColspan(2);
        cell.setFixedHeight(10);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // ------------------------------------------------------
        cell = new PdfPCell();
        cell.setColspan(2);
        cell.setBorderWidth(cellBorderWidth);

        PdfPTable t = new PdfPTable(3);
        t.getDefaultCell().setPadding(3.0f);
        t.setWidthPercentage(100.0f);

        int[] widths = { 1, 10, 1 };
        t.setWidths(widths);

        // setting headers
        t.addCell(new Paragraph(new Chunk("SerNo", headerFont)));
        t.addCell(new Paragraph(new Chunk("Name", headerFont)));
        t.addCell(new Paragraph(new Chunk("Qty", headerFont)));

        // setting table data
        // --------------------------------writing table
        // data------------------------------
        int serNo = 0;

        BigDecimal qty = null;

        for (WebMinOutLineBean orderlineBean : orderLineList) {
            serNo++;
            qty = orderlineBean.getQtyOrdered();

            t.addCell(new Paragraph(new Chunk(serNo + "", simpleFont)));
            t.addCell(new Paragraph(new Chunk(orderlineBean.getProductName(), simpleFont)));
            t.addCell(new Paragraph(new Chunk(qty.intValue() + "", simpleFont)));
        }
        // -----------------------------------------------------------------------------------

        // table.addCell(cell);
        table.setSplitRows(true);

        document.add(table);
        document.add(t);

    } catch (Exception e) {
        throw new OperationException(e);
    }

    // step 5: we close the document
    document.close();

    return reportName;
}