Example usage for com.lowagie.text Element ALIGN_RIGHT

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

Introduction

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

Prototype

int ALIGN_RIGHT

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

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java

License:Open Source License

/**
 * Builds the report cells./*from   w  w w .j ava 2 s  .  c o m*/
 */
protected void buildReportCells(Table table) throws BadElementException {
    int cellRow = 0;
    int tableRow = 2;
    Header[] rowHeaders = this._reportModel.getRowHeaders();
    NumberFormat formatter = NumberFormat.getNumberInstance();
    formatter.setMaximumFractionDigits(1);
    for (int i = 0; i < rowHeaders.length; i++) {
        int rowCount = 0;
        Header header = rowHeaders[i];
        Header[] children = header.getChildren();
        boolean hasChildren = false;
        if (children != null) {
            hasChildren = true;
            tableRow++;
            rowCount = children.length;
        } else {
            int headerType = header.getHeaderType();
            if (headerType == Header.HEADERTYPE_ROW_LABEL || headerType == Header.HEADERTYPE_ROW_SPACER) {
                rowCount = 0;
                tableRow++;
            } else {
                rowCount = 1;
            }
        }
        for (int j = 0; j < rowCount; j++) {
            if (hasChildren) {
                Header child = children[j];
                int headerType = child.getHeaderType();
                if (headerType == Header.HEADERTYPE_ROW_LABEL || headerType == Header.HEADERTYPE_ROW_SPACER) {
                    tableRow++;
                    continue;
                }
            }
            for (int cellColumn = 0; cellColumn < this._reportModel.getColumnSize(); cellColumn++) {
                Cell cell = this._reportModel.getCell(cellRow, cellColumn);
                int align = Element.ALIGN_RIGHT;
                Font font = this._normalFont;
                String s = null;

                switch (cell.getCellType()) {
                case Cell.CELLTYPE_PERCENT:
                    s = formatter.format(cell.getFloatValue());
                    break;
                case Cell.CELLTYPE_ROW_HEADER:
                    s = cell.getStringValue();
                    if (s.equals("&nbsp;")) {
                        s = " ";
                    }
                    font = this._boldFont;
                    align = Element.ALIGN_LEFT;
                    break;
                case Cell.CELLTYPE_SUM:
                    s = formatNumber(cell.getValue());
                    font = this._boldFont;
                    break;
                case Cell.CELLTYPE_TOTAL:
                    s = formatNumber(cell.getValue());
                    font = this._boldFont;
                    break;
                default:
                    s = formatNumber(cell.getValue());
                    break;
                }
                int tableColumn = cellColumn + 1;
                com.lowagie.text.Cell pdfCell = new com.lowagie.text.Cell(new Phrase(s, font));
                pdfCell.setHorizontalAlignment(align);
                pdfCell.setNoWrap(true);
                pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(pdfCell, new Point(tableRow, tableColumn));
                setColSize(s, tableColumn, false);
            }
            cellRow++;
            tableRow++;
        }
    }
    this._reportModel.close();
}

From source file:tk.diginspect.main.SoOFSignatories.java

public void createPDF() {
    doc = new Document(PageSize.A4);
    try {/*from   w  w  w .  j av  a 2  s. c  o m*/
        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/RFO";
        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        String strFinalname, strFilename2, strFilenames;
        String filename = sp.getString("EstablishmentName", null);
        String strfilename = filename.replaceAll("\\W+", "-");
        String inspector = sp.getString("FDRO1", null);
        String inspby = inspector.replaceAll("\\W+", "-");
        File file = new File(dir, strfilename + "-" + strFile + "-" + inspby + ".pdf");

        strFilename2 = strfilename + "-" + strFile + "-" + inspby;
        strFilenames = strFilename2 + ".pdf";
        strFinalname = path + "/" + strFilenames;
        savePreferences("fileName", strFinalname);

        FileOutputStream fOut = new FileOutputStream(file);
        PdfWriter.getInstance(doc, fOut);
        doc.open();

        FDALetterhead();

        // General Info Table
        float[] table1columnWidths = { 1f, 1f, 1f, 1f };
        PdfPTable table1 = new PdfPTable(table1columnWidths);
        table1.setWidthPercentage(110f);
        table1.setSpacingAfter(20f);
        insertCell(table1, "INSPECTION REPORT", Element.ALIGN_CENTER, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "Name of Establishment", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("EstablishmentName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Plant/Office Address", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PlantOfficeAddress", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Warehouse Address", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("WarehouseAddress", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Owner", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Owner", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Telephone Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("TelNumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Fax No", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("FaxNumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Classification", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);

        String Classification = sp.getString("MainClass", null) + ", " + sp.getString("SecClass", null) + ", "
                + sp.getString("ThirdClass", null) + ", " + sp.getString("FourthClass", "");

        insertCell(table1, Classification, Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Product/s:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Products", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Manner of Notification", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Notification", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Purpose of Inspection", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Inspection", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Registered Pharmacist / Authorized Representative / Person", Element.ALIGN_LEFT, 4,
                "#8EBAFF", 1, 0);
        insertCell(table1, "Name", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PharmacistName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Reg. No. (PRC-ID)", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcID", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Date Issued", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcDateIssued", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Validity", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcValidity", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Position", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PharmacistPosition", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Person/s Interviewed", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("InterviewedName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Position", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("InterviewedPosition", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "License to Operate", Element.ALIGN_LEFT, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTONumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Renewal", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTORenewalDate", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Validity", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTOValidity", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Payment of Appropriate Fee", Element.ALIGN_LEFT, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "OR Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("ORNum", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Amount", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, "Php " + sp.getString("ORAmount", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Date of Payment", Element.ALIGN_LEFT, 0, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("ORDate", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "RSN", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 1);
        insertCell(table1, sp.getString("RSN", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 1);
        doc.add(table1);

        footer();

        // 2nd Page
        doc.newPage();
        FDALetterhead();

        PdfPTable table2 = new PdfPTable(1);
        table2.setWidthPercentage(110f);
        table2.setSpacingAfter(20f);
        insertCell(table2, "Observation Findings:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell1(table2, sp.getString("ObservationFindings", ""), 1, 1, 600f);
        doc.add(table2);
        footer();

        // 3rd Page
        doc.newPage();
        FDALetterhead();

        PdfPTable table3 = new PdfPTable(1);
        table3.setWidthPercentage(110f);
        table3.setSpacingAfter(20f);

        insertCell(table3, "Directives:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 1);

        nested(table3, 0.1f, 2f, R.string.directives1, sp.getBoolean("Directives1", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives2, sp.getBoolean("Directives2", false), Element.ALIGN_LEFT);
        nested(table3, 0.2f, 2f, R.string.directives3, sp.getBoolean("Directives3", false),
                Element.ALIGN_RIGHT);
        nested(table3, 0.2f, 2f, R.string.directives4, sp.getBoolean("Directives4", false),
                Element.ALIGN_RIGHT);
        nested(table3, 0.1f, 2f, R.string.directives5, sp.getBoolean("Directives5", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives6, sp.getBoolean("Directives6", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives7, sp.getBoolean("Directives7", false), Element.ALIGN_LEFT);

        String Directives8 = getResources().getString(R.string.directives8);
        PdfPCell cellDirectives8 = new PdfPCell(new Paragraph(Font.TIMES_ROMAN, Directives8));
        cellDirectives8.setPaddingLeft(50);
        cellDirectives8.setPaddingTop(5);
        cellDirectives8.setPaddingBottom(5);
        cellDirectives8.setPaddingRight(5);
        cellDirectives8.setBorderWidthTop(0);
        cellDirectives8.setBorderWidthBottom(0);
        table3.addCell(cellDirectives8);

        String Directives = sp.getString("Directives8", null);
        boolean Directives9 = false, Directives10 = false;
        if (Directives.equals(R.string.directives9)) {
            Directives9 = true;
            Directives10 = false;
        } else if (Directives.equals(R.string.directives10)) {
            Directives9 = false;
            Directives10 = true;
        } else {
            Directives9 = false;
            Directives10 = false;
        }

        nested(table3, 0.3f, 2f, R.string.directives9, Directives9, Element.ALIGN_RIGHT);
        nested(table3, 0.3f, 2f, R.string.directives10, Directives10, Element.ALIGN_RIGHT);

        insertCell(table3, "Inspected By:", Element.ALIGN_CENTER, 1, "#8EBAFF", 1, 0);

        PdfPTable signature1 = new PdfPTable(2);

        sig(signature1, "FDRO1");
        sig(signature1, "FDRO2");

        insertCell(signature1, sp.getString("FDRO1", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, sp.getString("FDRO2", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, "Food-Drug Regulation Officer", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Food-Drug Regulation Officer", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Date: " + dateStarted, Element.ALIGN_LEFT, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Time: " + timeS, Element.ALIGN_LEFT, 1, "#FFFFFF", 1, 0);

        sig(signature1, "EstRep1");
        sig(signature1, "EstRep2");
        insertCell(signature1, sp.getString("EstRep1", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, sp.getString("EstRep2", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, "Establishments Representative", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);
        insertCell(signature1, "Establishments Representative", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);

        PdfPCell nesthousing1 = new PdfPCell(signature1);
        table3.addCell(nesthousing1);

        doc.add(table3);
        footer();

        // 4th Page
        doc.newPage();
        FDALetterhead();
        PdfPTable table4 = new PdfPTable(1);
        table4.setWidthPercentage(110f);
        table4.setSpacingAfter(20f);

        insertCell(table4, "(FDA USE ONLY)", Element.ALIGN_CENTER, 1, "#8EBAFF", 1, 1);
        insertCell(table4, "Compliance Made by the Company", Element.ALIGN_LEFT, 1, "#FFFFFF", 0, 0);
        nested(table4, 0.1f, 2f, R.string.CAPA, false, Element.ALIGN_LEFT);
        nested(table4, 0.2f, 2f, R.string.Accepted, false, Element.ALIGN_RIGHT);
        nested(table4, 0.2f, 2f, R.string.NotAccepted, false, Element.ALIGN_RIGHT);
        insertCell(table4, "Recommendation (to Licensing) :", Element.ALIGN_LEFT, 1, "#FFFFFF", 0, 0);
        insertCell1(table4, "", 0, 0, 100f);

        PdfPTable signature2 = new PdfPTable(2);

        insertCell1(signature2, "", 0, 0, 50f);
        insertCell1(signature2, "", 0, 0, 50f);

        insertCell(signature2, "Print Name & Signature of FDRO/s", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature2, "Date", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);

        insertCell(signature2, "Reviewed by:", Element.ALIGN_LEFT, 2, "#8EBAFF", 1, 1);

        insertCell1(signature2, "", 0, 0, 50f);
        insertCell1(signature2, "", 0, 0, 50f);

        insertCell(signature2, "Print Name & Signature of Team Leader/Supervisor", Element.ALIGN_CENTER, 1,
                "#FFFFFF", 1, 1);
        insertCell(signature2, "Date", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);

        PdfPCell nesthousing2 = new PdfPCell(signature2);
        table4.addCell(nesthousing2);

        doc.add(table4);
        footer();

    } catch (DocumentException de) {
        Log.e("PDFCreator", "DocumentException:" + de);
    } catch (FileNotFoundException e) {
        Log.e("PDFCreator", "ioException:" + e);
    } finally {
        doc.close();
    }
}