Example usage for com.lowagie.text Paragraph setAlignment

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

Introduction

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

Prototype

public void setAlignment(String alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

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  av  a 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 {//from www.  j  av  a  2 s  . c o  m
        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  v  a 2  s  .  c om
        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.web.reports.ocan.IndividualNeedRatingOverTimeReportGenerator.java

License:Open Source License

public void generateReport(OutputStream os) throws Exception {
    Document d = new Document(PageSize.A4.rotate());
    d.setMargins(20, 20, 20, 20);//from   www.  j a  v a2 s . c om
    PdfWriter writer = PdfWriter.getInstance(d, os);
    writer.setStrictImageSequence(true);
    d.open();

    //header
    Paragraph p = new Paragraph("Individual Need Rating Over Time", titleFont);
    p.setAlignment(Element.ALIGN_CENTER);
    d.add(p);
    d.add(Chunk.NEWLINE);

    //purpose
    Paragraph purpose = new Paragraph();
    purpose.add(new Chunk("Purpose of Report:", boldText));
    purpose.add(new Phrase(
            "The purpose of this report is to show change over time in a specific Need Rating for an individual Consumer. It adds up the number of needs across all Domains grouped by Need Rating (e.g. Unmet Needs, Met Needs, No Needs, Unknown) for all selected OCANs that were conducted with the Consumer and displays the results in an individual need rating line graph. Each line graph that is displayed compares the Consumer and the Staff's perspective. The staff may share this report with their Consumer as well.",
            normalText));
    d.add(purpose);
    d.add(Chunk.NEWLINE);

    //report parameters
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(makeCell(createFieldNameAndValuePhrase("Consumer Name:", reportBean.getConsumerName()),
            Element.ALIGN_LEFT));
    table.addCell(makeCell(
            createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(reportBean.getReportDate())),
            Element.ALIGN_RIGHT));
    table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", reportBean.getStaffName()),
            Element.ALIGN_LEFT));
    table.addCell("");
    d.add(table);
    d.add(Chunk.NEWLINE);

    int height = 260;

    if (reportBean.isShowUnmetNeeds()) {
        d.add(Image.getInstance(reportBean.getUnmetNeedsChart()
                .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null));
    }

    if (reportBean.isShowMetNeeds()) {
        d.add(Image.getInstance(reportBean.getMetNeedsChart()
                .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null));
    }

    if (reportBean.isShowNoNeeds()) {
        d.add(Image.getInstance(reportBean.getNoNeedsChart()
                .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null));
    }
    if (reportBean.isShowUnknownNeeds()) {
        d.add(Image.getInstance(reportBean.getUnknownNeedsChart()
                .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null));
    }

    d.close();
}

From source file:org.oscarehr.web.reports.ocan.NeedRatingOverTimeReportGenerator.java

License:Open Source License

public void generateReport(OutputStream os) throws Exception {
    Document d = new Document(PageSize.A4.rotate());
    d.setMargins(20, 20, 20, 20);/*w  ww.j a v a 2s .  c om*/
    PdfWriter writer = PdfWriter.getInstance(d, os);
    writer.setStrictImageSequence(true);
    d.open();

    //header
    Paragraph p = new Paragraph("Needs Over Time (Consumer and Staff)", titleFont);
    p.setAlignment(Element.ALIGN_CENTER);
    d.add(p);
    d.add(Chunk.NEWLINE);

    //purpose
    Paragraph purpose = new Paragraph();
    purpose.add(new Chunk("Purpose of Report:", boldText));
    purpose.add(new Phrase(
            "The purpose of this report is to show change over time in a specific Need Rating for an individual Consumer. It adds up the number of needs across all Domains grouped by Need Rating (e.g. Unmet Needs, Met Needs, No Needs, Unknown) for all selected OCANs that were conducted with the Consumer and displays the results in an individual need rating line graph. Each line graph that is displayed compares the Consumer and the Staff's perspective. The staff may share this report with their Consumer as well.",
            normalText));
    d.add(purpose);
    d.add(Chunk.NEWLINE);

    //report parameters
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(
            makeCell(createFieldNameAndValuePhrase("Consumer Name:", getConsumerName()), Element.ALIGN_LEFT));
    table.addCell(makeCell(createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(getReportDate())),
            Element.ALIGN_RIGHT));
    table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", getStaffName()), Element.ALIGN_LEFT));
    table.addCell("");
    d.add(table);
    d.add(Chunk.NEWLINE);

    //loop here...groups of 3
    int loopNo = 1;
    List<OcanNeedRatingOverTimeSummaryOfNeedsBean> summaryBeanList = new ArrayList<OcanNeedRatingOverTimeSummaryOfNeedsBean>();
    summaryBeanList.addAll(this.summaryOfNeedsBeanList);

    while (true) {
        if (summaryBeanList.size() == 0) {
            break;
        }
        List<OcanNeedRatingOverTimeSummaryOfNeedsBean> currentBeanList = new ArrayList<OcanNeedRatingOverTimeSummaryOfNeedsBean>();
        for (int x = 0; x < 3; x++) {
            if (summaryBeanList.size() == 0) {
                break;
            }
            currentBeanList.add(summaryBeanList.remove(0));
        }

        //summary of needs
        PdfPTable summaryOfNeedsTable = null;
        if (currentBeanList.size() == 1) {
            summaryOfNeedsTable = new PdfPTable(3);
            summaryOfNeedsTable.setWidthPercentage(100f - 52.8f);
            summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f });
        }
        if (currentBeanList.size() == 2) {
            summaryOfNeedsTable = new PdfPTable(6);
            summaryOfNeedsTable.setWidthPercentage(100f - 26.4f);
            summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f });
        }
        if (currentBeanList.size() == 3) {
            summaryOfNeedsTable = new PdfPTable(9);
            summaryOfNeedsTable.setWidthPercentage(100f);
            summaryOfNeedsTable
                    .setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f });
        }
        summaryOfNeedsTable.setHorizontalAlignment(Element.ALIGN_LEFT);
        summaryOfNeedsTable.setHeaderRows(3);

        addSummaryOfNeedsHeader(summaryOfNeedsTable, currentBeanList, loopNo);
        addSummaryOfNeedsRow(summaryOfNeedsTable, "Unmet Needs", "unmet", currentBeanList);
        addSummaryOfNeedsRow(summaryOfNeedsTable, "Met Needs", "met", currentBeanList);
        addSummaryOfNeedsRow(summaryOfNeedsTable, "No Needs", "no", currentBeanList);
        addSummaryOfNeedsRow(summaryOfNeedsTable, "Unknown Needs", "unknown", currentBeanList);

        d.add(summaryOfNeedsTable);
        d.add(Chunk.NEWLINE);

        if (summaryBeanList.size() == 0) {
            break;
        }
        loopNo++;
    }

    //BREAKDOWN OF SUMMARY OF NEEDS

    //loop here...groups of 3
    loopNo = 1;
    List<OcanNeedRatingOverTimeNeedBreakdownBean> breakdownBeanList = new ArrayList<OcanNeedRatingOverTimeNeedBreakdownBean>();
    breakdownBeanList.addAll(this.needBreakdownListByOCAN);
    OcanNeedRatingOverTimeNeedBreakdownBean lastBreakDownBean = null;
    while (true) {
        if (breakdownBeanList.size() == 0) {
            break;
        }
        List<OcanNeedRatingOverTimeNeedBreakdownBean> currentBeanList = new ArrayList<OcanNeedRatingOverTimeNeedBreakdownBean>();
        for (int x = 0; x < 3; x++) {
            if (breakdownBeanList.size() == 0) {
                break;
            }
            currentBeanList.add(breakdownBeanList.remove(0));
        }

        //summary of needs
        PdfPTable summaryOfNeedsTable = null;
        if (currentBeanList.size() == 1) {
            if (lastBreakDownBean == null) {
                summaryOfNeedsTable = new PdfPTable(3);
                summaryOfNeedsTable.setWidthPercentage(100f - 52.8f);
                summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f });
            } else {
                summaryOfNeedsTable = new PdfPTable(4);
                summaryOfNeedsTable.setWidthPercentage(100f - 52.8f);
                summaryOfNeedsTable.setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f });
            }
        }
        if (currentBeanList.size() == 2) {
            if (lastBreakDownBean == null) {
                summaryOfNeedsTable = new PdfPTable(6);
                summaryOfNeedsTable.setWidthPercentage(100f - 26.4f);
                summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f });
            } else {
                summaryOfNeedsTable = new PdfPTable(7);
                summaryOfNeedsTable.setWidthPercentage(100f - 26.4f);
                summaryOfNeedsTable
                        .setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f });
            }
        }
        if (currentBeanList.size() == 3) {
            if (lastBreakDownBean == null) {
                summaryOfNeedsTable = new PdfPTable(9);
                summaryOfNeedsTable.setWidthPercentage(100f);
                summaryOfNeedsTable.setWidths(
                        new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f });
            } else {
                summaryOfNeedsTable = new PdfPTable(10);
                summaryOfNeedsTable.setWidthPercentage(100f);
                summaryOfNeedsTable.setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f,
                        0.12f, 0.024f, 0.12f, 0.12f });
            }
        }
        summaryOfNeedsTable.setHorizontalAlignment(Element.ALIGN_LEFT);

        addSummaryOfNeedsDomainHeader(summaryOfNeedsTable, currentBeanList, loopNo);
        for (int x = 0; x < domains.size(); x++) {
            addSummaryOfNeedsDomainRow(summaryOfNeedsTable, x, getDomains(), currentBeanList,
                    lastBreakDownBean);
        }

        d.add(summaryOfNeedsTable);
        d.add(Chunk.NEWLINE);

        if (breakdownBeanList.size() == 0) {
            break;
        }
        if (currentBeanList.size() == 3) {
            lastBreakDownBean = currentBeanList.get(2);
        }
        loopNo++;
    }

    JFreeChart chart = generateNeedsOverTimeChart();
    BufferedImage image = chart.createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, 350);
    Image image2 = Image.getInstance(image, null);
    d.add(image2);

    d.close();
}

From source file:org.oscarehr.web.reports.ocan.SummaryOfActionsAndCommentsReportGenerator.java

License:Open Source License

public void generateReport(OutputStream os) throws Exception {
    Document d = new Document(PageSize.A4.rotate());
    d.setMargins(20, 20, 20, 20);/*from  w w  w .j  ava  2 s .c  o  m*/
    PdfWriter writer = PdfWriter.getInstance(d, os);
    writer.setStrictImageSequence(true);
    d.open();

    //header
    Paragraph p = new Paragraph("Summary of Actions and Comments", titleFont);
    p.setAlignment(Element.ALIGN_CENTER);
    d.add(p);
    d.add(Chunk.NEWLINE);

    //purpose
    Paragraph purpose = new Paragraph();
    purpose.add(new Chunk("Purpose of Report:", boldText));
    purpose.add(new Phrase(
            "This report displays a summary of Actions and Comments (both for the Consumer and the Staff) that were recorded in the selected OCANs for an individual Consumer. The report lists all the Actions and Comments associated to OCANs and Domains that were chosen by the Staff to be displayed. The Actions also list who is responsible for the Action and the Review Date for the Action. The Domains are categorized by need rating within within the current OCAN as well as displaying the need ratings from the previous OCANs. In the case of different need ratings by the Consumer and the Mental Health Worker, the higher need rating determines the category. The need ratings from highest to lowest are Unmet Needs, Met Needs, No Needs, and Unknown. The need rating given by the Consumer and the Staff are also displayed next to the Comments for each OCAN. This information can be passed along to other organizations if requested.",
            normalText));
    d.add(purpose);
    d.add(Chunk.NEWLINE);

    //report parameters
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(
            makeCell(createFieldNameAndValuePhrase("Consumer Name:", getConsumerName()), Element.ALIGN_LEFT));
    table.addCell(makeCell(createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(getReportDate())),
            Element.ALIGN_RIGHT));
    table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", getStaffName()), Element.ALIGN_LEFT));
    table.addCell("");
    d.add(table);
    d.add(Chunk.NEWLINE);

    if (reportBean == null) {
        d.close();
        return;
    }

    List<SummaryOfActionsAndCommentsDomainBean> unMetCategory = reportBean.getUnmetNeeds();
    List<SummaryOfActionsAndCommentsDomainBean> metCategory = reportBean.getMetNeeds();
    List<SummaryOfActionsAndCommentsDomainBean> noCategory = reportBean.getNoNeeds();
    List<SummaryOfActionsAndCommentsDomainBean> unknownCategory = reportBean.getUnknown();

    PdfPTable unmetTable = null;
    if (unMetCategory.size() > 0) {
        unmetTable = createNeedHeader("Unmet Needs");
    }
    for (SummaryOfActionsAndCommentsDomainBean domain : unMetCategory) {
        if (domain.getOcanBeans().size() > 0) {
            createDomainHeader(unmetTable, domain.getDomainName());
            for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) {
                createOcanEntry(unmetTable, ocanBean);
            }
        }
    }
    if (unmetTable != null) {
        d.add(unmetTable);
        d.add(Chunk.NEWLINE);
    }

    PdfPTable metTable = null;
    if (metCategory.size() > 0) {
        metTable = createNeedHeader("Met Needs");
    }
    for (SummaryOfActionsAndCommentsDomainBean domain : metCategory) {
        if (domain.getOcanBeans().size() > 0) {
            createDomainHeader(metTable, domain.getDomainName());
            for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) {
                createOcanEntry(metTable, ocanBean);
            }
        }
    }
    if (metTable != null) {
        d.add(metTable);
        d.add(Chunk.NEWLINE);
    }

    PdfPTable noTable = null;
    if (noCategory.size() > 0) {
        noTable = createNeedHeader("No Needs");
    }
    for (SummaryOfActionsAndCommentsDomainBean domain : noCategory) {
        if (domain.getOcanBeans().size() > 0) {
            createDomainHeader(noTable, domain.getDomainName());
            for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) {
                createOcanEntry(noTable, ocanBean);
            }
        }
    }
    if (noTable != null) {
        d.add(noTable);
        d.add(Chunk.NEWLINE);
    }

    PdfPTable unknownTable = null;
    if (unknownCategory.size() > 0) {
        unknownTable = createNeedHeader("Unknown");
    }
    for (SummaryOfActionsAndCommentsDomainBean domain : unknownCategory) {
        if (domain.getOcanBeans().size() > 0) {
            createDomainHeader(unknownTable, domain.getDomainName());
            for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) {
                createOcanEntry(unknownTable, ocanBean);
            }
        }
    }
    if (unknownTable != null) {
        d.add(unknownTable);
    }

    d.close();
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfCell.java

License:Open Source License

/**
 * Imports the Cell properties into the PatchRtfCell
 *
 * @param cell/*  w  w w .  jav  a2s  .c o m*/
 *          The Cell to import
 */
private void importCell(Cell cell) {
    this.content = new ArrayList<RtfBasicElement>();

    if (cell == null) {
        this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.CELL_BORDER,
                this.parentRow.getParentTable().getBorders());
        return;
    }

    if (cell instanceof PatchRtfCell) {
        PatchRtfCell rtfCell = (PatchRtfCell) cell;
        this.minimumHeight = rtfCell.minimumHeight;
    }

    this.colspan = cell.getColspan();
    this.rowspan = cell.getRowspan();
    if (cell.getRowspan() > 1) {
        this.mergeType = MERGE_VERT_PARENT;
    }
    if (cell instanceof PatchRtfCell) {
        this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.CELL_BORDER,
                ((PatchRtfCell) cell).getBorders());
    } else {
        this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.CELL_BORDER, cell.getBorder(),
                cell.getBorderWidth(), cell.getBorderColor());
    }
    this.verticalAlignment = cell.getVerticalAlignment();
    if (cell.getBackgroundColor() == null) {
        this.backgroundColor = new RtfColor(this.document, 255, 255, 255);
    } else {
        this.backgroundColor = new RtfColor(this.document, cell.getBackgroundColor());
    }

    this.cellPadding = (int) this.parentRow.getParentTable().getCellPadding();

    Iterator cellIterator = cell.getElements();
    Paragraph container = null;
    while (cellIterator.hasNext()) {
        try {
            Element element = (Element) cellIterator.next();
            // should we wrap it in a paragraph
            if (!(element instanceof Paragraph) && !(element instanceof List)) {
                if (container != null) {
                    container.add(element);
                } else {
                    container = new Paragraph();
                    container.setAlignment(cell.getHorizontalAlignment());
                    container.add(element);
                }
            } else {
                if (container != null) {
                    RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
                    for (int i = 0; i < rtfElements.length; i++) {
                        rtfElements[i].setInTable(true);
                        this.content.add(rtfElements[i]);
                    }
                    container = null;
                }
                // if horizontal alignment is undefined overwrite
                // with that of enclosing cell
                if (element instanceof Paragraph
                        && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) {
                    ((Paragraph) element).setAlignment(cell.getHorizontalAlignment());
                }

                RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(element);
                for (int i = 0; i < rtfElements.length; i++) {
                    rtfElements[i].setInTable(true);
                    this.content.add(rtfElements[i]);
                }
            }
        } catch (DocumentException de) {
            de.printStackTrace();
        }
    }
    if (container != null) {
        try {
            RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
            for (int i = 0; i < rtfElements.length; i++) {
                rtfElements[i].setInTable(true);
                this.content.add(rtfElements[i]);
            }
        } catch (DocumentException de) {
            de.printStackTrace();
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfCell.java

License:Open Source License

/**
 * Imports the Cell properties into the PatchRtfCell
 *
 * @param cell/* www  . j a v a  2 s.c  o  m*/
 *          The PdfPCell to import
 * @since 2.1.3
 */
private void importCell(PdfPCell cell) {
    this.content = new ArrayList<RtfBasicElement>();

    if (cell == null) {
        this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.CELL_BORDER,
                this.parentRow.getParentTable().getBorders());
        return;
    }

    // padding
    this.cellPadding = (int) this.parentRow.getParentTable().getCellPadding();
    this.cellPaddingBottom = cell.getPaddingBottom();
    this.cellPaddingTop = cell.getPaddingTop();
    this.cellPaddingRight = cell.getPaddingRight();
    this.cellPaddingLeft = cell.getPaddingLeft();

    // BORDERS
    this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.CELL_BORDER, cell.getBorder(),
            cell.getBorderWidth(), cell.getBorderColor());

    // border colors
    this.border = cell.getBorder();
    this.borderColor = cell.getBorderColor();
    this.borderColorBottom = cell.getBorderColorBottom();
    this.borderColorTop = cell.getBorderColorTop();
    this.borderColorLeft = cell.getBorderColorLeft();
    this.borderColorRight = cell.getBorderColorRight();

    // border widths
    this.borderWidth = cell.getBorderWidth();
    this.borderWidthBottom = cell.getBorderWidthBottom();
    this.borderWidthTop = cell.getBorderWidthTop();
    this.borderWidthLeft = cell.getBorderWidthLeft();
    this.borderWidthRight = cell.getBorderWidthRight();

    this.colspan = cell.getColspan();
    this.rowspan = 1; // cell.getRowspan();
    // if(cell.getRowspan() > 1) {
    // this.mergeType = MERGE_VERT_PARENT;
    // }

    this.verticalAlignment = cell.getVerticalAlignment();

    if (cell.getBackgroundColor() == null) {
        this.backgroundColor = new RtfColor(this.document, 255, 255, 255);
    } else {
        this.backgroundColor = new RtfColor(this.document, cell.getBackgroundColor());
    }

    // does it have column composite info?
    java.util.List compositeElements = cell.getCompositeElements();
    if (compositeElements != null) {
        Iterator cellIterator = compositeElements.iterator();
        // does it have column info?
        Paragraph container = null;
        while (cellIterator.hasNext()) {
            try {
                Element element = (Element) cellIterator.next();
                // should we wrap it in a paragraph
                if (!(element instanceof Paragraph) && !(element instanceof List)) {
                    if (container != null) {
                        container.add(element);
                    } else {
                        container = new Paragraph();
                        container.setAlignment(cell.getHorizontalAlignment());
                        container.add(element);
                    }
                } else {
                    if (container != null) {
                        RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
                        for (int i = 0; i < rtfElements.length; i++) {
                            rtfElements[i].setInTable(true);
                            this.content.add(rtfElements[i]);
                        }
                        container = null;
                    }
                    // if horizontal alignment is undefined overwrite
                    // with that of enclosing cell
                    if (element instanceof Paragraph
                            && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) {
                        ((Paragraph) element).setAlignment(cell.getHorizontalAlignment());
                    }

                    RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(element);
                    for (int i = 0; i < rtfElements.length; i++) {
                        rtfElements[i].setInTable(true);
                        this.content.add(rtfElements[i]);
                    }
                }
            } catch (DocumentException de) {
                de.printStackTrace();
            }
        }
        if (container != null) {
            try {
                RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
                for (int i = 0; i < rtfElements.length; i++) {
                    rtfElements[i].setInTable(true);
                    this.content.add(rtfElements[i]);
                }
            } catch (DocumentException de) {
                de.printStackTrace();
            }
        }
    }

    // does it have image info?

    Image img = cell.getImage();
    if (img != null) {
        try {
            RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(img);
            for (int i = 0; i < rtfElements.length; i++) {
                rtfElements[i].setInTable(true);
                this.content.add(rtfElements[i]);
            }
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // does it have phrase info?
    Phrase phrase = cell.getPhrase();
    if (phrase != null) {
        try {
            RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(phrase);
            for (int i = 0; i < rtfElements.length; i++) {
                rtfElements[i].setInTable(true);
                this.content.add(rtfElements[i]);
            }
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // does it have table info?
    PdfPTable table = cell.getTable();
    if (table != null) {
        this.add(table);
        // try {
        // RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(table);
        // for (int i = 0; i < rtfElements.length; i++) {
        // rtfElements[i].setInTable(true);
        // this.content.add(rtfElements[i]);
        // }
        // } catch (DocumentException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }
    }

}

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

License:Open Source License

public static String endOfTheDayPDF(Properties ctx, CloseTillBean bean) throws OperationException {
    String reportName = RandomStringGenerator.randomstring() + ".pdf";
    String reportPath = ReportManager.getReportPath(reportName);

    double beginningBalance = (bean.getBeginningBalance() == null ? 0
            : bean.getBeginningBalance().doubleValue());
    double statementDifference = (bean.getNetCashTrx() == null ? 0 : bean.getNetCashTrx().doubleValue());
    double transferAmount = (bean.getBalanceEntered() == null ? 0 : bean.getBalanceEntered().doubleValue());
    double differenceAmount = (bean.getDifference() == null ? 0 : bean.getDifference().doubleValue());
    double endingBalance = (bean.getEndingBalance() == null ? 0 : bean.getEndingBalance().doubleValue());
    double tillCashTotal = (bean.getCashTotal() == null ? 0 : bean.getCashTotal().doubleValue());
    double cashBeanCardTotal = (bean.getCardTotal() == null ? 0 : bean.getCardTotal().doubleValue());
    double tillCardTotal = (bean.getCardTotal() == null ? 0 : bean.getCardTotal().doubleValue());
    double cardDifference = (bean.getCardDifference() == null ? 0 : bean.getCardDifference().doubleValue());
    double cashBeanChequeTotal = (bean.getChequeTotal() == null ? 0 : bean.getChequeTotal().doubleValue());
    double tillChequeTotal = (bean.getChequeTotal() == null ? 0 : bean.getChequeTotal().doubleValue());
    double chequeDifference = (bean.getChequeDifference() == null ? 0
            : bean.getChequeDifference().doubleValue());
    double grandTotal = (bean.getGrandTotal() == null ? 0 : bean.getGrandTotal().doubleValue());

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

    // Font headerFont = new Font(Font.TIMES_ROMAN, 8,Font.BOLD);
    Font simpleFont = new Font(Font.TIMES_ROMAN, 8);

    final float NO_BORDER = 0.0f;
    // final float THIN_BORDER = 1.0f;

    String currency = "Rs ";
    NumberFormat formatter = new DecimalFormat("###,###,##0.00");
    PdfPCell cell = null;//from w  ww  .  j  a v  a 2s . co m

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A7, 3, 3, 2, 4);// l,r,t,b
    // document.getPageSize().set;

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

    try {
        currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol();
        PdfWriter.getInstance(document, new FileOutputStream(reportPath));

        document.open();

        PdfPTable layoutTbl = new PdfPTable(1);
        layoutTbl.getDefaultCell().setBorderWidth(NO_BORDER);
        layoutTbl.getDefaultCell().setPadding(2.0f);

        SimpleDateFormat sdf = new SimpleDateFormat(TimestampConvertor.DEFAULT_DATE_PATTERN1);
        Date today = new Date(System.currentTimeMillis());

        // 1.add title
        Paragraph title = new Paragraph(new Chunk("End of the Day Report", titleFont));
        title.setAlignment(Paragraph.ALIGN_CENTER);
        cell = new PdfPCell(title);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(NO_BORDER);
        layoutTbl.addCell(cell);

        Paragraph subTitle = new Paragraph(new Chunk(sdf.format(today), subtitleFont));
        subTitle.setAlignment(Paragraph.ALIGN_CENTER);
        cell = new PdfPCell(subTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(NO_BORDER);
        layoutTbl.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setFixedHeight(10);
        cell.setBorderWidth(NO_BORDER);
        layoutTbl.addCell(cell);

        // display report data
        PdfPTable table = new PdfPTable(2);
        Phrase phrase = null;

        // row 1
        phrase = new Phrase("Till No:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(bean.getTillName(), simpleFont);
        table.addCell(phrase);

        // row 2
        phrase = new Phrase("Begining Balance:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(beginningBalance), simpleFont);
        table.addCell(phrase);

        // row 3
        phrase = new Phrase("Net Cash Trx:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(statementDifference), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Till Balance Entered:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(transferAmount), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Difference:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(differenceAmount), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Ending Balance:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(endingBalance), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Cash Total:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(tillCashTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Card Amt Entered:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(cashBeanCardTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Card Total:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(tillCardTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Card Difference:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(cardDifference), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Cheque Amt Entered:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(cashBeanChequeTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Cheque Total:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(tillChequeTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Cheque Difference:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(chequeDifference), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Grand Total:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(grandTotal), simpleFont);
        table.addCell(phrase);

        layoutTbl.addCell(table);

        document.add(layoutTbl);

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

    document.close();

    return reportName;

}

From source file:org.posterita.core.PDFReportGenerator.java

License:Open Source License

public String getPDFReport(Properties ctx, ArrayList dataSource) throws OperationException {
    String filename = RandomStringGenerator.randomstring() + ".pdf";
    String dir = UDIFilePropertiesManager.getProperty().get(ctx, PropertiesConstant.UDI_HOME)
            + "/config/reports/pdf/";
    String filepath = dir + filename;

    //Generatting report

    //Initialising the datasource
    this.dataSource = dataSource;

    if (dataSource == null)
        throw new OperationException("Cannot generate report! Cause: empty datasource");

    Rectangle dimension = getDocumentDimension();
    Document document = new Document(dimension, MARGIN, MARGIN, MARGIN, MARGIN);

    try {/*w ww  .java  2  s. c o m*/
        writer = PdfWriter.getInstance(document, new FileOutputStream(filepath));
        writer.setPageEvent(new PDFReportPageEventHelper());

        document.open();

        //Add the title part
        Paragraph title = new Paragraph();
        Paragraph subTitle = new Paragraph();

        if (reportTitle != null) {
            title.add(new Chunk(reportTitle, TITLE_FONT));
            title.setAlignment(Element.ALIGN_CENTER);
            document.add(title);
        }

        if (reportSubTitle != null) {
            subTitle.add(new Chunk(reportSubTitle, SUBTITLE_FONT));
            subTitle.setAlignment(Element.ALIGN_CENTER);
            document.add(subTitle);
        }

        if ((reportSubTitle != null) || (reportTitle != null)) {
            document.add(new Paragraph(" "));
        }

        writeDocument(document);

        document.close();
        writer.close();

        return "config/report/pdf/" + filename;
    } catch (Exception e) {
        throw new OperationException(e);
    }

}