Example usage for com.lowagie.text Element ALIGN_CENTER

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

Introduction

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

Prototype

int ALIGN_CENTER

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

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:org.apache.poi.xwpf.converter.internal.itext.StyleEngineForIText.java

License:Open Source License

private StyleParagraphProperties mapStyleParagraphProperties(CTPPr xwpfParagraphProperties) {
    StyleParagraphProperties paragraphProperties = new StyleParagraphProperties();
    CTSpacing spacing = xwpfParagraphProperties.getSpacing();
    if (spacing != null) {

        BigInteger spacingBefore = spacing.getBefore();

        if (spacingBefore != null) {
            paragraphProperties.setSpacingBefore(spacingBefore.intValue());
        }/*w  w  w  . j a  v  a  2s .c o  m*/
        BigInteger spacingAfter = spacing.getAfter();
        if (spacingAfter != null) {
            paragraphProperties.setSpacingAfter(spacingAfter.intValue());
        }
    }

    // TODO : text Alignement...

    CTTextAlignment alignment = xwpfParagraphProperties.getTextAlignment();

    if (alignment != null) {
        STTextAlignment textAlignment = alignment.xgetVal();

        if (STTextAlignment.BASELINE.equals(textAlignment)) {
            paragraphProperties.setAlignment(Element.ALIGN_BASELINE);
        } else if (STTextAlignment.BOTTOM.equals(textAlignment)) {
            paragraphProperties.setAlignment(Element.ALIGN_BOTTOM);
        } else if (STTextAlignment.CENTER.equals(textAlignment)) {
            paragraphProperties.setAlignment(Element.ALIGN_CENTER);
        } else if (STTextAlignment.TOP.equals(textAlignment)) {
            paragraphProperties.setAlignment(Element.ALIGN_TOP);
        }

    }
    CTInd ctInd = xwpfParagraphProperties.getInd();
    if (ctInd != null) {
        processIndent(paragraphProperties, ctInd);

    }

    // CTParaRPr ctParaRPr = xwpfParagraphProperties.getRPr();
    // if (ctParaRPr != null) {
    //
    // }
    return paragraphProperties;
}

From source file:org.areasy.common.doclet.document.CustomTitle.java

License:Open Source License

/**
 * Prints the title page.//from w  w w .j  a v a 2  s.c om
 *
 * @throws Exception
 */
public void print() throws Exception {
    String apiTitlePageProp = DefaultConfiguration.getString(ARG_DOC_TITLE_PAGE, ARG_VAL_NO).toLowerCase();

    if (apiTitlePageProp.equalsIgnoreCase(ARG_VAL_YES)) {
        String apiFileProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_TITLE_FILE, "");

        // If the (pdf) filename contains page information, remove it,
        // because for the title page only 1 page can be imported
        if (apiFileProp.indexOf(",") != -1)
            apiFileProp = apiFileProp.substring(0, apiFileProp.indexOf(","));

        String labelTitle = DefaultConfiguration.getString(ARG_LB_OUTLINE_TITLE, LB_TITLE);
        String titleDest = "TITLEPAGE:";

        if (apiFileProp.length() > 0) {
            File apiFile = new File(DefaultConfiguration.getWorkDir(), apiFileProp);

            if (apiFile.exists() && apiFile.isFile()) {
                Destinations.addValidDestinationFile(apiFile);
                State.setCurrentFile(apiFile);

                pdfDocument.newPage();
                pdfDocument.add(PDFUtility.createAnchor(titleDest));
                Bookmarks.addRootBookmark(labelTitle, titleDest);

                if (apiFile.getName().toLowerCase().endsWith(".pdf")) {
                    PDFUtility.insertPdfPages(apiFile, "1");
                } else {
                    String html = DocletUtility.getHTMLBodyContentFromFile(apiFile);
                    Element[] objs = HtmlParserWrapper.createPdfObjects(html);
                    PDFUtility.printPdfElements(objs);
                }
            } else
                log.error("Title page file not found or invalid: " + apiFileProp);
        } else {
            String apiTitleProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_TITLE, "");
            String apiCopyrightProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_COPYRIGHT, "");
            String apiAuthorProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_AUTHOR, "");
            String apiVersionProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_VERSION, "");

            if (apiVersionProp != null && apiVersionProp.length() > 0)
                apiVersionProp = "Version " + apiVersionProp;

            pdfDocument.newPage();
            pdfDocument.add(PDFUtility.createAnchor(titleDest));
            Bookmarks.addRootBookmark(labelTitle, titleDest);

            Paragraph p1 = new Paragraph((float) 100.0,
                    new Chunk(apiTitleProp, Fonts.getFont(TEXT_FONT, BOLD, 42)));
            Paragraph p2 = new Paragraph((float) 140.0,
                    new Chunk(apiAuthorProp, Fonts.getFont(TEXT_FONT, BOLD, 18)));
            Paragraph p3 = new Paragraph((float) 20.0,
                    new Chunk(apiCopyrightProp, Fonts.getFont(TEXT_FONT, 12)));
            Paragraph p4 = new Paragraph((float) 20.0,
                    new Chunk(apiVersionProp, Fonts.getFont(TEXT_FONT, BOLD, 12)));

            p1.setAlignment(Element.ALIGN_CENTER);
            p2.setAlignment(Element.ALIGN_CENTER);
            p3.setAlignment(Element.ALIGN_CENTER);
            p4.setAlignment(Element.ALIGN_CENTER);

            pdfDocument.add(p1);
            pdfDocument.add(p2);
            pdfDocument.add(p3);
            pdfDocument.add(p4);
        }
    }
}

From source file:org.areasy.common.doclet.document.tags.HtmlTag.java

License:Open Source License

/**
 * Creates a PDF Paragraph with the appropriate
 * alignment and the default leading and correct font.
 *
 * @param content The Chunk that goes into the Paragraph.
 * @return The resulting PDF Paragraph object.
 *//*  w  w w .  j av a  2  s. c o m*/
public Paragraph createParagraph(Chunk content) {
    Paragraph result = new Paragraph(getLeading(), content);

    if (isCentered())
        result.setAlignment(Element.ALIGN_CENTER);
    if (isRight())
        result.setAlignment(Element.ALIGN_RIGHT);

    return result;
}

From source file:org.areasy.common.doclet.document.tags.HtmlTagUtility.java

License:Open Source License

/**
 * Returns the Element constant associated with the specified horizontal
 * alignment (left, right, center, justified).
 *///from   w w  w.  java 2  s .  com
public static int getAlignment(String htmlAlignString, int defaultAlign) {
    if (htmlAlignString == null)
        return defaultAlign;

    if ("center".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_CENTER;
    if ("right".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_RIGHT;
    if ("left".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_LEFT;
    if ("justify".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_JUSTIFIED;

    return defaultAlign;
}

From source file:org.areasy.common.doclet.document.tags.TagIMG.java

License:Open Source License

public Element[] toPdfObjects() {
    String src = getAttribute("src");
    Element[] results = new Element[0];
    Element result = null;/*  ww w. j  av a2  s .c o  m*/

    if (src == null) {
        log.error("Image tag has no 'src' attribute.");
        return null;
    }

    try {
        // now we use awt Image to create iText image instead of
        // letting it read images by itself
        java.awt.Image awt = null;

        if (src.indexOf("://") > 0)
            awt = Toolkit.getDefaultToolkit().createImage(new URL(src));
        else {
            String filePath = DocletUtility.getFilePath(src);
            awt = Toolkit.getDefaultToolkit().createImage(filePath);
        }

        //img = Image.getInstance(PDFUtil.getFilePath(src));
        img = Image.getInstance(awt, null);

        // for the time being let's stick with A4
        Rectangle size = PageSize.A4;
        String width = getAttribute("width");

        if (width != null) {
            // trying to cope with the resolution differences
            float w = NumberUtility.toFloat(width, 0) / 96 * 72;
            img.scaleAbsoluteWidth(w);
        }

        float maxW = size.width() - 100;

        if (img.plainWidth() > maxW)
            img.scaleAbsoluteWidth(maxW);

        String height = getAttribute("height");

        if (height != null) {
            // trying to cope with the resolution differences
            float h = NumberUtility.toFloat(height, 0) / 96 * 72;
            img.scaleAbsoluteHeight(h);
        }

        float maxH = size.height() - 100;

        if (img.plainHeight() > maxH)
            img.scaleAbsoluteHeight(maxH);

        result = img;

        img.setAlignment(HtmlTagUtility.getAlignment(getAttribute("align"), Element.ALIGN_CENTER));

        String border = getAttribute("border");

        if (border != null) {
            // trying to cope with the resolution differences
            float b = NumberUtility.toFloat(border, 0);

            img.setBorder((int) b);
            img.setBorderWidthTop(b);
            img.setBorderWidthLeft(b);
            img.setBorderWidthRight(b);
            img.setBorderWidthBottom(b);
            img.setBorderColor(Color.black);
        }

    } catch (FileNotFoundException e) {
        DocletUtility.error("** Image not found: " + src, e);
    } catch (Exception e) {
        DocletUtility.error("** Failed to read image: " + src, e);
    }

    if (result != null) {
        results = new Element[1];
        results[0] = result;
    }

    return results;
}

From source file:org.areasy.common.doclet.document.tags.TagTABLE.java

License:Open Source License

private void createTable(int numcols) {
    table = new PdfPTable(numcols);

    String width = getAttribute("width");
    if (width == null)
        table.setWidthPercentage(100);/*w ww .j av  a  2s  .c  o  m*/
    else if (width.endsWith("%"))
        table.setWidthPercentage(HtmlTagUtility.parseFloat(width, 100f));
    else
        table.setTotalWidth(HtmlTagUtility.parseFloat(width, 400f));

    table.getDefaultCell().setPadding(HtmlTagUtility.parseFloat(getAttribute("cellpadding"), 2.0f));
    table.getDefaultCell().setBackgroundColor(HtmlTagUtility.getColor(getAttribute("bgcolor")));
    table.setHorizontalAlignment(HtmlTagUtility.getAlignment(getAttribute("align"), Element.ALIGN_CENTER));

    /* Border doesn't have to have a value set */
    if (getAttribute("border") != null) {
        table.getDefaultCell().setBorder(Rectangle.BOX);
        table.getDefaultCell().setBorderWidth(HtmlTagUtility.parseFloat(getAttribute("border"), 1.0f));
        table.getDefaultCell().setBorderColor(HtmlTagUtility.getColor("gray"));
    } else {
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setBorderWidth(0.0f);
    }

    //set width data for columns.
    setTableWidthsForCells();
}

From source file:org.areasy.common.doclet.document.tags.TagTD.java

License:Open Source License

private PdfPCell createCell(Element[] content) {
    int defaultAlign = (getType() == TAG_TH) ? Element.ALIGN_CENTER : Element.ALIGN_LEFT;

    String align = getInheritedAttribute("align", false);
    String valign = getInheritedAttribute("valign", false);
    String bgcolor = getInheritedAttribute("bgcolor", true);
    int alignment = HtmlTagUtility.getAlignment(align, defaultAlign);

    PdfPCell cell = PDFUtility.createElementCell(2, alignment, content);

    cell.setHorizontalAlignment(HtmlTagUtility.getAlignment(align, defaultAlign));
    cell.setVerticalAlignment(HtmlTagUtility.getVerticalAlignment(valign, Element.ALIGN_MIDDLE));
    cell.setBackgroundColor(HtmlTagUtility.getColor(bgcolor));
    cell.setColspan(parseSpan(getAttribute("colspan")));

    cell.setUseAscender(true); // needs newer iText
    cell.setUseDescender(true); // needs newer iText
    cell.setUseBorderPadding(true); // needs newer iText

    if (getAttribute("nowrap") != null)
        cell.setNoWrap(true);//from  w  w w  .  ja  v  a 2 s .  c o m
    if (getType() == TAG_TH)
        cell.setMarkupAttribute(HEADER_INDICATOR_ATTR, "true");

    return cell;
}

From source file:org.caisi.tickler.web.TicklerPrinter.java

License:Open Source License

private void addStandardTableEntry(PdfPTable table, String name, String value) {
    PdfPCell cell1 = new PdfPCell(getParagraph(name + ":"));

    cell1.setBorder(PdfPCell.BOTTOM);//from   w w w .  j a va  2s .  com
    cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell cell2 = new PdfPCell(getParagraph(value));
    cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell2.setBorder(PdfPCell.BOTTOM);

    table.addCell(cell1);
    table.addCell(cell2);
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java

License:Open Source License

/**
 * Entering the project title in the summary
 *//* w  w  w .  ja  va2 s.  c o m*/
private void addProjectTitle() {
    LineSeparator line = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -7);
    Paragraph paragraph = new Paragraph();
    line.setLineColor(titleColor);
    try {
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        paragraph.setFont(BODY_TEXT_BOLD_FONT);
        paragraph.add("Project: ");
        paragraph.setFont(BODY_TEXT_FONT);
        paragraph.add(this.messageReturn("P" + project.getId() + " - "));
        paragraph.add(this.messageReturn(project.getTitle()));
        paragraph.add(line);
        document.add(paragraph);
        document.add(Chunk.NEWLINE);
        ;
    } catch (DocumentException e) {
        LOG.error("There was an error trying to add the project title to the project summary pdf", e);
    }
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

/**
 * This method add Activities for the summary project
 *//*from w w  w. j a  v  a2s .  c  om*/
private void addActivities() {

    try {
        document.newPage();
        Paragraph activityBlock = new Paragraph("6. " + this.getText("summaries.project.activity"),
                HEADING2_FONT);
        activityBlock.setAlignment(Element.ALIGN_JUSTIFIED);
        activityBlock.add(Chunk.NEWLINE);

        PdfPTable table;
        List<Activity> listActivities = project.getActivities();

        if (listActivities.isEmpty()) {
            activityBlock.setFont(BODY_TEXT_FONT);
            activityBlock.add(this.getText("summaries.project.empty"));
            document.add(activityBlock);
        } else {
            activityBlock.add(Chunk.NEWLINE);
            document.add(activityBlock);
            int counter = 1;
            for (Activity activity : listActivities) {
                boolean printActity = true;
                if (activity != null) {
                    if (!project.isReporting()) {
                        Calendar c = Calendar.getInstance();
                        c.setTime(activity.getEndDate());
                        Calendar cStartDate = Calendar.getInstance();
                        cStartDate.setTime(activity.getStartDate());
                        if (c.get(Calendar.YEAR) != config.getPlanningCurrentYear()) {
                            if (cStartDate.get(Calendar.YEAR) != config.getPlanningCurrentYear()) {
                                printActity = false;
                            }

                        }

                        if (activity.getActivityStatus() == Integer
                                .parseInt(ProjectStatusEnum.Cancelled.getStatusId())) {
                            printActity = false;
                        }
                    }
                    if (printActity) {
                        table = new PdfPTable(2);
                        table.setTotalWidth(480);
                        table.setLockedWidth(true);

                        // Header table
                        activityBlock = new Paragraph();
                        activityBlock.setAlignment(Element.ALIGN_CENTER);
                        activityBlock.setFont(TABLE_HEADER_FONT);
                        activityBlock.add("Activity #" + counter);

                        PdfPCell cell_new = new PdfPCell(activityBlock);
                        cell_new.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE);
                        cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND);
                        cell_new.setUseBorderPadding(true);
                        cell_new.setPadding(3);
                        cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR);
                        cell_new.setColspan(2);

                        this.addTableHeaderCell(table, cell_new);

                        // Activity title
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.title"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(this.messageReturn(activity.getTitle()));
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        // Activity description
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.description"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(this.messageReturn(activity.getDescription()));
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        String startDate = null;
                        String endDate = null;
                        try {
                            startDate = new SimpleDateFormat("dd-MM-yyyy").format(activity.getStartDate());
                        } catch (Exception e) {

                        }
                        try {

                            endDate = new SimpleDateFormat("dd-MM-yyyy").format(activity.getEndDate());
                        } catch (Exception e) {

                        }

                        // Activity Start Date
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.startDate") + " (dd-MM-yyyy)" + ": ");

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(startDate);
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                        // Activity End Date
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.endDate") + " (dd-MM-yyyy)" + ": ");

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(endDate);
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                        // Activity Leader
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.activityLeader") + ": ");
                        activityBlock.setFont(TABLE_BODY_FONT);

                        PartnerPerson activityPartnerPerson = activity.getLeader();

                        if (activityPartnerPerson != null) {
                            activityBlock.add(activityPartnerPerson.getComposedName());
                            String partnerInstitution = this.mapPartnerPersons
                                    .get(String.valueOf(activityPartnerPerson.getId()));
                            if (partnerInstitution != null) {
                                activityBlock.add(", " + partnerInstitution);
                            }
                        } else {
                            activityBlock.add(this.getText("summaries.project.empty"));
                        }
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        // if (project.isReporting()) {
                        // status
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.status"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        if (activity.getActivityStatus() > 0) {
                            activityBlock.add(statuses.get(String.valueOf(activity.getActivityStatus())));
                        } else {
                            activityBlock.add(" " + this.getText("summaries.project.empty"));
                            // }
                            activityBlock.add(Chunk.NEWLINE);

                            if (activity.isStatusCancelled() || activity.isStatusExtended()
                                    || activity.isStatusOnGoing()) {
                                this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                                activityBlock = new Paragraph();
                                activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                                activityBlock.add(this.getText("summaries.project.activities.justification"));

                                activityBlock.setFont(TABLE_BODY_FONT);
                                activityBlock.add(this.messageReturn(activity.getActivityProgress()));
                                activityBlock.add(Chunk.NEWLINE);

                                this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);
                            } else {
                                this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);
                            }
                        }

                        // document.add(Chunk.NEWLINE);
                        document.add(table);
                        activityBlock = new Paragraph();
                        activityBlock.add(Chunk.NEWLINE);
                        document.add(activityBlock);
                        counter++;

                    }
                }

            }

            // Leason regardins
            activityBlock = new Paragraph();
            activityBlock.setAlignment(Element.ALIGN_JUSTIFIED);
            activityBlock.setFont(BODY_TEXT_BOLD_FONT);
            if (!project.isReporting()) {
                activityBlock.add(this.getText("summaries.project.activities.lessonsRegarding"));
            } else {
                activityBlock.add(this.getText("summaries.project.activities.reporting.lessonsRegarding"));
            }
            activityBlock.setFont(BODY_TEXT_FONT);

            if (project.getComponentLesson("activities") != null) {
                activityBlock.add(this.messageReturn(project.getComponentLesson("activities").getLessons()));
            } else {
                activityBlock.add(this.messageReturn(null));
            }
            document.add(activityBlock);

        }

    } catch (DocumentException e) {
        LOG.error(
                "There was an error trying to add the project activities to the project summary pdf of project {} ",
                e, project.getId());
    }

}