Example usage for com.itextpdf.text.pdf PdfPTable setTotalWidth

List of usage examples for com.itextpdf.text.pdf PdfPTable setTotalWidth

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable setTotalWidth.

Prototype

public void setTotalWidth(final float columnWidth[]) throws DocumentException 

Source Link

Document

Sets the full width of the table from the absolute column width.

Usage

From source file:net.digitstar.vanadio.AbstractReportPdf.java

License:Apache License

protected PdfPTable createHeader(Document document, int page, int pageTotal, ReportOptions reportOptions) {
    PdfPTable header = new PdfPTable(3);
    header.setTotalWidth(document.right() - document.left());
    PdfPCell def = header.getDefaultCell();
    String left = "";
    String center = "";
    String right = "";

    if (reportOptions.isShowPageNumberIfOnePage()
            || (!reportOptions.isShowPageNumberIfOnePage() && pageTotal > 1)) {
        right = reportOptions.isShowPageTotal() ? Labels.PAGE_TOTAL.getLabelFormatted(page, pageTotal)
                : Labels.PAGE.getLabelFormatted(page);
    }//from w w w .j a v a2 s .c  o  m

    def.setFixedHeight(computeHeight(FontType.HEADERFOOTER.getFont()));

    def.setBorder(CellStyle.Border.NONE.getValue());
    if (reportOptions.isUseHrRuler())
        def.setBorder(CellStyle.Border.BOTTOM.getValue());

    def.setHorizontalAlignment(CellStyle.Align.LEFT.getValue());
    header.addCell(new Phrase(left, FontType.HEADERFOOTER.getFont()));
    def.setHorizontalAlignment(CellStyle.Align.CENTER.getValue());
    header.addCell(new Phrase(center, FontType.HEADERFOOTER.getFont()));
    def.setHorizontalAlignment(CellStyle.Align.RIGHT.getValue());
    header.addCell(new Phrase(right, FontType.HEADERFOOTER.getFont()));
    return header;
}

From source file:net.digitstar.vanadio.AbstractReportPdf.java

License:Apache License

protected PdfPTable createFooter(Document document, int page, int pageTotal, ReportOptions reportOptions) {
    PdfPTable footer = new PdfPTable(3);
    footer.setTotalWidth(document.right() - document.left());
    PdfPCell def = footer.getDefaultCell();
    String left = "";
    String center = "";
    String right = "";

    def.setFixedHeight(computeHeight(FontType.HEADERFOOTER.getFont()));
    def.setBorder(CellStyle.Border.NONE.getValue());
    if (reportOptions.isUseHrRuler())
        def.setBorder(CellStyle.Border.TOP.getValue());

    if (reportOptions.isShowPrintDate())
        right = Labels.PRINTED.getLabelFormatted(getDateTimeFormat().format(new Date()));

    def.setHorizontalAlignment(CellStyle.Align.LEFT.getValue());
    footer.addCell(new Phrase(left, FontType.HEADERFOOTER.getFont()));
    def.setHorizontalAlignment(CellStyle.Align.CENTER.getValue());
    footer.addCell(new Phrase(center, FontType.HEADERFOOTER.getFont()));
    def.setHorizontalAlignment(CellStyle.Align.RIGHT.getValue());
    footer.addCell(new Phrase(right, FontType.HEADERFOOTER.getFont()));
    return footer;
}

From source file:net.pflaeging.PortableSigner.PDFSigner.java

License:Open Source License

/** Creates a new instance of DoSignPDF */
public void doSignPDF(String pdfInputFileName, String pdfOutputFileName, String pkcs12FileName, String password,
        Boolean signText, String signLanguage, String sigLogo, Boolean finalize, String sigComment,
        String signReason, String signLocation, Boolean noExtraPage, float verticalPos, float leftMargin,
        float rightMargin, Boolean signLastPage, byte[] ownerPassword) throws PDFSignerException {
    try {/*from w w  w . j a  v  a2 s . c om*/
        //System.out.println("-> DoSignPDF <-");
        //System.out.println("Eingabedatei: " + pdfInputFileName);
        //System.out.println("Ausgabedatei: " + pdfOutputFileName);
        //System.out.println("Signaturdatei: " + pkcs12FileName);
        //System.out.println("Signaturblock?: " + signText);
        //System.out.println("Sprache der Blocks: " + signLanguage);
        //System.out.println("Signaturlogo: " + sigLogo);
        System.err.println("Position V:" + verticalPos + " L:" + leftMargin + " R:" + rightMargin);
        Rectangle signatureBlock;

        java.security.Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 2);

        pkcs12 = new GetPKCS12(pkcs12FileName, password);

        PdfReader reader = null;
        try {
            //                System.out.println("Password:" + ownerPassword.toString());
            if (ownerPassword == null)
                reader = new PdfReader(pdfInputFileName);
            else
                reader = new PdfReader(pdfInputFileName, ownerPassword);
        } catch (IOException e) {

            /* MODIFY BY: Denis Torresan
             Main.setResult(
                java.util.ResourceBundle.getBundle(
                "net/pflaeging/PortableSigner/i18n").getString(
                "CouldNotBeOpened"),
                true,
                e.getLocalizedMessage());
             */

            throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n")
                    .getString("CouldNotBeOpened"), true, e.getLocalizedMessage());
        }
        FileOutputStream fout = null;
        try {
            fout = new FileOutputStream(pdfOutputFileName);
        } catch (FileNotFoundException e) {

            /* MODIFY BY: Denis Torresan
             Main.setResult(
                java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("CouldNotBeWritten"),
                true,
                e.getLocalizedMessage());
             */

            throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n")
                    .getString("CouldNotBeWritten"), true, e.getLocalizedMessage());

        }
        PdfStamper stp = null;
        try {
            Date datum = new Date(System.currentTimeMillis());

            int pages = reader.getNumberOfPages();

            Rectangle size = reader.getPageSize(pages);
            stp = PdfStamper.createSignature(reader, fout, '\0', null, true);
            HashMap<String, String> pdfInfo = reader.getInfo();
            // thanks to Markus Feisst
            String pdfInfoProducer = "";

            if (pdfInfo.get("Producer") != null) {
                pdfInfoProducer = pdfInfo.get("Producer").toString();
                pdfInfoProducer = pdfInfoProducer + " (signed with PortableSigner " + Version.release + ")";
            } else {
                pdfInfoProducer = "Unknown Producer (signed with PortableSigner " + Version.release + ")";
            }
            pdfInfo.put("Producer", pdfInfoProducer);
            //System.err.print("++ Producer:" + pdfInfo.get("Producer").toString());
            stp.setMoreInfo(pdfInfo);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XmpWriter xmp = new XmpWriter(baos, pdfInfo);
            xmp.close();
            stp.setXmpMetadata(baos.toByteArray());
            if (signText) {
                String greet, signator, datestr, ca, serial, special, note, urn, urnvalue;
                int specialcount = 0;
                int sigpage;
                int rightMarginPT, leftMarginPT;
                float verticalPositionPT;
                ResourceBundle block = ResourceBundle
                        .getBundle("net/pflaeging/PortableSigner/Signatureblock_" + signLanguage);
                greet = block.getString("greeting");
                signator = block.getString("signator");
                datestr = block.getString("date");
                ca = block.getString("issuer");
                serial = block.getString("serial");
                special = block.getString("special");
                note = block.getString("note");
                urn = block.getString("urn");
                urnvalue = block.getString("urnvalue");

                //sigcomment = block.getString(signLanguage + "-comment");
                // upper y
                float topy = size.getTop();
                System.err.println("Top: " + topy * ptToCm);
                // right x
                float rightx = size.getRight();
                System.err.println("Right: " + rightx * ptToCm);
                if (!noExtraPage) {
                    sigpage = pages + 1;
                    stp.insertPage(sigpage, size);
                    // 30pt left, 30pt right, 20pt from top
                    rightMarginPT = 30;
                    leftMarginPT = 30;
                    verticalPositionPT = topy - 20;
                } else {
                    if (signLastPage) {
                        sigpage = pages;
                    } else {
                        sigpage = 1;
                    }
                    System.err.println("Page: " + sigpage);
                    rightMarginPT = Math.round(rightMargin / ptToCm);
                    leftMarginPT = Math.round(leftMargin / ptToCm);
                    verticalPositionPT = topy - Math.round(verticalPos / ptToCm);
                }
                if (!GetPKCS12.atEgovOID.equals("")) {
                    specialcount = 1;
                }
                PdfContentByte content = stp.getOverContent(sigpage);

                float[] cellsize = new float[2];
                cellsize[0] = 100f;
                // rightx = width of page
                // 60 = 2x30 margins
                // cellsize[0] = description row
                // cellsize[1] = 0
                // 70 = logo width
                cellsize[1] = rightx - rightMarginPT - leftMarginPT - cellsize[0] - cellsize[1] - 70;

                // Pagetable = Greeting, signatureblock, comment
                // sigpagetable = outer table
                //      consist: greetingcell, signatureblock , commentcell
                PdfPTable signatureBlockCompleteTable = new PdfPTable(2);
                PdfPTable signatureTextTable = new PdfPTable(2);
                PdfPCell signatureBlockHeadingCell = new PdfPCell(
                        new Paragraph(new Chunk(greet, new Font(Font.FontFamily.HELVETICA, 12))));
                signatureBlockHeadingCell.setPaddingBottom(5);
                signatureBlockHeadingCell.setColspan(2);
                signatureBlockHeadingCell.setBorderWidth(0f);
                signatureBlockCompleteTable.addCell(signatureBlockHeadingCell);

                // inner table start
                // Line 1
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(signator, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(GetPKCS12.subject, new Font(Font.FontFamily.COURIER, 10))));
                // Line 2
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(datestr, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(datum.toString(), new Font(Font.FontFamily.COURIER, 10))));
                // Line 3
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(ca, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(GetPKCS12.issuer, new Font(Font.FontFamily.COURIER, 10))));
                // Line 4
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(serial, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable.addCell(new Paragraph(
                        new Chunk(GetPKCS12.serial.toString(), new Font(Font.FontFamily.COURIER, 10))));
                // Line 5
                if (specialcount == 1) {
                    signatureTextTable.addCell(new Paragraph(
                            new Chunk(special, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                    signatureTextTable.addCell(new Paragraph(
                            new Chunk(GetPKCS12.atEgovOID, new Font(Font.FontFamily.COURIER, 10))));
                }
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(urn, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable
                        .addCell(new Paragraph(new Chunk(urnvalue, new Font(Font.FontFamily.COURIER, 10))));
                signatureTextTable.setTotalWidth(cellsize);
                System.err.println(
                        "signatureTextTable Width: " + cellsize[0] * ptToCm + " " + cellsize[1] * ptToCm);
                // inner table end

                signatureBlockCompleteTable.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                Image logo;
                //                     System.out.println("Logo:" + sigLogo + ":");
                if (sigLogo == null || "".equals(sigLogo)) {
                    logo = Image.getInstance(
                            getClass().getResource("/net/pflaeging/PortableSigner/SignatureLogo.png"));
                } else {
                    logo = Image.getInstance(sigLogo);
                }

                PdfPCell logocell = new PdfPCell();
                logocell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                logocell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                logocell.setImage(logo);
                signatureBlockCompleteTable.addCell(logocell);
                PdfPCell incell = new PdfPCell(signatureTextTable);
                incell.setBorderWidth(0f);
                signatureBlockCompleteTable.addCell(incell);
                PdfPCell commentcell = new PdfPCell(
                        new Paragraph(new Chunk(sigComment, new Font(Font.FontFamily.HELVETICA, 10))));
                PdfPCell notecell = new PdfPCell(
                        new Paragraph(new Chunk(note, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                //commentcell.setPaddingTop(10);
                //commentcell.setColspan(2);
                // commentcell.setBorderWidth(0f);
                if (!sigComment.equals("")) {
                    signatureBlockCompleteTable.addCell(notecell);
                    signatureBlockCompleteTable.addCell(commentcell);
                }
                float[] cells = { 70, cellsize[0] + cellsize[1] };
                signatureBlockCompleteTable.setTotalWidth(cells);
                System.err.println(
                        "signatureBlockCompleteTable Width: " + cells[0] * ptToCm + " " + cells[1] * ptToCm);
                signatureBlockCompleteTable.writeSelectedRows(0, 4 + specialcount, leftMarginPT,
                        verticalPositionPT, content);
                System.err.println(
                        "signatureBlockCompleteTable Position " + 30 * ptToCm + " " + (topy - 20) * ptToCm);
                signatureBlock = new Rectangle(30 + signatureBlockCompleteTable.getTotalWidth() - 20,
                        topy - 20 - 20, 30 + signatureBlockCompleteTable.getTotalWidth(), topy - 20);
                //                    //////
                //                    AcroFields af = reader.getAcroFields();
                //                    ArrayList names = af.getSignatureNames();
                //                    for (int k = 0; k < names.size(); ++k) {
                //                        String name = (String) names.get(k);
                //                        System.out.println("Signature name: " + name);
                //                        System.out.println("\tSignature covers whole document: " + af.signatureCoversWholeDocument(name));
                //                        System.out.println("\tDocument revision: " + af.getRevision(name) + " of " + af.getTotalRevisions());
                //                        PdfPKCS7 pk = af.verifySignature(name);
                //                        X509Certificate tempsigner = pk.getSigningCertificate();
                //                        Calendar cal = pk.getSignDate();
                //                        Certificate pkc[] = pk.getCertificates();
                //                        java.util.ResourceBundle tempoid =
                //                                java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/SpecialOID");
                //                        String tmpEgovOID = "";
                //
                //                        for (Enumeration<String> o = tempoid.getKeys(); o.hasMoreElements();) {
                //                            String element = o.nextElement();
                //                            // System.out.println(element + ":" + oid.getString(element));
                //                            if (tempsigner.getNonCriticalExtensionOIDs().contains(element)) {
                //                                if (!tmpEgovOID.equals("")) {
                //                                    tmpEgovOID += ", ";
                //                                }
                //                                tmpEgovOID += tempoid.getString(element) + " (OID=" + element + ")";
                //                            }
                //                        }
                //                        //System.out.println("\tSigniert von: " + PdfPKCS7.getSubjectFields(pk.getSigningCertificate()));
                //                        System.out.println("\tSigniert von: " + tempsigner.getSubjectX500Principal().toString());
                //                        System.out.println("\tDatum: " + cal.getTime().toString());
                //                        System.out.println("\tAusgestellt von: " + tempsigner.getIssuerX500Principal().toString());
                //                        System.out.println("\tSeriennummer: " + tempsigner.getSerialNumber());
                //                        if (!tmpEgovOID.equals("")) {
                //                            System.out.println("\tVerwaltungseigenschaft: " + tmpEgovOID);
                //                        }
                //                        System.out.println("\n");
                //                        System.out.println("\tDocument modified: " + !pk.verify());
                ////                Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal);
                ////                if (fails == null) {
                ////                    System.out.println("\tCertificates verified against the KeyStore");
                ////                } else {
                ////                    System.out.println("\tCertificate failed: " + fails[1]);
                ////                }
                //                    }
                //
                //                //////
            } else {
                signatureBlock = new Rectangle(0, 0, 0, 0); // fake definition
            }
            PdfSignatureAppearance sap = stp.getSignatureAppearance();
            //                sap.setCrypto(GetPKCS12.privateKey, GetPKCS12.certificateChain, null,
            //                        PdfSignatureAppearance.WINCER_SIGNED );
            sap.setCrypto(GetPKCS12.privateKey, GetPKCS12.certificateChain, null, null);
            sap.setReason(signReason);
            sap.setLocation(signLocation);
            //                if (signText) {
            //                    sap.setVisibleSignature(signatureBlock,
            //                            pages + 1, "PortableSigner");
            //                }
            if (finalize) {
                sap.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
            } else {
                sap.setCertificationLevel(PdfSignatureAppearance.NOT_CERTIFIED);
            }
            stp.close();

            /* MODIFY BY: Denis Torresan
            Main.setResult(
              java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("IsGeneratedAndSigned"),
              false,
              "");
                */

        } catch (Exception e) {

            /* MODIFY BY: Denis Torresan
             Main.setResult(
                java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("ErrorWhileSigningFile"),
                true,
                e.getLocalizedMessage());
             */

            throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n")
                    .getString("ErrorWhileSigningFile"), true, e.getLocalizedMessage());

        }
    } catch (KeyStoreException kse) {

        /* MODIFY BY: Denis Torresan
         Main.setResult(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("ErrorCreatingKeystore"),
            true, kse.getLocalizedMessage());
         */

        throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n")
                .getString("ErrorCreatingKeystore"), true, kse.getLocalizedMessage());

    }
}

From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java

License:Apache License

/**
 * Create the metrics values table for given report unit. This table will be added to the PDF document.
 *
 * @param allMetricsMap map of all QC metrics - keys and description.
 * @param reportUnit    Report unit for which to create the metrics values table.
 * @return PDF table containing metrics values of the report unit.
 *///from   w  w w. j  a v  a  2  s .co  m
private static PdfPTable createMetricsValuesTable(final Map<String, String> allMetricsMap,
        final ReportUnit reportUnit) {
    /*
     * TODO: Column size, font size and spacing of the metrics value table. 
     */
    // Create columns names.
    final String columnNames[] = { Constants.METRICS_ID_COLUMN_NAME, Constants.DESCRIPTION_COLUMN_NAME,
            Constants.VALUE_COLUMN_NAME, Constants.METRICS_ID_COLUMN_NAME, Constants.DESCRIPTION_COLUMN_NAME,
            Constants.VALUE_COLUMN_NAME, };
    //Creation of table object.
    final PdfPTable table = new PdfPTable(columnNames.length);
    try {
        table.setSpacingBefore(TABLE_SPACING);
        //Set the table width. 
        table.setTotalWidth(COLUMN_WIDTHS);
        table.setLockedWidth(true);
        //Add table header. 
        for (int i = 0; i < TOTAL_COLUMNS; ++i) {
            final PdfPCell headerCell = new PdfPCell(new Phrase(columnNames[i], Constants.TABLE_HEADER_FONT));
            headerCell.setBackgroundColor(BaseColor.RED);
            headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(headerCell);
        }
        //Read metricsValues corresponding to reportUnit.
        final Map<String, String> metricsValues = reportUnit.getMetricsValues();
        //TODO: Split allMetricsMap in two parts such that sorted rows are properly added in the table.
        //Get all keys  
        final Object[] keyArray = allMetricsMap.keySet().toArray();
        //get all values
        final Object[] valueArray = allMetricsMap.values().toArray();
        //Calculate halfSize
        final int halfSize = keyArray.length / 2;
        for (int i = 0; i < halfSize; ++i) {
            addMetric(keyArray[i].toString(), valueArray[i].toString(), metricsValues, table);
            addMetric(keyArray[i + halfSize].toString(), valueArray[i + halfSize].toString(), metricsValues,
                    table);
        }
    } catch (final DocumentException e) {
        //DocumentException signals that an error has occurred in a Document.
        logger.log(Level.SEVERE, String.format(PDF_TABLE_EXCEPTION_MESSAGE, reportUnit.getMsrunName()), e);
    }
    return table;
}

From source file:om.edu.squ.squportal.portlet.tsurvey.dao.pdf.TeachingSurveyPdfImpl.java

License:Open Source License

/**
 * //  w  ww.  jav a2 s . co  m
 * method name  : getPdfSurveyAnalysis
 * @param object
 * @param semesterYear
 * @param questionByYear
 * @param questionSetNo
 * @param byos
 * @param inputStream
 * @param res
 * @return
 * @throws DocumentException
 * @throws IOException
 * TeachingSurveyPdfImpl
 * return type  : OutputStream
 * 
 * purpose      : Generate PDF content
 *
 * Date          :   Mar 28, 2016 7:21:04 PM
 */
public OutputStream getPdfSurveyAnalysis(Object object, String semesterYear, String questionByYear,
        int questionSetNo, ByteArrayOutputStream byos, InputStream inputStream, ResourceResponse res)
        throws DocumentException, IOException {

    Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, BaseColor.BLACK);

    PdfReader pdfTemplate = new PdfReader(inputStream);
    PdfStamper pdfStamper = new PdfStamper(pdfTemplate, byos);
    Survey survey = (Survey) object;
    String sectionNos = "";
    String seatsTaken = "";
    DecimalFormat formatter = new DecimalFormat("###.##");

    String RIGHT = Constants.RIGHT;
    String CENTER = Constants.CENTER;
    String LEFT = Constants.LEFT;

    pdfStamper.getAcroFields().setField("txtCourse", survey.getCourseCode() + " / " + survey.getCourseName());
    pdfStamper.getAcroFields().setField("txtCollegeName", survey.getCollegeName());

    for (SurveyResponse resp : survey.getSurveyResponses()) {
        sectionNos = sectionNos + resp.getSectionNo() + " ";
        seatsTaken = String.valueOf(resp.getSeatsTaken());
    }

    pdfStamper.getAcroFields().setField("txtSectionNo", sectionNos);
    pdfStamper.getAcroFields().setField("txtDepartmentName", survey.getDepartmentName());
    pdfStamper.getAcroFields().setField("txtEmpName", survey.getEmpName());
    pdfStamper.getAcroFields().setField("txtStudentRegistered", seatsTaken);

    pdfStamper.getAcroFields().setField("txtSemesterYear", semesterYear);

    pdfStamper.getAcroFields().setGenerateAppearances(true);

    /* ****************** */

    PdfPTable table = new PdfPTable(13);

    table.addCell(getPdfCell("", 2, 0, font, LEFT));
    table.addCell(getPdfCell(
            UtilProperty.getMessage("prop.course.teaching.survey.analysis.course.teaching.items", null), 2, 0,
            font, CENTER));
    table.addCell(
            getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.response.number", null), 0,
                    6, font, CENTER));
    table.addCell(getPdfCell(
            UtilProperty.getMessage("prop.course.teaching.survey.analysis.response.percentage", null), 2, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.mean", null), 0, 4,
            font, CENTER));

    table.addCell(
            getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.disagree.strong", null), 0,
                    0, font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.disagree", null), 0,
            0, font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.agree", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.agree.strong", null),
            0, 0, font, CENTER));
    table.addCell(
            getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.applicable.not", null), 0,
                    0, font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.total", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.sect", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.crs", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.dept", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.col", null), 0, 0,
            font, CENTER));

    /* ---------------------------------------------------------------------------- */
    table.addCell(getPdfCell("", 0, 0, font));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.course.items", null),
            0, 12, font, CENTER));

    int cTotal = 0;
    float cPctVal = 0f;
    float cSectionMean = 0f;
    float cCourseMean = 0f;
    float cDepart = 0f;
    float cCollege = 0f;
    int rowCount = 0;

    for (SurveyResponse sures : survey.getSurveyResponses()) {
        for (Analysis analysis : sures.getAnalysisList()) {
            if (analysis.getQuestion().equals("Q2") || analysis.getQuestion().equals("Q14")
                    || analysis.getQuestion().equals(questionByYear)) {
                /***  First part    ***/
                table.addCell(getPdfCell(analysis.getQuestion(), 0, 0, font));
                table.addCell(
                        getPdfCell(
                                UtilProperty.getMessage("prop.course.teaching.survey.analysis.set"
                                        + questionSetNo + ".question" + analysis.getQuestionLabel(), null),
                                0, 0, font, LEFT));
                table.addCell(getPdfCell(String.valueOf(analysis.getStrongDisagree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getDisAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getStrongAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getNotApplicable()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getTotal()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getPercentageResponse()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getSectionMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getCourseMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getDepartmentMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getCollegeMean()), 0, 0, font, RIGHT));

                cTotal = cTotal + analysis.getTotal();
                cPctVal = cPctVal + analysis.getPercentageResponse();
                cSectionMean = cSectionMean + analysis.getSectionMean();
                cCourseMean = cCourseMean + analysis.getCollegeMean();
                cDepart = cDepart + analysis.getDepartmentMean();
                cCollege = cCollege + analysis.getCollegeMean();
                rowCount = rowCount + 1;

            }
        }
    }

    /***  First part - Summary   ***/
    table.addCell(getPdfCell(String.valueOf(""), 0, 0, font));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.summary", null), 0,
            0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(""), 0, 5, font));
    table.addCell(getPdfCell(String.valueOf(cTotal), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cPctVal / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cSectionMean / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cCourseMean / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cDepart / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cCollege / rowCount)), 0, 0, font, RIGHT));

    table.addCell(getPdfCell("", 0, 13, font));

    table.addCell(getPdfCell("", 0, 0, font));
    table.addCell(
            getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.teaching.items", null), 0,
                    12, font, LEFT));

    cTotal = 0;
    cPctVal = 0f;
    cSectionMean = 0f;
    cCourseMean = 0f;
    cDepart = 0f;
    cCollege = 0f;
    rowCount = 0;
    for (SurveyResponse sures : survey.getSurveyResponses()) {
        for (Analysis analysis : sures.getAnalysisList()) {
            if (!(analysis.getQuestion().equals("Q2") || analysis.getQuestion().equals("Q14")
                    || analysis.getQuestion().equals(questionByYear))) {

                table.addCell(getPdfCell(analysis.getQuestion(), 0, 0, font));
                table.addCell(
                        getPdfCell(
                                UtilProperty.getMessage("prop.course.teaching.survey.analysis.set"
                                        + questionSetNo + ".question" + analysis.getQuestionLabel(), null),
                                0, 0, font, LEFT));
                table.addCell(getPdfCell(String.valueOf(analysis.getStrongDisagree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getDisAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getStrongAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getNotApplicable()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getTotal()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getPercentageResponse()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getSectionMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getCourseMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getDepartmentMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getCollegeMean()), 0, 0, font, RIGHT));

                cTotal = cTotal + analysis.getTotal();
                cPctVal = cPctVal + analysis.getPercentageResponse();
                cSectionMean = cSectionMean + analysis.getSectionMean();
                cCourseMean = cCourseMean + analysis.getCollegeMean();
                cDepart = cDepart + analysis.getDepartmentMean();
                cCollege = cCollege + analysis.getCollegeMean();
                rowCount = rowCount + 1;

            }

        }

    }

    /***  Second part - Summary   ***/
    table.addCell(getPdfCell(String.valueOf(""), 0, 0, font));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.summary", null), 0,
            0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(""), 0, 5, font));
    table.addCell(getPdfCell(String.valueOf(cTotal), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cPctVal / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cSectionMean / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cCourseMean / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cDepart / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cCollege / rowCount)), 0, 0, font, RIGHT));

    if (!survey.getMessage().equals("")) {
        table.addCell(getPdfCell("", 0, 13, font));
        table.addCell(getPdfCell("", 0, 0, font));
        table.addCell(getPdfCell(survey.getMessage(), 0, 12, font, CENTER));
    }

    table.setTotalWidth(750);
    table.setLockedWidth(true);
    table.setWidths(new float[] { 1, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });

    ColumnText column = new ColumnText(pdfStamper.getOverContent(1));
    Rectangle rectPage1 = new Rectangle(120, 20, 659, 480);

    column.setSimpleColumn(rectPage1);
    column.addElement(table);

    int status = column.go();

    pdfStamper.setFormFlattening(true);

    pdfStamper.close();

    pdfTemplate.close();

    res.setContentType("application/pdf");

    return res.getPortletOutputStream();

}

From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java

private void prepareWeightedAverageTable() throws DocumentException {
    PdfPTable tableWeightedInches = new PdfPTable(14);

    tableWeightedInches.setTotalWidth(new float[] { 190, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 120 });
    designTableTitleCell(tableWeightedInches, "Irrigation Weighted Average (Inches)");
    //bwOutputSummaryFileExcel.insertDataWithStyle("Irrigation Weighted Average (Inches)", 0, true, true);
    createTableHeader(tableWeightedInches);
    summaryTables.add(tableWeightedInches);

    PdfPTable tableWeightedGallon = new PdfPTable(14);
    tableWeightedGallon.setTotalWidth(new float[] { 190, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 120 });
    designTableTitleCell(tableWeightedGallon, "Irrigation Weighted Average (Gallons)");
    //bwOutputSummaryFileExcel.insertDataWithStyle("Irrigation Weighted Average (Gallons)", 0, true, true);
    createTableHeader(tableWeightedGallon);
    summaryTables.add(tableWeightedGallon);
}

From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java

private void generalInformation(SummaryReport summaryReport1, Document bwOutputSummaryFile1)
        throws DocumentException {
    // a table with three columns
    PdfPTable table = new PdfPTable(14);

    table.setTotalWidth(new float[] { 190, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 120 });
    designTableTitleCell(table, "Details in Inches");
    excelSummary.mergeCells();/*ww w  . java2s  . c o m*/
    excelSummary.insertDataWithStyle("Details in Inches", 4, true, true);
    excelSummary.insertEmptyLine(2);
    createTableHeader(table);
    createExcelTableHeader();
    /**
     * *************Mean Rainfall Details*****************
     */

    designRowTitleCell(table, "Mean Rainfall");

    excelSummary.insertDataWithStyle("Mean Rainfall", 0, false, true);

    double totalVal = 0.0;
    String str = "";
    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getTotalRainFallByMonth(i);

        if (val >= 0) {
            totalVal += val;
            str = String.format("%6.2f", val);
        } else {
            str = "NA";
        }

        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);

    }
    str = String.format("%6.2f", totalVal);
    designDataCell(table, str);
    excelSummary.insertDataWithStyle(str, 0, true, true);
    excelSummary.setColNum(1);
    /**
     * *************Mean Evaporation*****************
     */
    designRowTitleCell(table, "Mean ET");
    excelSummary.insertDataWithStyle("Mean ET", 0, false, true);
    totalVal = 0.0;
    str = "";
    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getTotalEvaporationByMonth(i);
        if (val >= 0) {
            totalVal += val;
            str = String.format("%6.2f", val);
        } else {
            str = "NA";
        }

        str = String.format("%6.2f", val);
        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);
    }
    str = String.format("%6.2f", totalVal);
    designDataCell(table, str);
    excelSummary.insertDataWithStyle(str, 0, true, true);
    excelSummary.setColNum(1);
    /**
     * *********Peak Evaporation Details************
     */
    designRowTitleCell(table, "Peak ET");
    excelSummary.insertDataWithStyle("Peak ET", 0, false, true);
    totalVal = 0.0;
    str = "";

    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getPeakEvaporationByMonth(i);
        if (val >= 0) {
            totalVal += val;
            str = String.format("%6.2f", val);
        } else {
            str = "NA";
        }

        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);
    }
    str = String.format("%6.2f", totalVal);
    designDataCell(table, str);
    excelSummary.insertDataWithStyle(str, 0, false, true);
    excelSummary.insertEmptyLine(2);
    summaryTables.add(table);

}

From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java

private void infoInInches(Document bwOutputSummaryFile1, SummaryReport summaryReport1)
        throws DocumentException {
    PdfPTable table;
    PdfPCell cell;//from  ww  w .  j  a va2 s. c  o m
    double totalVal;
    String str;
    //bwOutputSummaryFile1.add(new Paragraph("\r\n"));
    table = new PdfPTable(14);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    table.setTotalWidth(new float[] { 190, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 120 });

    designTableTitleCell(table, "Details in Inches");
    excelSummary.insertEmptyLine(1);
    excelSummary.mergeCells();
    excelSummary.insertDataWithStyle("Details in Inches", 4, false, true);
    excelSummary.insertEmptyLine(1);
    createTableHeader(table);
    createExcelTableHeader();

    double[] soilArea = getSoilArea();
    double areaSum = 0.0;

    for (double a : soilArea) {
        areaSum += a;
    }

    /**
     * *********Peak Evaporation Details************
     */
    designRowTitleCell(table, "Avg Irr Req");
    excelSummary.insertDataWithStyle("Avg Irr Req", 0, false, true);

    totalVal = 0.0;
    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getAverageIrrigationRequired(i);
        if (val >= 0) {
            double wIrr = (val * this.soil.getSoilTypeArea()) / areaSum;
            summaryReport.setWeightedAvgIrrRequired(i, wIrr);
            totalVal += val;
            str = String.format("%6.2f", val);
        } else {
            str = "NA";
        }

        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);
    }
    str = String.format("%6.2f", totalVal);
    designDataCell(table, str);
    excelSummary.insertDataWithStyle(str, 0, false, true);
    excelSummary.insertEmptyLine(1);
    /**
     * *********2-in-10 Irrigation Required************
     */
    designRowTitleCell(table, "2-in-10 Irr Req");
    excelSummary.insertDataWithStyle("2-in-10 Irr Req", 0, false, true);
    totalVal = 0.0;
    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getTwoin10IrrigationRequired(i);
        if (val >= 0) {
            double wIrr = (val * this.soil.getSoilTypeArea()) / areaSum;
            summaryReport.setWeighted2In10IrrRequired(i, wIrr);
            totalVal += val;
            str = String.format("%6.2f", val);
        } else {
            str = "NA";
        }

        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);
    }
    str = String.format("%6.2f", totalVal);
    designDataCell(table, str);
    excelSummary.insertDataWithStyle(str, 0, false, true);
    excelSummary.insertEmptyLine(1);
    /**
     * *********1-in-10 Irrigation Required************
     */
    designRowTitleCell(table, "1-in-10 Irr Req");
    excelSummary.insertDataWithStyle("1-in-10 Irr Req", 0, false, true);
    totalVal = 0.0;
    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getOnein10IrrigationRequired(i);
        if (val >= 0) {
            double wIrr = (val * this.soil.getSoilTypeArea()) / areaSum;
            summaryReport.setWeighted1In10IrrRequired(i, wIrr);
            totalVal += val;
            str = String.format("%6.2f", val);
        } else {
            str = "NA";
        }

        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);
    }
    str = String.format("%6.2f", totalVal);
    designDataCell(table, str);
    excelSummary.insertDataWithStyle(str, 0, false, true);
    excelSummary.insertEmptyLine(1);
    summaryTables.add(table);
}

From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java

private PdfPTable probablityInfoInGallons(Document bwOutputSummaryFile1, SummaryReport summaryReport1,
        double area) throws DocumentException {
    PdfPTable table;
    PdfPCell cell;/*from   www  .  j  a  va 2s .  co  m*/
    double totalVal;
    String str;
    //bwOutputSummaryFile1.add(new Paragraph("\r\n"));
    table = new PdfPTable(14);

    table.setTotalWidth(new float[] { 190, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 120 });
    designTableTitleCell(table, "Details in Million Gallons");
    createTableHeader(table);

    excelSummary.insertEmptyLine(1);
    excelSummary.mergeCells();
    excelSummary.insertDataWithStyle("Details in Million Gallons", 4, false, true);
    excelSummary.insertEmptyLine(1);
    createExcelTableHeader();

    /**
     * *********Peak Evaporation Details************
     */
    designRowTitleCell(table, "Avg Irr Req");
    excelSummary.insertDataWithStyle("Avg Irr Req", 0, false, true);
    totalVal = 0.0;
    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getAverageIrrigationRequired(i);
        str = "";
        if (val >= 0) {
            val = (val * area * 27154);
            val = (val / 1000000);
            str = String.format("%6.2f", val);
            totalVal += val;
        } else {
            str = "NA";
        }

        //str = String.format("%6.2f", val);
        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);

    }
    str = String.format("%6.2f", totalVal);
    //str = "-";
    designDataCell(table, str);
    excelSummary.insertDataWithStyle(str, 0, false, true);
    excelSummary.insertEmptyLine(1);

    /**
     * *********2-in-10 Irrigation Required************
     */
    designRowTitleCell(table, "2-in-10 Irr Req");
    excelSummary.insertDataWithStyle("2-in-10 Irr Req", 0, false, true);
    totalVal = 0.0;
    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getTwoin10IrrigationRequired(i);
        str = "";
        if (val >= 0) {
            val = (val * area * 27154);
            val = (val / 1000000);
            str = String.format("%6.2f", val);
            totalVal += val;
        } else {
            str = "NA";
        }

        //str = String.format("%6.2f", val);
        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);
    }
    str = String.format("%6.2f", totalVal);
    //str = "-";
    designDataCell(table, str);
    excelSummary.insertDataWithStyle(str, 0, false, true);
    excelSummary.insertEmptyLine(1);
    /**
     * *********1-in-10 Irrigation Required************
     */
    designRowTitleCell(table, "1-in-10 Irr Req");
    excelSummary.insertDataWithStyle("1-in-10 Irr Req", 0, false, true);
    totalVal = 0.0;
    for (int i = 1; i <= 12; i++) {
        double val = summaryReport1.getOnein10IrrigationRequired(i);
        str = "";
        if (val >= 0) {
            val = (val * area * 27154);
            val = (val / 1000000);
            str = String.format("%6.2f", val);
            totalVal += val;
        } else {
            str = "NA";
        }

        //str = String.format("%6.2f", val);
        designDataCell(table, str);
        excelSummary.insertDataWithStyle(str, 0, false, true);
    }
    str = String.format("%6.2f", totalVal);
    //str = "-";
    designDataCell(table, str);
    summaryTables.add(table);
    excelSummary.insertDataWithStyle(str, 0, false, true);
    excelSummary.insertEmptyLine(1);
    //bwOutputSummaryFile1.add(table);
    return table;
}

From source file:org.cejug.yougi.web.report.EventAttendeeReport.java

License:Open Source License

public void printReport(List<Attendee> attendees) throws DocumentException {
    float[] columnSizes = { 20, 220, 220, 60 };
    PdfPTable table = new PdfPTable(columnSizes.length);
    table.setLockedWidth(true);//from   w ww. ja  v a2  s.co  m
    table.setTotalWidth(columnSizes);

    PdfPCell headerCell = new PdfPCell(new Phrase("Yougi"));
    headerCell.setColspan(4);
    headerCell.setBackgroundColor(BaseColor.ORANGE);
    headerCell.setPadding(3);
    table.addCell(headerCell);

    table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);

    PdfPCell checkCell = new PdfPCell(new Phrase(" "));
    checkCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(checkCell);

    PdfPCell productCell = new PdfPCell(new Phrase("Nome"));
    productCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    productCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(productCell);

    PdfPCell currentPurchaseCell = new PdfPCell(new Phrase("Email"));
    currentPurchaseCell.setPadding(3);
    currentPurchaseCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    currentPurchaseCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(currentPurchaseCell);

    PdfPCell previousPurchaseCell = new PdfPCell(new Phrase("Presente"));
    previousPurchaseCell.setPadding(3);
    previousPurchaseCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    previousPurchaseCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(previousPurchaseCell);

    table.getDefaultCell().setBackgroundColor(null);
    table.setHeaderRows(2);

    Font font = new Font(Font.FontFamily.HELVETICA, 9);
    int seq = 1;
    for (Attendee attendee : attendees) {
        table.addCell(new Phrase(String.valueOf(seq++), font));

        table.addCell(new Phrase(attendee.getUserAccount().getFullName(), font));

        table.addCell(new Phrase(attendee.getUserAccount().getEmail(), font));

        table.addCell(" ");
    }

    document.add(table);
}