Example usage for com.lowagie.text.pdf PdfPCell setPaddingRight

List of usage examples for com.lowagie.text.pdf PdfPCell setPaddingRight

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setPaddingRight.

Prototype

public void setPaddingRight(float paddingRight) 

Source Link

Document

Setter for property paddingRight.

Usage

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

License:Open Source License

protected void apply(PdfPCell cell, RenderingContext context, PJsonObject params) {
    if (paddingLeft != null)
        cell.setPaddingLeft(paddingLeft.floatValue());
    if (paddingRight != null)
        cell.setPaddingRight(paddingRight.floatValue());
    if (paddingTop != null)
        cell.setPaddingTop(paddingTop.floatValue());
    if (paddingBottom != null)
        cell.setPaddingBottom(paddingBottom.floatValue());

    if (borderWidthLeft != null)
        cell.setBorderWidthLeft(borderWidthLeft.floatValue());
    if (borderWidthRight != null)
        cell.setBorderWidthRight(borderWidthRight.floatValue());
    if (borderWidthTop != null)
        cell.setBorderWidthTop(borderWidthTop.floatValue());
    if (borderWidthBottom != null)
        cell.setBorderWidthBottom(borderWidthBottom.floatValue());

    if (getBorderColorLeftVal(context, params) != null)
        cell.setBorderColorLeft(getBorderColorLeftVal(context, params));
    if (getBorderColorRightVal(context, params) != null)
        cell.setBorderColorRight(getBorderColorRightVal(context, params));
    if (getBorderColorTopVal(context, params) != null)
        cell.setBorderColorTop(getBorderColorTopVal(context, params));
    if (getBorderColorBottomVal(context, params) != null)
        cell.setBorderColorBottom(getBorderColorBottomVal(context, params));

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

    if (align != null)
        cell.setHorizontalAlignment(align.getCode());
    if (vertAlign != null)
        cell.setVerticalAlignment(vertAlign.getCode());

}

From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableParagraph.java

License:Open Source License

@SuppressWarnings("unchecked")
public Element getElement() {
    if (!elementPostProcessed) {
        elementPostProcessed = true;/*from w  w w  .  ja  va  2 s  . co m*/

        // add space if this paragraph is empty
        // otherwise it's height will be zero
        boolean empty = true;
        ArrayList<Chunk> chunks = getChunks();
        for (Chunk chunk : chunks) {
            if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) {
                empty = false;
                break;
            }
        }
        if (empty) {
            super.add(new Chunk("\u00A0")); // non breaking space
        }

        // adjust line height and baseline
        if (font != null && font.getBaseFont() != null) {
            // iText and open office computes proportional line height differently
            // [iText] line height = coefficient * font size
            // [open office] line height = coefficient * (font ascender + font descender + font extra margin)
            // we have to increase paragraph line height to generate pdf similar to open office document
            // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph
            float size = font.getSize();
            float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size);
            float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value
            float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size);
            float multiplier = (ascender + descender + margin) / size;
            if (multipliedLeading > 0.0f) {
                setMultipliedLeading(getMultipliedLeading() * multiplier);
            }

            // iText seems to output text with baseline lower than open office
            // we raise all paragraph text by some amount
            // again this may be inaccurate if fonts with different size are used in this paragraph
            float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative
            float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier;
            chunks = getChunks();
            for (Chunk chunk : chunks) {
                Font f = chunk.getFont();
                if (f != null) {
                    // have to raise underline and strikethru as well
                    float s = f.getSize();
                    if (f.isUnderlined()) {
                        f.setStyle(f.getStyle() & ~Font.UNDERLINE);
                        chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise);
                    }
                    if (f.isStrikethru()) {
                        f.setStyle(f.getStyle() & ~Font.STRIKETHRU);
                        chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise);
                    }
                }
                chunk.setTextRise(chunk.getTextRise() + textRise);
            }
        }

        // wrap this paragraph into a table if necessary
        if (wrapperCell != null) {
            // background color or borders were set
            wrapperCell.addElement(this);
            wrapperTable = createTable(wrapperCell);
            if (getIndentationLeft() > 0.0f || getIndentationRight() > 0.0f || getSpacingBefore() > 0.0f
                    || getSpacingAfter() > 0.0f) {
                // margins were set, have to wrap the cell again
                PdfPCell outerCell = createCell();
                outerCell.setPaddingLeft(getIndentationLeft());
                setIndentationLeft(0.0f);
                outerCell.setPaddingRight(getIndentationRight());
                setIndentationRight(0.0f);
                outerCell.setPaddingTop(getSpacingBefore());
                setSpacingBefore(0.0f);
                outerCell.setPaddingBottom(getSpacingAfter());
                setSpacingAfter(0.0f);
                outerCell.addElement(wrapperTable);
                wrapperTable = createTable(outerCell);
            }
        }
    }
    return wrapperTable != null ? wrapperTable : this;
}

From source file:org.revager.export.InvitationPDFExporter.java

License:Open Source License

/**
 * Write the aspects./*from   w  w  w.  ja  va2s  .c  o m*/
 * 
 * @throws ExportException
 *             If an error occurs while writing the aspects
 */
private void writeAspects() throws ExportException {
    /*
     * If the role of the attendee is not reviewer show all aspects
     */
    List<Aspect> aspects = null;

    if (attendee.getRole() == Role.REVIEWER) {
        aspects = attMgmt.getAspects(attendee);
    } else {
        aspects = aspMgmt.getAspects();
    }

    if (aspects.size() == 0) {
        return;
    }

    try {
        Font descriptionFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font directiveFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font categoryFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font reviewerFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9);

        /*
         * Build base table for all attendees
         */
        PdfPTable tableAspects = new PdfPTable(1);
        tableAspects.setWidthPercentage(100);
        tableAspects.setSplitRows(false);
        tableAspects.getDefaultCell().setBorderWidth(0);
        tableAspects.getDefaultCell().setPadding(0);

        boolean grayBackground = true;

        for (Aspect asp : aspects) {
            /*
             * Build table for one aspect
             */
            PdfPTable tableAspect = new PdfPTable(new float[] { 0.70f, 0.30f });
            tableAspect.setWidthPercentage(100);
            tableAspect.getDefaultCell().setBorderWidth(0);
            tableAspect.getDefaultCell().setPadding(0);

            PdfPCell cellAspect = new PdfPCell();
            cellAspect.setPadding(0);
            cellAspect.setBorder(0);

            Phrase phraseStrut = new Phrase(" ");
            phraseStrut.setLeading(leading * 0.4f);

            /*
             * directive and description of the aspect
             */
            PdfPCell cell = new PdfPCell();
            cell.setBorderWidth(0);
            cell.setPadding(padding * 0.4f);
            cell.setPaddingBottom(padding * 1.5f);
            cell.addElement(new Phrase(asp.getDirective(), directiveFont));
            cell.addElement(phraseStrut);
            cell.addElement(new Phrase(asp.getDescription(), descriptionFont));

            /*
             * the reviewers of this aspect (moderator only)
             */
            if (attendee.getRole() == Role.MODERATOR) {
                cell.addElement(phraseStrut);
                cell.addElement(phraseStrut);

                String separator = "";

                Phrase phraseReviewers = new Phrase();
                phraseReviewers.setLeading(leading);
                phraseReviewers.setFont(reviewerFont);

                for (Attendee att : attMgmt.getAttendees()) {
                    if (attMgmt.hasAspect(asp, att)) {
                        phraseReviewers.add(new Chunk(separator + att.getName(), reviewerFont));

                        separator = "    ";
                    }
                }

                cell.addElement(phraseReviewers);
            }

            tableAspect.addCell(cell);

            /*
             * category of the aspect
             */
            cell = new PdfPCell(new Phrase(asp.getCategory(), categoryFont));
            cell.setBorderWidth(0);
            cell.setPadding(padding * 0.4f);
            cell.setPaddingTop(padding * 1.1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            tableAspect.addCell(cell);

            cellAspect.addElement(tableAspect);
            cellAspect.setPadding(0);
            cellAspect.setPaddingLeft(padding);
            cellAspect.setPaddingRight(padding);

            if (grayBackground == true) {
                grayBackground = false;
                cellAspect.setBackgroundColor(cellBackground);
            } else {
                grayBackground = true;
            }

            /*
             * Add aspect to the list
             */
            tableAspects.addCell(cellAspect);
        }

        PdfPCell cellBottomLine = new PdfPCell();
        cellBottomLine.setPadding(0);
        cellBottomLine.setBorderWidth(0);
        cellBottomLine.setBorderWidthBottom(1);
        cellBottomLine.setBorderColor(cellBackground);

        tableAspects.addCell(cellBottomLine);

        /*
         * Add the attendee base table to the document
         */
        pdfDoc.add(tableAspects);
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot put aspects into the PDF document."));
    }
}

From source file:org.revager.export.PDFPageEventHelper.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    int columnNumber;

    try {/*w w  w.  jav a 2 s. c  om*/
        Rectangle page = document.getPageSize();
        float pageWidth = page.getWidth() - document.leftMargin() - document.rightMargin();

        /*
         * Write marks
         */
        setMarks(writer, document);

        /*
         * Define fonts
         */
        headBaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        Font headFont = new Font(headBaseFont, headFontSize);

        footBaseFont = BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED);
        Font footFont = new Font(footBaseFont, footFontSize);

        /*
         * Cell fill for space between head/foot and content
         */
        PdfPCell cellFill = new PdfPCell();
        cellFill.setMinimumHeight(PDFTools.cmToPt(0.8f));
        cellFill.setBorderWidth(0);

        /*
         * Write head
         */
        if (headLogoPath != null) {
            columnNumber = 2;
        } else {
            columnNumber = 1;
        }

        PdfPTable head = new PdfPTable(columnNumber);

        Phrase phraseTitle = new Phrase(headTitle, headFont);

        PdfPCell cellTitle = new PdfPCell(phraseTitle);
        cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT);
        cellTitle.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cellTitle.setPaddingTop(0);
        cellTitle.setPaddingBottom(PDFTools.cmToPt(0.2f));
        cellTitle.setPaddingLeft(0);
        cellTitle.setPaddingRight(0);
        cellTitle.setBorderWidthTop(0);
        cellTitle.setBorderWidthBottom(0.5f);
        cellTitle.setBorderWidthLeft(0);
        cellTitle.setBorderWidthRight(0);

        head.addCell(cellTitle);

        if (headLogoPath != null) {
            Image headLogo = Image.getInstance(headLogoPath);
            headLogo.scaleToFit(PDFTools.cmToPt(5.0f), PDFTools.cmToPt(1.1f));

            PdfPCell cellLogo = new PdfPCell(headLogo);
            cellLogo.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cellLogo.setVerticalAlignment(Element.ALIGN_BOTTOM);
            cellLogo.setPaddingTop(0);
            cellLogo.setPaddingBottom(PDFTools.cmToPt(0.15f));
            cellLogo.setPaddingLeft(0);
            cellLogo.setPaddingRight(0);
            cellLogo.setBorderWidthTop(0);
            cellLogo.setBorderWidthBottom(0.5f);
            cellLogo.setBorderWidthLeft(0);
            cellLogo.setBorderWidthRight(0);

            head.addCell(cellLogo);

            head.addCell(cellFill);
        }

        head.addCell(cellFill);

        head.setTotalWidth(pageWidth);
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        /*
         * Write foot
         */
        if (footText == null) {
            footText = " ";
        }

        PdfPTable foot = new PdfPTable(1);

        foot.addCell(cellFill);

        PdfPCell cellFootText = new PdfPCell(new Phrase(footText, footFont));
        cellFootText.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellFootText.setVerticalAlignment(Element.ALIGN_TOP);
        cellFootText.setPaddingTop(PDFTools.cmToPt(0.15f));
        cellFootText.setPaddingBottom(0);
        cellFootText.setPaddingLeft(0);
        cellFootText.setPaddingRight(0);
        cellFootText.setBorderWidthTop(0.5f);
        cellFootText.setBorderWidthBottom(0);
        cellFootText.setBorderWidthLeft(0);
        cellFootText.setBorderWidthRight(0);

        foot.addCell(cellFootText);

        /*
         * Print page numbers
         */
        PdfContentByte contentByte = writer.getDirectContent();
        contentByte.saveState();

        String text = MessageFormat.format(translate("Page {0} of") + " ", writer.getPageNumber());

        float textSize = footBaseFont.getWidthPoint(text, footFontSize);
        float textBase = document.bottom() - PDFTools.cmToPt(1.26f);
        contentByte.beginText();
        contentByte.setFontAndSize(footBaseFont, footFontSize);

        float adjust;
        if (footText.trim().equals("")) {
            adjust = (pageWidth / 2) - (textSize / 2) - footBaseFont.getWidthPoint("0", footFontSize);
        } else {
            adjust = 0;
        }

        contentByte.setTextMatrix(document.left() + adjust, textBase);
        contentByte.showText(text);
        contentByte.endText();
        contentByte.addTemplate(template, document.left() + adjust + textSize, textBase);

        contentByte.stroke();
        contentByte.restoreState();

        foot.setTotalWidth(pageWidth);
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExceptionConverter(e);
    }
}

From source file:org.revager.export.ProtocolPDFExporter.java

License:Open Source License

/**
 * Write the title page of the protocol.
 * /*from  w w  w .j  a v a  2s. c  om*/
 * @param meetings
 *            the meetings
 * @param attachProdExtRefs
 *            true, if the external reference of the product should be part
 *            of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the title page
 */
protected void writeTitlePage(List<Meeting> meetings, boolean attachProdExtRefs) throws ExportException {
    try {
        Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED),
                10);

        Font plainFontSmall = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8);

        Font boldFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 11);

        Font italicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font italicFontSmall = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8);

        Font boldItalicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 11);

        Font boldItalicFontSmall = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8);

        Font protocolFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 20);

        Font reviewFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 15);

        Font meetingFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 13);

        /*
         * Title of the protocol
         */
        PdfPTable tableTitlePage = new PdfPTable(new float[] { 0.6f, 0.4f });
        tableTitlePage.setWidthPercentage(100);
        tableTitlePage.setSplitRows(false);
        tableTitlePage.getDefaultCell().setBorder(0);
        tableTitlePage.getDefaultCell().setPadding(0);

        String protocolTitle = translate("Findings List of the Review");

        if (meetings.size() == 1) {
            protocolTitle = translate("Findings List of the Review Meeting");
        }

        PdfPCell cellProtocol = new PdfPCell(new Phrase(protocolTitle, protocolFontTitle));
        cellProtocol.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellProtocol.setColspan(2);
        cellProtocol.setBorderWidth(0);
        cellProtocol.setPaddingTop(PDFTools.cmToPt(0.4f));
        cellProtocol.setPaddingBottom(PDFTools.cmToPt(0.2f));

        tableTitlePage.addCell(cellProtocol);

        /*
         * Name of the review
         */
        PdfPCell cellRevName = new PdfPCell(
                new Phrase(Application.getInstance().getReviewMgmt().getReviewName(), reviewFontTitle));
        cellRevName.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellRevName.setColspan(2);
        cellRevName.setBorderWidth(0);
        cellRevName.setPaddingBottom(PDFTools.cmToPt(1.6f));

        tableTitlePage.addCell(cellRevName);

        /*
         * Review meeting date and location
         */
        if (meetings.size() == 1) {
            sdfDate.setTimeZone(meetings.get(0).getProtocol().getDate().getTimeZone());
            sdfTime.setTimeZone(meetings.get(0).getProtocol().getDate().getTimeZone());

            String meetingDate = sdfDate.format(meetings.get(0).getProtocol().getDate().getTime());

            String meetingTime = sdfTime.format(meetings.get(0).getProtocol().getStart().getTime()) + " - "
                    + sdfTime.format(meetings.get(0).getProtocol().getEnd().getTime()) + " ["
                    + meetings.get(0).getProtocol().getEnd().getTimeZone().getDisplayName() + "]";

            Phrase phraseMeeting = new Phrase(meetingDate + " (" + meetingTime + ")", meetingFontTitle);

            PdfPCell cellMeeting = new PdfPCell(phraseMeeting);
            cellMeeting.setColspan(2);
            cellMeeting.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMeeting.setPadding(0);
            cellMeeting.setBorderWidth(0);

            tableTitlePage.addCell(cellMeeting);

            String location = meetings.get(0).getProtocol().getLocation();

            if (location.trim().equals("")) {
                location = "--";
            }
            cellMeeting = new PdfPCell(new Phrase(translate("Location") + ": " + location, meetingFontTitle));
            cellMeeting.setColspan(2);
            cellMeeting.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMeeting.setPadding(0);
            cellMeeting.setBorderWidth(0);
            cellMeeting.setPaddingTop(PDFTools.cmToPt(0.15f));
            cellMeeting.setPaddingBottom(PDFTools.cmToPt(1.9f));

            tableTitlePage.addCell(cellMeeting);
        }

        /*
         * Review description and comments
         */
        PdfPCell cellRevDesc = new PdfPCell(new Phrase(translate("Review Description:"), boldItalicFont));
        cellRevDesc.setBorderWidth(0);
        cellRevDesc.setPadding(padding);

        tableTitlePage.addCell(cellRevDesc);

        cellRevDesc = new PdfPCell(new Phrase(translate("Review Comments"), boldFont));
        cellRevDesc.setBorderWidth(0);
        cellRevDesc.setPadding(padding);
        cellRevDesc.setBackgroundColor(cellBackground);

        tableTitlePage.addCell(cellRevDesc);

        String revDesc = Application.getInstance().getReviewMgmt().getReviewDescription();
        if (revDesc.trim().equals("")) {
            revDesc = "--";
        }

        Phrase phrDesc = new Phrase(revDesc, plainFont);
        phrDesc.setLeading(leading);
        cellRevDesc = new PdfPCell();
        cellRevDesc.addElement(phrDesc);
        cellRevDesc.setBorderWidth(0);
        cellRevDesc.setPadding(padding);
        cellRevDesc.setPaddingBottom(padding * 1.8f);

        tableTitlePage.addCell(cellRevDesc);

        String revComm = Application.getInstance().getReviewMgmt().getReviewComments();
        if (revComm.trim().equals("")) {
            revComm = "--";
        }

        Phrase phrComm = new Phrase(revComm, italicFont);
        phrComm.setLeading(leading);
        cellRevDesc = new PdfPCell();
        cellRevDesc.addElement(phrComm);
        cellRevDesc.setBorderWidth(0);
        cellRevDesc.setPadding(padding);
        cellRevDesc.setPaddingBottom(padding * 1.8f);
        cellRevDesc.setBackgroundColor(cellBackground);

        tableTitlePage.addCell(cellRevDesc);

        tableTitlePage.addCell(createVerticalStrut(PDFTools.cmToPt(1.0f), 2));

        /*
         * Product title
         */
        PdfPTable tableProduct = new PdfPTable(new float[] { 0.07f, 0.93f });
        tableProduct.setWidthPercentage(100);
        tableProduct.setSplitRows(false);
        tableProduct.getDefaultCell().setBorderWidth(0);
        tableProduct.getDefaultCell().setPadding(0);

        PdfPCell cellProdTitle = new PdfPCell(new Phrase(translate("Reviewed Product:"), boldItalicFont));
        cellProdTitle.setColspan(2);
        cellProdTitle.setPadding(padding);
        cellProdTitle.setBorder(0);

        tableProduct.addCell(cellProdTitle);

        /*
         * List point used for lists
         */
        Phrase phraseListPoint = new Phrase("", boldFont);
        phraseListPoint.setLeading(leading);

        PdfPCell cellListPoint = new PdfPCell();
        cellListPoint.addElement(phraseListPoint);
        cellListPoint.setBorderWidth(0);
        cellListPoint.setPadding(padding);
        cellListPoint.setPaddingLeft(padding * 2);
        cellListPoint.setPaddingBottom(0);

        /*
         * Write name and version of the reviewed product
         */
        String prodName = Data.getInstance().getResiData().getReview().getProduct().getName();

        if (prodName.trim().equals("")) {
            prodName = "--";
        }

        Phrase phrName = new Phrase(translate("Product Name") + ": " + prodName, plainFont);
        phrName.setLeading(leading);

        PdfPCell cellName = new PdfPCell();
        cellName.addElement(phrName);
        cellName.setBorderWidth(0);
        cellName.setPadding(padding);
        cellName.setPaddingBottom(0);

        tableProduct.addCell(cellListPoint);

        tableProduct.addCell(cellName);

        String prodVersion = Data.getInstance().getResiData().getReview().getProduct().getVersion();

        if (prodVersion.trim().equals("")) {
            prodVersion = "--";
        }

        Phrase phrVersion = new Phrase(translate("Product Version") + ": " + prodVersion, plainFont);
        phrVersion.setLeading(leading);

        PdfPCell cellVersion = new PdfPCell();
        cellVersion.addElement(phrVersion);
        cellVersion.setBorderWidth(0);
        cellVersion.setPadding(padding);
        cellVersion.setPaddingBottom(0);

        tableProduct.addCell(cellListPoint);

        tableProduct.addCell(cellVersion);

        if (Application.getInstance().getReviewMgmt().getNumberOfProdRefs() > 0) {
            /*
             * Table of product references
             */
            PdfPCell cellRefTitle = new PdfPCell(new Phrase(translate("Product References:"), boldItalicFont));
            cellRefTitle.setBorderWidth(0);
            cellRefTitle.setPadding(padding);
            cellRefTitle.setPaddingTop(padding * 4);
            cellRefTitle.setColspan(2);

            tableProduct.addCell(cellRefTitle);

            /*
             * Textual references
             */
            for (String ref : Application.getInstance().getReviewMgmt().getProductReferences()) {
                Phrase phraseRef = new Phrase(ref, plainFont);
                phraseRef.setLeading(leading);

                PdfPCell cellRef = new PdfPCell();
                cellRef.addElement(phraseRef);
                cellRef.setBorderWidth(0);
                cellRef.setPadding(padding);
                cellRef.setPaddingBottom(0);

                tableProduct.addCell(cellListPoint);

                tableProduct.addCell(cellRef);
            }

            /*
             * External file references
             */
            for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) {
                Phrase phraseRef = new Phrase();
                phraseRef.add(new Chunk(ref.getName(), plainFont));
                phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFont));
                phraseRef.setFont(plainFont);
                phraseRef.setLeading(leading);

                PdfPCell cellRef = new PdfPCell();
                cellRef.addElement(phraseRef);
                cellRef.setBorderWidth(0);
                cellRef.setPadding(padding);
                cellRef.setPaddingBottom(0);

                tableProduct.addCell(cellListPoint);

                if (attachProdExtRefs) {
                    cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref));
                }

                tableProduct.addCell(cellRef);
            }
        }

        /*
         * Add the product table to the base table
         */
        PdfPCell cellProduct = new PdfPCell(tableProduct);
        cellProduct.setBorder(0);
        cellProduct.setPadding(0);

        tableTitlePage.addCell(cellProduct);

        /*
         * List the meetings of this review
         */
        PdfPCell cellInfos = new PdfPCell();
        cellInfos.setBorder(0);
        cellInfos.setPadding(0);

        /*
         * meeting list title or meeting info title
         */
        PdfPTable tableInfos = new PdfPTable(new float[] { 0.09f, 0.91f });
        tableInfos.setWidthPercentage(100);
        tableInfos.setSplitRows(false);
        tableInfos.getDefaultCell().setBorderWidth(0);
        tableInfos.getDefaultCell().setPadding(0);

        String title = translate("Meeting Information:");

        if (meetings.size() > 1) {
            title = translate("Findings Lists of the Review Meetings:");
        }

        PdfPCell cellInfosTitle = new PdfPCell(new Phrase(title, boldFont));
        cellInfosTitle.setColspan(2);
        cellInfosTitle.setPadding(padding);
        cellInfosTitle.setBorder(0);

        tableInfos.addCell(cellInfosTitle);

        if (meetings.size() > 1) {
            /*
             * list the meetings of this review (for review protocols)
             */
            for (Meeting m : meetings) {
                Protocol protocol = m.getProtocol();
                if (protocol != null) {
                    String meetingDate = sdfDate.format(protocol.getDate().getTime());

                    String meetingTime = sdfTime.format(protocol.getStart().getTime()) + " - "
                            + sdfTime.format(protocol.getEnd().getTime()) + " ["
                            + protocol.getEnd().getTimeZone().getDisplayName() + "]";
                    String protLoc = protocol.getLocation();
                    if (protLoc.trim().equals("")) {
                        protLoc = "--";
                    }

                    Phrase phraseMeet = new Phrase(
                            translate("Date") + ": " + meetingDate + "\n" + translate("Time") + ": "
                                    + meetingTime + "\n" + translate("Location") + ": " + protLoc,
                            italicFont);

                    Paragraph paraMeet = new Paragraph();
                    paraMeet.setLeading(leading);

                    Anchor anchor = new Anchor(phraseMeet);
                    anchor.setReference("#" + Long.toString(
                            protocol.getDate().getTimeInMillis() + protocol.getStart().getTimeInMillis()));

                    paraMeet.add(anchor);

                    PdfPCell cellMeet = new PdfPCell();
                    cellMeet.addElement(paraMeet);
                    cellMeet.setBorderWidth(0);
                    cellMeet.setPadding(padding);

                    tableInfos.addCell(cellListPoint);

                    tableInfos.addCell(cellMeet);
                }
            }
        } else {
            Protocol prot = meetings.get(0).getProtocol();
            Duration meetDur = DatatypeFactory.newInstance()
                    .newDuration(prot.getEnd().getTimeInMillis() - prot.getStart().getTimeInMillis());

            Phrase phraseMeetInfo = new Phrase(
                    translate("Duration of the meeting") + ":\n" + meetDur.getHours() + " "
                            + translate("Hour(s)") + ", " + meetDur.getMinutes() + " " + translate("Minute(s)"),
                    italicFont);
            phraseMeetInfo.setLeading(leading);

            PdfPCell cellMeetInfo = new PdfPCell();
            cellMeetInfo.addElement(phraseMeetInfo);
            cellMeetInfo.setBorderWidth(0);
            cellMeetInfo.setPadding(padding);

            tableInfos.addCell(cellListPoint);

            tableInfos.addCell(cellMeetInfo);

            /*
             * meeting number of findings
             */
            phraseMeetInfo = new Phrase(translate("Number of findings") + ": " + prot.getFindings().size(),
                    italicFont);
            phraseMeetInfo.setLeading(leading);

            cellMeetInfo = new PdfPCell();
            cellMeetInfo.addElement(phraseMeetInfo);
            cellMeetInfo.setBorderWidth(0);
            cellMeetInfo.setPadding(padding);

            tableInfos.addCell(cellListPoint);

            tableInfos.addCell(cellMeetInfo);

            /*
             * meeting number of attendees
             */
            phraseMeetInfo = new Phrase(
                    translate("Number of attendees") + ": " + protMgmt.getAttendees(prot).size(), italicFont);
            phraseMeetInfo.setLeading(leading);

            cellMeetInfo = new PdfPCell();
            cellMeetInfo.addElement(phraseMeetInfo);
            cellMeetInfo.setBorderWidth(0);
            cellMeetInfo.setPadding(padding);

            tableInfos.addCell(cellListPoint);

            tableInfos.addCell(cellMeetInfo);
        }

        cellInfos.addElement(tableInfos);
        cellInfos.setBackgroundColor(cellBackground);
        cellInfos.setPaddingBottom(padding);

        tableTitlePage.addCell(cellInfos);

        /*
         * Insert vertical strut
         */
        tableTitlePage.addCell(createVerticalStrut(PDFTools.cmToPt(1.0f), 2));

        /*
         * Write general impression and recommendation
         */
        PdfPTable tableRevInfo = new PdfPTable(new float[] { 0.5f, 0.5f });
        tableRevInfo.setWidthPercentage(100);
        tableRevInfo.setSplitRows(false);
        tableRevInfo.getDefaultCell().setBorderWidth(0);
        tableRevInfo.getDefaultCell().setPadding(0);

        /*
         * Insert vertical strut
         */
        tableRevInfo.addCell(createVerticalStrut(PDFTools.cmToPt(0.5f), 2));

        PdfPCell cellImpr = new PdfPCell(
                new Phrase(translate("General impressions of the product:"), boldFont));
        cellImpr.setBorderWidth(0);
        cellImpr.setPadding(padding);
        cellImpr.setBorderColor(verticalBorderColor);
        cellImpr.setBorderWidthLeft(verticalBorderWidth);

        tableRevInfo.addCell(cellImpr);

        PdfPCell cellReco = new PdfPCell(
                new Phrase(translate("Final recommendation for the product:"), boldFont));
        cellReco.setBorderWidth(0);
        cellReco.setPadding(padding);
        cellReco.setBorderColor(verticalBorderColor);
        cellReco.setBorderWidthLeft(verticalBorderWidth);

        tableRevInfo.addCell(cellReco);

        String impression = Application.getInstance().getReviewMgmt().getImpression();
        if (impression.trim().equals("")) {
            impression = "--";
        }

        Phrase phrImpr = new Phrase(impression, italicFont);
        phrImpr.setLeading(leading);
        cellImpr = new PdfPCell();
        cellImpr.addElement(phrImpr);
        cellImpr.setBorderWidth(0);
        cellImpr.setPadding(padding);
        cellImpr.setPaddingBottom(padding * 1.8f);
        cellImpr.setBorderColor(verticalBorderColor);
        cellImpr.setBorderWidthLeft(verticalBorderWidth);

        tableRevInfo.addCell(cellImpr);

        String recommendation = Application.getInstance().getReviewMgmt().getRecommendation();
        if (recommendation.trim().equals("")) {
            recommendation = "--";
        }

        Phrase phrReco = new Phrase(recommendation, italicFont);
        phrReco.setLeading(leading);
        cellReco = new PdfPCell();
        cellReco.addElement(phrReco);
        cellReco.setBorderWidth(0);
        cellReco.setPadding(padding);
        cellReco.setPaddingBottom(padding * 1.8f);
        cellReco.setBorderColor(verticalBorderColor);
        cellReco.setBorderWidthLeft(verticalBorderWidth);

        tableRevInfo.addCell(cellReco);

        /*
         * Add vertical strut
         */
        tableRevInfo.addCell(createVerticalStrut(PDFTools.cmToPt(0.8f), 2));

        /*
         * Write possible severities for this review
         */
        String severities = "";
        String separator = "";
        for (String sev : Application.getInstance().getSeverityMgmt().getSeverities()) {
            severities = severities + separator + sev;
            separator = "; ";
        }

        Phrase phrSeverities = new Phrase();
        phrSeverities.add(new Chunk(
                translate("The severities of the findings in this review (descending order of importance):"),
                italicFontSmall));
        phrSeverities.add(new Chunk(" " + severities, boldItalicFontSmall));
        phrSeverities.setLeading(leading);
        PdfPCell cellSevs = new PdfPCell();
        cellSevs.setColspan(2);
        cellSevs.addElement(phrSeverities);
        cellSevs.setBorderWidth(0);
        cellSevs.setPadding(padding);

        tableRevInfo.addCell(cellSevs);

        /*
         * Short review statistics
         */
        if (meetings.size() > 1) {
            Phrase phrRevStat = new Phrase(MessageFormat.format(translate(
                    "This review consists of {0} attendees, {1} findings, {2} meetings and {3} aspects."),
                    Application.getInstance().getReviewMgmt().getNumberOfAttendees(),
                    Application.getInstance().getReviewMgmt().getNumberOfFindings(),
                    Application.getInstance().getReviewMgmt().getNumberOfMeetings(),
                    Application.getInstance().getReviewMgmt().getNumberOfAspects()), italicFontSmall);
            phrRevStat.setLeading(leading);
            PdfPCell cellRevStat = new PdfPCell();
            cellRevStat.setColspan(2);
            cellRevStat.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellRevStat.addElement(phrRevStat);
            cellRevStat.setBorderWidth(0);
            cellRevStat.setPadding(padding);
            cellRevStat.setPaddingTop(0);

            tableRevInfo.addCell(cellRevStat);
        }

        /*
         * Write the date of creation
         */
        String creationDate = sdfDate.format(new Date().getTime());

        Phrase phrCreationDate = new Phrase(
                translate("This finding has been created with RevAger on") + " " + creationDate,
                plainFontSmall);
        phrCreationDate.setLeading(leading);
        PdfPCell cellCrDate = new PdfPCell();
        cellCrDate.setColspan(2);
        cellCrDate.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellCrDate.addElement(phrCreationDate);
        cellCrDate.setBorderWidth(0);
        cellCrDate.setPadding(0);
        cellCrDate.setPaddingLeft(padding);
        cellCrDate.setPaddingRight(padding);

        tableRevInfo.addCell(cellCrDate);

        /*
         * Add content to the base table
         */
        PdfPCell cellRevInfo = new PdfPCell();
        cellRevInfo.setColspan(2);
        cellRevInfo.setBorder(0);
        cellRevInfo.setPadding(0);
        cellRevInfo.addElement(tableRevInfo);

        tableTitlePage.addCell(cellRevInfo);

        pdfDoc.add(tableTitlePage);
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot generate front page of the PDF document."));
    }
}

From source file:org.revager.export.ProtocolPDFExporter.java

License:Open Source License

/**
 * Writes the given attendees to the protocol.
 * /*from   w  w w.  ja  va2  s .c  o  m*/
 * @param protocol
 *            the protocol
 * @param showAttendeesAspects
 *            true, if the aspects of the reviewers should be part of the
 *            protocol
 * @param showAttendeesPrepTime
 *            true, if the preparation time of the reviewers should be part
 *            of the protocol
 * @param showSignatureFields
 *            ture, if the signature fields should be part of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the attendees to the
 *             protocol
 */
protected void writeAttendees(Protocol protocol, boolean showAttendeesAspects, boolean showAttendeesPrepTime,
        boolean showSignatureFields) throws ExportException {
    List<Attendee> atts;

    if (protocol != null) {
        atts = protMgmt.getAttendees(protocol);
    } else {
        atts = Application.getInstance().getAttendeeMgmt().getAttendees();
    }

    /*
     * Sort the attendees by their role into different lists
     */
    List<Attendee> reviewers = new ArrayList<Attendee>();
    List<Attendee> moderators = new ArrayList<Attendee>();
    List<Attendee> scribes = new ArrayList<Attendee>();
    List<Attendee> authors = new ArrayList<Attendee>();
    List<Attendee> customers = new ArrayList<Attendee>();
    List<Attendee> others = new ArrayList<Attendee>();

    for (Attendee att : atts) {
        switch (att.getRole()) {
        case AUTHOR:
            authors.add(att);
            break;
        case CUSTOMER:
            customers.add(att);
            break;
        case MODERATOR:
            moderators.add(att);
            break;
        case REVIEWER:
            reviewers.add(att);
            break;
        case SCRIBE:
            scribes.add(att);
            break;
        default:
            others.add(att);
            break;
        }
    }

    List<List<Attendee>> attendees = new ArrayList<List<Attendee>>();
    attendees.add(moderators);
    attendees.add(scribes);
    attendees.add(authors);
    attendees.add(customers);
    attendees.add(reviewers);
    attendees.add(others);

    /*
     * Write attendees
     */
    try {
        Font contactFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED),
                10);

        Font nameFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font roleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font aspectsFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8);

        Font aspectsTitleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8);

        /*
         * Build base table for all attendees
         */
        PdfPTable tableAttendees = new PdfPTable(1);
        tableAttendees.setWidthPercentage(100);
        tableAttendees.setSplitRows(false);
        tableAttendees.getDefaultCell().setBorderWidth(0);
        tableAttendees.getDefaultCell().setPadding(0);

        boolean grayBackground = true;

        for (List<Attendee> attList : attendees) {
            for (Attendee att : attList) {
                /*
                 * Build table for one attendee
                 */
                PdfPTable tableAttendee = new PdfPTable(new float[] { 0.80f, 0.20f });
                tableAttendee.setWidthPercentage(100);
                tableAttendee.getDefaultCell().setBorderWidth(0);
                tableAttendee.getDefaultCell().setPadding(0);

                PdfPCell cellAttendee = new PdfPCell();
                cellAttendee.setPadding(0);
                cellAttendee.setBorder(0);

                /*
                 * Name of the attendee
                 */
                PdfPCell cell = new PdfPCell();
                cell.setBorderWidth(0);
                cell.setPadding(padding * 0.4f);
                cell.setPaddingBottom(padding * 1.5f);
                cell.addElement(new Phrase(att.getName(), nameFont));
                cell.addElement(new Phrase(att.getContact(), contactFont));

                Phrase phraseStrut = new Phrase(" ");
                phraseStrut.setLeading(leading * 0.6f);

                /*
                 * Aspects of this attendee
                 */
                if (!attMgmt.getAspects(att).isEmpty() && showAttendeesAspects) {
                    String separator = "";

                    cell.addElement(phraseStrut);

                    cell.addElement(new Phrase(translate("Assigned aspects:") + " ", aspectsTitleFont));

                    Phrase phraseAspects = new Phrase();
                    phraseAspects.setLeading(leading);
                    phraseAspects.setFont(aspectsFont);

                    for (Aspect asp : attMgmt.getAspects(att)) {
                        phraseAspects.add(new Chunk(
                                separator + asp.getDirective() + " (" + asp.getCategory() + ")", aspectsFont));

                        separator = "    ";
                    }

                    cell.addElement(phraseAspects);
                }

                /*
                 * Preparation time of the attendee
                 */
                Duration prepTime;
                if (protocol != null) {
                    prepTime = protMgmt.getAttendeePrepTime(att, protocol);
                } else {
                    prepTime = null;
                }

                if (prepTime != null && showAttendeesPrepTime) {
                    cell.addElement(phraseStrut);

                    cell.addElement(new Phrase(translate("Preparation time:") + " ", aspectsTitleFont));

                    Phrase phrasePrepTime = new Phrase();
                    phrasePrepTime.setLeading(leading);
                    phrasePrepTime.setFont(aspectsFont);

                    String prep = "";
                    String separator = "";

                    if (prepTime.getDays() > 0) {
                        prep = prep + prepTime.getDays() + " " + translate("Day(s)");

                        separator = ", ";
                    }

                    if (prepTime.getHours() > 0) {
                        prep = prep + separator + prepTime.getHours() + " " + translate("Hour(s)");

                        separator = ", ";
                    }

                    if (prepTime.getMinutes() >= 0) {
                        prep = prep + separator + prepTime.getMinutes() + " " + translate("Minute(s)");

                        separator = ", ";
                    }

                    phrasePrepTime.add(new Chunk(prep, aspectsFont));

                    cell.addElement(phrasePrepTime);
                }

                /*
                 * Signature field for the attendee
                 */
                if (showSignatureFields) {
                    cell.addElement(phraseStrut);
                    cell.addElement(phraseStrut);
                    cell.addElement(phraseStrut);
                    cell.addElement(phraseStrut);

                    cell.addElement(new Phrase("________________________________________", aspectsFont));

                    cell.addElement(
                            new Phrase(translate("Date, Signature") + " (" + att.getName() + ")", aspectsFont));
                }

                tableAttendee.addCell(cell);

                /*
                 * role of the attendee
                 */
                cell = new PdfPCell(new Phrase(translate(att.getRole().toString()), roleFont));
                cell.setBorderWidth(0);
                cell.setPadding(padding * 0.4f);
                cell.setPaddingTop(padding * 1.1f);
                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

                tableAttendee.addCell(cell);

                cellAttendee.addElement(tableAttendee);
                cellAttendee.setPadding(0);
                cellAttendee.setPaddingLeft(padding);
                cellAttendee.setPaddingRight(padding);

                if (grayBackground == true) {
                    grayBackground = false;
                    cellAttendee.setBackgroundColor(cellBackground);
                } else {
                    grayBackground = true;
                }

                /*
                 * Add attendee to the list
                 */
                tableAttendees.addCell(cellAttendee);
            }
        }

        PdfPCell cellBottomLine = new PdfPCell();
        cellBottomLine.setPadding(0);
        cellBottomLine.setBorderWidth(0);
        cellBottomLine.setBorderWidthBottom(1);
        cellBottomLine.setBorderColor(cellBackground);

        tableAttendees.addCell(cellBottomLine);

        /*
         * Add the attendee base table to the document
         */
        pdfDoc.add(tableAttendees);
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot put attendees into the PDF document."));
    }
}

From source file:org.tellervo.desktop.print.BasicBoxLabel.java

License:Open Source License

public void generateBoxLabel(OutputStream output) {

    try {/*ww  w  .  j a  v a2 s.com*/

        PdfWriter writer = PdfWriter.getInstance(document, output);

        document.setPageSize(PageSize.LETTER);

        document.open();

        cb = writer.getDirectContent();

        // Set basic metadata
        document.addAuthor("Tellervo");
        document.addSubject("Tellervo Box Labels");

        PdfPTable table = new PdfPTable(2);
        table.setTotalWidth(495f);
        table.setLockedWidth(true);

        for (WSIBox b : boxlist) {
            Paragraph p = new Paragraph();

            p.add(new Chunk(b.getTitle() + Chunk.NEWLINE, labelTitleFont));
            p.add(new Chunk(Chunk.NEWLINE + b.getComments() + Chunk.NEWLINE, bodyFont));
            p.add(new Chunk(App.getLabName() + Chunk.NEWLINE + Chunk.NEWLINE, bodyFont));
            p.add(new Chunk(this.getBarCode(b), 0, 0, true));

            PdfPCell cell = new PdfPCell(p);
            cell.setPaddingLeft(15f);
            cell.setPaddingRight(15f);
            cell.setBorderColor(Color.LIGHT_GRAY);

            table.addCell(cell);

        }

        PdfPCell cell = new PdfPCell(new Paragraph());
        cell.setBorderColor(Color.LIGHT_GRAY);

        table.addCell(cell);
        document.add(table);
        document.close();

        /*float top = document.top(15);
        int row = 1;
                
        for(int i = 0; i< boxlist.size(); i = i+2)
        {
                   
           log.debug("Document left : "+document.left());
           log.debug("Document right: "+document.right());
           log.debug("Top           : "+top);
                   
                   
                   
                   
                   
                   
          // Column 1      
          ColumnText ct1a = new ColumnText(cb);
          ct1a.setSimpleColumn(document.left(), 
                   top-210, 
                   368, 
                   top, 
                   20, 
                   Element.ALIGN_LEFT);
                  
          ColumnText ct1b = new ColumnText(cb);
          ct1b.setSimpleColumn(document.left(), 
             top-70, 
             document.left()+206, 
             top-150, 
             20, 
             Element.ALIGN_LEFT);
                  
          try{
        WSIBox b1 = boxlist.get(i);
        ct1a.addText(getTitlePDF(b1));
        ct1a.go();
                     
                
        ct1b.addElement(getBarCode(b1));
        ct1b.go();
                
          } catch (Exception e)
          {
             log.debug("Failed writing box label in left column where i="+i);
          }
                  
                  
          // Column 2      
          ColumnText ct2a = new ColumnText(cb);
          ct2a.setSimpleColumn(306, 
                   top-210, 
                   document.right(), 
                   top, 
                   20, 
                   Element.ALIGN_LEFT);
                  
          ColumnText ct2b = new ColumnText(cb);
          ct2b.setSimpleColumn(306, 
             top-70, 
             512,  
             top-80, 
             20, 
             Element.ALIGN_LEFT);
                  
          try{
        WSIBox b2 = boxlist.get(i+1);
        ct2a.addText(getTitlePDF(b2));
        ct2a.go();
                     
                
        ct2b.addElement(getBarCode(b2));
        ct2b.go();
                
          } catch (Exception e)
          {
             log.debug("Failed writing box label in right column where i="+i);
             //e.printStackTrace();
          }
                  
                  
          // Column 2
        /*   ColumnText ct2 = new ColumnText(cb);
          ct2.setSimpleColumn(370,     //llx 
          top-100,            //lly   
          document.right(0),   //urx
          top+15,            //ury
          20,               //leading
          Element.ALIGN_RIGHT  //alignment
          );
                  
          try{
          WSIBox b2 = boxlist.get(i+1);
          ct2.addText(getTitlePDF(b2));
          ct2.addElement(getBarCode(b2));
          ct2.go();
          } catch (Exception e)
          {
             log.debug("Failed writing box label where i="+i+1);
          }
          */
        /*
                
        top = top-160;
                
        if(row==5)
        {
           top = document.top(15);
        document.newPage();
        row=1;
        }
        else
        {
           row++;
        }
                
                
                
                
                
        }*/

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }

    // Close the document
    document.close();
}

From source file:org.unitime.timetable.export.PDFPrinter.java

License:Open Source License

@Override
public void printLine(String... fields) {
    PdfPCellEvent setLineDashEvent = new PdfPCellEvent() {
        @Override//  w  ww. j av a 2  s.c o  m
        public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
            PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
            cb.setLineDash(new float[] { 2, 2 }, 0);
        }
    };

    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        String f = fields[idx];
        if (f == null || f.isEmpty() || (iCheckLast
                && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx])))
            f = "";

        boolean number = sNumber.matcher(f).matches();

        Font font = PdfFont.getFont();
        Phrase p = new Phrase(f, PdfFont.getSmallFont());

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(iLastLine == null ? Rectangle.TOP : Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(number ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT);
        cell.setPaddingBottom(4f);
        cell.setCellEvent(setLineDashEvent);
        if (number)
            cell.setPaddingRight(10f);
        iTable.addCell(cell);

        float width = 0;
        if (f.indexOf('\n') >= 0) {
            for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();)
                width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
        } else
            width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize()));
        iMaxWidth[idx] = Math.max(iMaxWidth[idx], width + (number ? 10 : 0));
    }
    iLastLine = fields;
}

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

public void createPDF() {
    doc = new Document(PageSize.A4);
    try {//from ww  w  .  j  a va  2s. 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();
    }
}

From source file:uk.ac.ox.oucs.vle.resources.PDFWriter.java

License:Educational Community License

private PdfPCell headCell(String name, Font font) {

    PdfPCell pdfCell = new PdfPCell(new Phrase(name, font));
    pdfCell.setMinimumHeight(font.getSize() * 2f);
    pdfCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    pdfCell.setVerticalAlignment(Element.ALIGN_CENTER);
    pdfCell.setPaddingBottom(font.getSize() * 0.5f);
    pdfCell.setPaddingTop(font.getSize() * 0.5f);
    pdfCell.setPaddingLeft(font.getSize());
    pdfCell.setPaddingRight(font.getSize());
    return pdfCell;
}