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:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java

License:Open Source License

@Override
public void visit(StyleParagraphPropertiesElement ele) {

    StyleParagraphProperties paragraphProperties = currentStyle.getParagraphProperties();
    if (paragraphProperties == null) {
        paragraphProperties = new StyleParagraphProperties();
        currentStyle.setParagraphProperties(paragraphProperties);
    }/*from   ww  w  .j a  va2  s.c  o  m*/

    // background-color
    String backgroundColor = ele.getFoBackgroundColorAttribute();
    if (StringUtils.isNotEmpty(backgroundColor)) {
        paragraphProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor));
    }

    // border
    String border = ele.getFoBorderAttribute();
    if (StringUtils.isNotEmpty(border)) {
        paragraphProperties.setBorder(new StyleBorder(border, BorderType.ALL));
    }
    // border-bottom
    String borderBottom = ele.getFoBorderBottomAttribute();
    if (StringUtils.isNotEmpty(borderBottom)) {
        paragraphProperties.setBorderBottom(new StyleBorder(borderBottom, BorderType.BOTTOM));
    }

    // border-left
    String borderLeft = ele.getFoBorderLeftAttribute();
    if (StringUtils.isNotEmpty(borderLeft)) {
        paragraphProperties.setBorderLeft(new StyleBorder(borderLeft, BorderType.LEFT));
    }

    // border-bottom
    String borderRight = ele.getFoBorderRightAttribute();
    if (StringUtils.isNotEmpty(borderRight)) {
        paragraphProperties.setBorderRight(new StyleBorder(borderRight, BorderType.RIGHT));
    }

    // border-top
    String borderTop = ele.getFoBorderTopAttribute();
    if (StringUtils.isNotEmpty(borderTop)) {
        paragraphProperties.setBorderTop(new StyleBorder(borderTop, BorderType.TOP));
    }

    // join-border
    Boolean joinBorder = ele.getStyleJoinBorderAttribute();
    if (joinBorder != null) {
        paragraphProperties.setJoinBorder(joinBorder);
    }

    // line-height
    String lineHeight = ele.getFoLineHeightAttribute();
    if (StringUtils.isNotEmpty(lineHeight)) {
        paragraphProperties.setLineHeight(new StyleLineHeight(ODFUtils.getDimensionAsPoint(lineHeight),
                ODFUtils.hasPercentUnit(lineHeight)));
    }

    // margin
    String margin = ele.getFoMarginAttribute();
    if (StringUtils.isNotEmpty(margin)) {
        paragraphProperties.setMargin(ODFUtils.getDimensionAsPoint(margin));
    }

    // margin-bottom
    String marginBottom = ele.getFoMarginBottomAttribute();
    if (StringUtils.isNotEmpty(marginBottom)) {
        paragraphProperties.setMarginBottom(ODFUtils.getDimensionAsPoint(marginBottom));
    }

    // margin-left
    String marginLeft = ele.getFoMarginLeftAttribute();
    if (StringUtils.isNotEmpty(marginLeft)) {
        paragraphProperties.setMarginLeft(ODFUtils.getDimensionAsPoint(marginLeft));
    }

    // margin-right
    String marginRight = ele.getFoMarginRightAttribute();
    if (StringUtils.isNotEmpty(marginRight)) {
        paragraphProperties.setMarginRight(ODFUtils.getDimensionAsPoint(marginRight));
    }

    // margin-top
    String marginTop = ele.getFoMarginTopAttribute();
    if (StringUtils.isNotEmpty(marginTop)) {
        paragraphProperties.setMarginTop(ODFUtils.getDimensionAsPoint(marginTop));
    }

    // padding
    String padding = ele.getFoPaddingAttribute();
    if (StringUtils.isNotEmpty(padding)) {
        paragraphProperties.setPadding(ODFUtils.getDimensionAsPoint(padding));
    }

    // padding-bottom
    String paddingBottom = ele.getFoPaddingBottomAttribute();
    if (StringUtils.isNotEmpty(paddingBottom)) {
        paragraphProperties.setPaddingBottom(ODFUtils.getDimensionAsPoint(paddingBottom));
    }

    // padding-left
    String paddingLeft = ele.getFoPaddingLeftAttribute();
    if (StringUtils.isNotEmpty(paddingLeft)) {
        paragraphProperties.setPaddingLeft(ODFUtils.getDimensionAsPoint(paddingLeft));
    }

    // padding-right
    String paddingRight = ele.getFoPaddingRightAttribute();
    if (StringUtils.isNotEmpty(paddingRight)) {
        paragraphProperties.setPaddingRight(ODFUtils.getDimensionAsPoint(paddingRight));
    }

    // padding-top
    String paddingTop = ele.getFoPaddingTopAttribute();
    if (StringUtils.isNotEmpty(paddingTop)) {
        paragraphProperties.setPaddingTop(ODFUtils.getDimensionAsPoint(paddingTop));
    }

    // text-align
    String textAlign = ele.getFoTextAlignAttribute();
    if (StringUtils.isNotEmpty(textAlign)) {
        int alignment = Element.ALIGN_UNDEFINED;
        if (FoTextAlignAttribute.Value.START.toString().equals(textAlign)) {
            alignment = Element.ALIGN_LEFT;
        } else if (FoTextAlignAttribute.Value.END.toString().equals(textAlign)) {
            alignment = Element.ALIGN_RIGHT;
        } else if (FoTextAlignAttribute.Value.LEFT.toString().equals(textAlign)) {
            alignment = Element.ALIGN_LEFT;
        } else if (FoTextAlignAttribute.Value.RIGHT.toString().equals(textAlign)) {
            alignment = Element.ALIGN_RIGHT;
        } else if (FoTextAlignAttribute.Value.CENTER.toString().equals(textAlign)) {
            alignment = Element.ALIGN_CENTER;
        } else if (FoTextAlignAttribute.Value.JUSTIFY.toString().equals(textAlign)) {
            alignment = Element.ALIGN_JUSTIFIED;
        }
        paragraphProperties.setAlignment(alignment);
    }

    // auto-text-indent
    Boolean autoTextIndent = ele.getStyleAutoTextIndentAttribute();
    if (autoTextIndent != null) {
        paragraphProperties.setAutoTextIndent(autoTextIndent);
    }

    // text-indent
    String textIndent = ele.getFoTextIndentAttribute();
    if (StringUtils.isNotEmpty(textIndent)) {
        paragraphProperties.setTextIndent(ODFUtils.getDimensionAsPoint(textIndent));
    }

    // keep-together
    String keepTogether = ele.getFoKeepTogetherAttribute();
    if (StringUtils.isNotEmpty(keepTogether)) {
        if (FoKeepTogetherAttribute.Value.ALWAYS.toString().equals(keepTogether)) {
            paragraphProperties.setKeepTogether(Boolean.TRUE);
        } else {
            paragraphProperties.setKeepTogether(Boolean.FALSE);
        }
    }

    // fo:break-before
    String breakBefore = ele.getFoBreakBeforeAttribute();
    if (StringUtils.isNotEmpty(breakBefore)) {
        if (FoBreakBeforeAttribute.Value.PAGE.toString().equals(breakBefore)) {
            paragraphProperties.setBreakBefore(StyleBreak.createWithPageBreak());
        } else if (FoBreakBeforeAttribute.Value.COLUMN.toString().equals(breakBefore)) {
            paragraphProperties.setBreakBefore(StyleBreak.createWithColumnBreak());
        } else {
            paragraphProperties.setBreakBefore(StyleBreak.createWithNoBreak());
        }
    }

    super.visit(ele);
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java

License:Open Source License

@Override
public void visit(StyleTabStopElement ele) {
    if (currentTabStopPropertiesList == null) {
        return;/*from  w  w  w.  j av a  2 s  .c o  m*/
    }
    StyleTabStopProperties tabStopProperties = new StyleTabStopProperties();
    currentTabStopPropertiesList.add(tabStopProperties);

    // leader-text
    String leaderText = ele.getStyleLeaderTextAttribute();
    if (StringUtils.isNotEmpty(leaderText)) {
        tabStopProperties.setLeaderText(leaderText);
    }

    // position
    String position = ele.getStylePositionAttribute();
    if (StringUtils.isNotEmpty(position)) {
        tabStopProperties.setPosition(ODFUtils.getDimensionAsPoint(position));
    }

    // type
    String type = ele.getStyleTypeAttribute();
    if (StringUtils.isNotEmpty(type)) {
        if (StyleTypeAttribute.Value.LEFT.toString().equals(type)) {
            tabStopProperties.setType(Element.ALIGN_LEFT);
        } else if (StyleTypeAttribute.Value.RIGHT.toString().equals(type)) {
            tabStopProperties.setType(Element.ALIGN_RIGHT);
        } else {
            tabStopProperties.setType(Element.ALIGN_CENTER);
        }
    }

    super.visit(ele);
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java

License:Open Source License

@Override
public void visit(StyleTablePropertiesElement ele) {

    StyleTableProperties tableProperties = new StyleTableProperties();
    currentStyle.setTableProperties(tableProperties);

    // background-color
    String backgroundColor = ele.getFoBackgroundColorAttribute();
    if (StringUtils.isNotEmpty(backgroundColor)) {
        tableProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor));

    }//  w w  w . java2 s.  c  o m

    // width
    String width = ele.getStyleWidthAttribute();
    if (StringUtils.isNotEmpty(width)) {
        tableProperties.setWidth(ODFUtils.getDimensionAsPoint(width));
    }

    // align
    String align = ele.getTableAlignAttribute();
    if (StringUtils.isNotEmpty(align)) {
        if (TableAlignAttribute.Value.LEFT.toString().equals(align)) {
            tableProperties.setAlignment(Element.ALIGN_LEFT);
        } else if (TableAlignAttribute.Value.RIGHT.toString().equals(align)) {
            tableProperties.setAlignment(Element.ALIGN_RIGHT);
        } else {
            tableProperties.setAlignment(Element.ALIGN_CENTER);
        }
    }

    // margin
    String margin = ele.getFoMarginAttribute();
    if (StringUtils.isNotEmpty(margin)) {
        tableProperties.setMargin(ODFUtils.getDimensionAsPoint(margin));
    }

    // margin-bottom
    String marginBottom = ele.getFoMarginBottomAttribute();
    if (StringUtils.isNotEmpty(marginBottom)) {
        tableProperties.setMarginBottom(ODFUtils.getDimensionAsPoint(marginBottom));
    }

    // margin-left
    String marginLeft = ele.getFoMarginLeftAttribute();
    if (StringUtils.isNotEmpty(marginLeft)) {
        tableProperties.setMarginLeft(ODFUtils.getDimensionAsPoint(marginLeft));
    }

    // margin-right
    String marginRight = ele.getFoMarginRightAttribute();
    if (StringUtils.isNotEmpty(marginRight)) {
        tableProperties.setMarginRight(ODFUtils.getDimensionAsPoint(marginRight));
    }

    // margin-top
    String marginTop = ele.getFoMarginTopAttribute();
    if (StringUtils.isNotEmpty(marginTop)) {
        tableProperties.setMarginTop(ODFUtils.getDimensionAsPoint(marginTop));
    }

    // may-break-between-rows
    Boolean mayBreakBetweenRows = ele.getStyleMayBreakBetweenRowsAttribute();
    if (mayBreakBetweenRows != null) {
        tableProperties.setMayBreakBetweenRows(mayBreakBetweenRows);
    }

    super.visit(ele);
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java

License:Open Source License

@Override
protected IITextContainer startVisitParagraph(CTP paragraph, ListItemContext itemContext,
        IITextContainer pdfParentContainer) throws Exception {
    // create PDF paragraph
    StylableParagraph pdfParagraph = pdfDocument.createParagraph(pdfParentContainer);

    CTTbl parentTable = super.getParentTable();
    // indentation left
    Float indentationLeft = stylesDocument.getIndentationLeft(paragraph, parentTable);
    if (indentationLeft != null) {
        pdfParagraph.setIndentationLeft(indentationLeft);
    }/* ww  w  .  j a v a  2  s. c  o m*/
    // indentation right
    Float indentationRight = stylesDocument.getIndentationRight(paragraph, parentTable);
    if (indentationRight != null) {
        pdfParagraph.setIndentationRight(indentationRight);
    }
    // indentation first line
    Float indentationFirstLine = stylesDocument.getIndentationFirstLine(paragraph, parentTable);
    if (indentationFirstLine != null) {
        pdfParagraph.setFirstLineIndent(indentationFirstLine);
    }
    // indentation hanging (remove first line)
    Float indentationHanging = stylesDocument.getIndentationHanging(paragraph, parentTable);
    if (indentationHanging != null) {
        pdfParagraph.setFirstLineIndent(-indentationHanging);
    }

    // // spacing before
    Float spacingBefore = stylesDocument.getSpacingBefore(paragraph, parentTable);
    if (spacingBefore != null) {
        pdfParagraph.setSpacingBefore(spacingBefore);
    }

    // spacing after
    // one more pargraph, spacing after should be applied.
    Float spacingAfter = stylesDocument.getSpacingAfter(paragraph, parentTable);
    if (spacingAfter != null) {
        pdfParagraph.setSpacingAfter(spacingAfter);
    }

    ParagraphLineSpacing lineSpacing = stylesDocument.getParagraphSpacing(paragraph, parentTable);
    if (lineSpacing != null) {
        if (lineSpacing.getLeading() != null && lineSpacing.getMultipleLeading() != null) {
            pdfParagraph.setLeading(lineSpacing.getLeading(), lineSpacing.getMultipleLeading());
        } else {
            if (lineSpacing.getLeading() != null) {
                pdfParagraph.setLeading(lineSpacing.getLeading());
            }
            if (lineSpacing.getMultipleLeading() != null) {
                pdfParagraph.setMultipliedLeading(lineSpacing.getMultipleLeading());
            }
        }

    }

    // text-align
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph, parentTable);
    if (alignment != null) {
        switch (alignment) {
        case LEFT:
            pdfParagraph.setAlignment(Element.ALIGN_LEFT);
            break;
        case RIGHT:
            pdfParagraph.setAlignment(Element.ALIGN_RIGHT);
            break;
        case CENTER:
            pdfParagraph.setAlignment(Element.ALIGN_CENTER);
            break;
        case BOTH:
            pdfParagraph.setAlignment(Element.ALIGN_JUSTIFIED);
            break;
        default:
            break;
        }
    }
    return pdfParagraph;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java

License:Open Source License

private StylableTable createPDFTable(CTTbl table, float[] colWidths, IITextContainer pdfParentContainer)
        throws DocumentException {
    // 2) Compute tableWith
    TableWidth tableWidth = stylesDocument.getTableWidth(table);
    StylableTable pdfPTable = pdfDocument.createTable(pdfParentContainer, colWidths.length);
    pdfPTable.setTotalWidth(colWidths);//from   ww  w.j a va2 s  .  c  o m
    if (tableWidth != null && tableWidth.width > 0) {
        if (tableWidth.percentUnit) {
            pdfPTable.setWidthPercentage(tableWidth.width);
        } else {
            pdfPTable.setTotalWidth(tableWidth.width);
        }
    }
    pdfPTable.setLockedWidth(true);

    // Table alignment
    ParagraphAlignment alignment = stylesDocument.getTableAlignment(table);
    if (alignment != null) {
        switch (alignment) {
        case LEFT:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_LEFT);
            break;
        case RIGHT:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_RIGHT);
            break;
        case CENTER:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_CENTER);
            break;
        case BOTH:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            break;
        default:
            break;
        }
    }

    // Table indentation
    Float indentation = stylesDocument.getTableIndentation(table);
    if (indentation != null) {
        pdfPTable.setPaddingLeft(indentation);
    }
    return pdfPTable;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java

License:Open Source License

@Override
protected IITextContainer startVisitParagraph(XWPFParagraph docxParagraph, ListItemContext itemContext,
        IITextContainer pdfParentContainer) throws Exception {
    this.currentRunX = null;

    // create PDF paragraph
    StylableParagraph pdfParagraph = pdfDocument.createParagraph(pdfParentContainer);

    // indentation left
    Float indentationLeft = stylesDocument.getIndentationLeft(docxParagraph);
    if (indentationLeft != null) {
        pdfParagraph.setIndentationLeft(indentationLeft);
    }//from www  .ja  va  2 s.com
    // indentation right
    Float indentationRight = stylesDocument.getIndentationRight(docxParagraph);
    if (indentationRight != null) {
        pdfParagraph.setIndentationRight(indentationRight);
    }
    // indentation first line
    Float indentationFirstLine = stylesDocument.getIndentationFirstLine(docxParagraph);
    if (indentationFirstLine != null) {
        pdfParagraph.setFirstLineIndent(indentationFirstLine);
    }
    // indentation hanging (remove first line)
    Float indentationHanging = stylesDocument.getIndentationHanging(docxParagraph);
    if (indentationHanging != null) {
        pdfParagraph.setFirstLineIndent(-indentationHanging);
    }

    // // spacing before
    Float spacingBefore = stylesDocument.getSpacingBefore(docxParagraph);
    if (spacingBefore != null) {
        pdfParagraph.setSpacingBefore(spacingBefore);
    }

    // spacing after
    Float spacingAfter = stylesDocument.getSpacingAfter(docxParagraph);
    if (spacingAfter != null) {
        pdfParagraph.setSpacingAfter(spacingAfter);
    }

    ParagraphLineSpacing lineSpacing = stylesDocument.getParagraphSpacing(docxParagraph);
    if (lineSpacing != null) {
        if (lineSpacing.getLeading() != null && lineSpacing.getMultipleLeading() != null) {
            pdfParagraph.setLeading(lineSpacing.getLeading(), lineSpacing.getMultipleLeading());
        } else {
            if (lineSpacing.getLeading() != null) {
                pdfParagraph.setLeading(lineSpacing.getLeading());
            }
            if (lineSpacing.getMultipleLeading() != null) {
                pdfParagraph.setMultipliedLeading(lineSpacing.getMultipleLeading());
            }
        }

    }

    // text-align
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(docxParagraph);
    if (alignment != null) {
        switch (alignment) {
        case LEFT:
            pdfParagraph.setAlignment(Element.ALIGN_LEFT);
            break;
        case RIGHT:
            pdfParagraph.setAlignment(Element.ALIGN_RIGHT);
            break;
        case CENTER:
            pdfParagraph.setAlignment(Element.ALIGN_CENTER);
            break;
        case BOTH:
            pdfParagraph.setAlignment(Element.ALIGN_JUSTIFIED);
            break;
        default:
            break;
        }
    }

    // background-color
    Color backgroundColor = stylesDocument.getBackgroundColor(docxParagraph);
    if (backgroundColor != null) {
        pdfParagraph.setBackgroundColor(Converter.toAwtColor(backgroundColor));
    }

    // border
    CTBorder borderTop = stylesDocument.getBorderTop(docxParagraph);
    pdfParagraph.setBorder(borderTop, Rectangle.TOP);

    CTBorder borderBottom = stylesDocument.getBorderBottom(docxParagraph);
    pdfParagraph.setBorder(borderBottom, Rectangle.BOTTOM);

    CTBorder borderLeft = stylesDocument.getBorderLeft(docxParagraph);
    pdfParagraph.setBorder(borderLeft, Rectangle.LEFT);

    CTBorder borderRight = stylesDocument.getBorderRight(docxParagraph);
    pdfParagraph.setBorder(borderRight, Rectangle.RIGHT);

    if (itemContext != null) {
        CTLvl lvl = itemContext.getLvl();
        CTPPr lvlPPr = lvl.getPPr();
        if (lvlPPr != null) {
            if (ParagraphIndentationLeftValueProvider.INSTANCE
                    .getValue(docxParagraph.getCTP().getPPr()) == null) {

                // search the indentation from the level properties only if
                // paragraph has not override it
                // see
                // https://code.google.com/p/xdocreport/issues/detail?id=239
                Float indLeft = ParagraphIndentationLeftValueProvider.INSTANCE.getValue(lvlPPr);
                if (indLeft != null) {
                    pdfParagraph.setIndentationLeft(indLeft);
                }
            }
            if (ParagraphIndentationHangingValueProvider.INSTANCE
                    .getValue(docxParagraph.getCTP().getPPr()) == null) {
                // search the hanging from the level properties only if
                // paragraph has not override it
                // see
                // https://code.google.com/p/xdocreport/issues/detail?id=239
                Float hanging = stylesDocument.getIndentationHanging(lvlPPr);
                if (hanging != null) {
                    pdfParagraph.setFirstLineIndent(-hanging);
                }
            }
        }
        CTRPr lvlRPr = lvl.getRPr();
        if (lvlRPr != null) {
            // Font family
            String listItemFontFamily = stylesDocument.getFontFamilyAscii(lvlRPr);

            // Get font size
            Float listItemFontSize = stylesDocument.getFontSize(lvlRPr);

            // Get font style
            int listItemFontStyle = Font.NORMAL;
            Boolean bold = stylesDocument.getFontStyleBold(lvlRPr);
            if (bold != null && bold) {
                listItemFontStyle |= Font.BOLD;
            }
            Boolean italic = stylesDocument.getFontStyleItalic(lvlRPr);
            if (italic != null && italic) {
                listItemFontStyle |= Font.ITALIC;
            }
            Boolean strike = stylesDocument.getFontStyleStrike(lvlRPr);
            if (strike != null && strike) {
                listItemFontStyle |= Font.STRIKETHRU;
            }

            // Font color
            Color listItemFontColor = stylesDocument.getFontColor(lvlRPr);

            pdfParagraph.setListItemFontFamily(listItemFontFamily);
            pdfParagraph.setListItemFontSize(listItemFontSize);
            pdfParagraph.setListItemFontStyle(listItemFontStyle);
            pdfParagraph.setListItemFontColor(Converter.toAwtColor(listItemFontColor));

        }
        pdfParagraph.setListItemText(itemContext.getText());
    }
    return pdfParagraph;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java

License:Open Source License

private StylableTable createPDFTable(XWPFTable table, float[] colWidths, IITextContainer pdfParentContainer)
        throws DocumentException {
    // 2) Compute tableWith
    TableWidth tableWidth = stylesDocument.getTableWidth(table);
    StylableTable pdfPTable = pdfDocument.createTable(pdfParentContainer, colWidths.length);
    pdfPTable.setTotalWidth(colWidths);//from w  ww.  j a  v a  2  s .c  om
    if (tableWidth != null && tableWidth.width > 0) {
        if (tableWidth.percentUnit) {
            pdfPTable.setWidthPercentage(tableWidth.width);
        } else {
            pdfPTable.setTotalWidth(tableWidth.width);
        }
    }
    pdfPTable.setLockedWidth(true);

    // Table alignment
    ParagraphAlignment alignment = stylesDocument.getTableAlignment(table);
    if (alignment != null) {
        switch (alignment) {
        case LEFT:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_LEFT);
            break;
        case RIGHT:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_RIGHT);
            break;
        case CENTER:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_CENTER);
            break;
        case BOTH:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            break;
        default:
            break;
        }
    }

    // Table indentation
    Float indentation = stylesDocument.getTableIndentation(table);
    if (indentation != null) {
        pdfPTable.setPaddingLeft(indentation);
    }
    return pdfPTable;
}

From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java

License:Open Source License

/**
 * method to create PDF//from   w  w w.ja  va 2 s .co  m
 * @param adminUser The admin user
 * @param locale The locale
 * @param strNameFile PDF name
 * @param out OutputStream
 * @param nIdRecord the id record
 * @param listIdEntryConfig list of config id entry
 * @param bExtractNotFilledField if true, extract empty fields, false
 */
public static void doCreateDocumentPDF(AdminUser adminUser, Locale locale, String strNameFile, OutputStream out,
        int nIdRecord, List<Integer> listIdEntryConfig, Boolean bExtractNotFilledField) {
    Document document = new Document(PageSize.A4);

    Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME);

    EntryFilter filter;

    Record record = RecordHome.findByPrimaryKey(nIdRecord, plugin);

    filter = new EntryFilter();
    filter.setIdDirectory(record.getDirectory().getIdDirectory());
    filter.setIsGroup(EntryFilter.FILTER_TRUE);

    List<IEntry> listEntry = DirectoryUtils.getFormEntries(record.getDirectory().getIdDirectory(), plugin,
            adminUser);
    int nIdDirectory = record.getDirectory().getIdDirectory();
    Directory directory = DirectoryHome.findByPrimaryKey(nIdDirectory, plugin);

    try {
        PdfWriter.getInstance(document, out);
    } catch (DocumentException e) {
        AppLogService.error(e);
    }

    document.open();

    if (record.getDateCreation() != null) {
        SimpleDateFormat monthDayYearformatter = new SimpleDateFormat(
                AppPropertiesService.getProperty(PROPERTY_POLICE_FORMAT_DATE));

        Font fontDate = new Font(
                DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)),
                DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_DATE)),
                DirectoryUtils
                        .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_DATE)));

        Paragraph paragraphDate = new Paragraph(
                new Phrase(monthDayYearformatter.format(record.getDateCreation()).toString(), fontDate));

        paragraphDate.setAlignment(DirectoryUtils
                .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_ALIGN_DATE)));

        try {
            document.add(paragraphDate);
        } catch (DocumentException e) {
            AppLogService.error(e);
        }
    }

    Image image;

    try {

        image = Image.getInstance(ImageIO.read(new File(AppPathService
                .getAbsolutePathFromRelativePath(AppPropertiesService.getProperty(PROPERTY_IMAGE_URL)))), null);
        image.setAlignment(
                DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_IMAGE_ALIGN)));
        float fitWidth;
        float fitHeight;

        try {
            fitWidth = Float.parseFloat(AppPropertiesService.getProperty(PROPERTY_IMAGE_FITWIDTH));
            fitHeight = Float.parseFloat(AppPropertiesService.getProperty(PROPERTY_IMAGE_FITHEIGHT));
        } catch (NumberFormatException e) {
            fitWidth = 100f;
            fitHeight = 100f;
        }

        image.scaleToFit(fitWidth, fitHeight);

        try {
            document.add(image);
        } catch (DocumentException e) {
            AppLogService.error(e);
        }
    } catch (BadElementException e) {
        AppLogService.error(e);
    } catch (MalformedURLException e) {
        AppLogService.error(e);
    } catch (IOException e) {
        AppLogService.error(e);
    }

    directory.getTitle();

    Font fontTitle = new Font(
            DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)),
            DirectoryUtils
                    .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_TITLE_DIRECTORY)),
            DirectoryUtils.convertStringToInt(
                    AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_TITLE_DIRECTORY)));
    fontTitle.isUnderlined();

    Paragraph paragraphHeader = new Paragraph(new Phrase(directory.getTitle(), fontTitle));
    paragraphHeader.setAlignment(Element.ALIGN_CENTER);
    paragraphHeader.setSpacingBefore(DirectoryUtils.convertStringToInt(
            AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_BEFORE_TITLE_DIRECTORY)));
    paragraphHeader.setSpacingAfter(DirectoryUtils.convertStringToInt(
            AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_AFTER_TITLE_DIRECTORY)));

    try {
        document.add(paragraphHeader);
    } catch (DocumentException e) {
        AppLogService.error(e);
    }

    builderPDFWithEntry(document, plugin, nIdRecord, listEntry, listIdEntryConfig, locale,
            bExtractNotFilledField);
    document.close();
}

From source file:fr.univlorraine.mondossierweb.controllers.InscriptionController.java

License:Apache License

/**
 * //from   w  w w .  ja va  2s  . co  m
 * @param document pdf
 */
public void creerPdfCertificatScolarite(final Document document, Etudiant etudiant, Inscription inscription) {

    //configuration des fonts
    Font normal = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    Font normalBig = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    Font header = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD);

    //date
    Date d = new Date();
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    String date = dateFormat.format(d);

    document.open();
    try {

        Signataire signataire = multipleApogeeService
                .getSignataire(configController.getCertScolCodeSignataire());

        // Ajout Bordeaux1
        if (configController.isCertScolUtiliseLogo()) {
            //ajout image test
            if (configController.getLogoUniversitePdf() != null
                    && !configController.getLogoUniversitePdf().equals("")) {
                Image imageLogo = Image.getInstance(configController.getLogoUniversitePdf());
                float scaleRatio = 40 / imageLogo.getHeight();
                float newWidth = scaleRatio * imageLogo.getWidth();
                imageLogo.scaleAbsolute(newWidth, 40);
                imageLogo.setAbsolutePosition(100, 750);
                document.add(imageLogo);
            } else if (configController.getCertScolHeaderUniv() != null
                    && !configController.getCertScolHeaderUniv().equals("")) {
                Image imageHeader = Image.getInstance(configController.getCertScolHeaderUniv());
                float scaleHeader = 600 / imageHeader.getWidth();
                float newHeigthHeader = scaleHeader * imageHeader.getHeight();
                imageHeader.scaleAbsolute(600, newHeigthHeader);
                imageHeader.setAbsolutePosition(0, 765);
                document.add(imageHeader);
            }

            if (configController.getCertScolFooter() != null
                    && !configController.getCertScolFooter().equals("")) {
                Image imageFooter = Image.getInstance(configController.getCertScolFooter());
                float scaleFooter = 600 / imageFooter.getWidth();
                float newHeigthFooter = scaleFooter * imageFooter.getHeight();
                imageFooter.scaleAbsolute(600, newHeigthFooter);
                imageFooter.setAbsolutePosition(0, 0);
                document.add(imageFooter);
            }
        }

        Paragraph pTitre = new Paragraph("\n\n" + applicationContext
                .getMessage("pdf.certificat.title", null, Locale.getDefault()).toUpperCase(), header);
        pTitre.setAlignment(Element.ALIGN_CENTER);
        document.add(pTitre);

        Paragraph pCertifie = new Paragraph("\n\n\n\n" + signataire.getQua_sig() + " "
                + applicationContext.getMessage("pdf.certificat.certifie", null, Locale.getDefault()) + "\n\n",
                normal);
        pCertifie.setAlignment(Element.ALIGN_LEFT);
        document.add(pCertifie);

        if (etudiant.getNom() != null) {
            String civ = multipleApogeeService.getCodCivFromCodInd(etudiant.getCod_ind());
            String civCertif = "";
            if (civ != null) {
                if (civ.equals("1")) {
                    civCertif = applicationContext.getMessage("pdf.certificat.civ1", null, Locale.getDefault());
                } else if (civ.equals("2")) {
                    civCertif = applicationContext.getMessage("pdf.certificat.civ2", null, Locale.getDefault());
                }
            }
            Paragraph pNom = new Paragraph(civCertif + " " + etudiant.getNom(), normalBig);
            pNom.setIndentationLeft(15);
            document.add(pNom);
        }
        if (etudiant.getCod_nne() != null) {
            Paragraph pNNE = new Paragraph(
                    "\n" + applicationContext.getMessage("pdf.certificat.id", null, Locale.getDefault()) + " : "
                            + etudiant.getCod_nne().toLowerCase(),
                    normal);
            pNNE.setAlignment(Element.ALIGN_LEFT);
            document.add(pNNE);
        }
        if (etudiant.getCod_etu() != null) {
            Paragraph p01 = new Paragraph(
                    applicationContext.getMessage("pdf.certificat.numetudiant", null, Locale.getDefault())
                            + " : " + etudiant.getCod_etu(),
                    normal);
            p01.setAlignment(Element.ALIGN_LEFT);
            document.add(p01);
        }
        if (etudiant.getDatenaissance() != null) {
            Paragraph pDateNaissance = new Paragraph(
                    applicationContext.getMessage("pdf.certificat.naissance1", null, Locale.getDefault()) + " "
                            + etudiant.getDatenaissance(),
                    normal);
            pDateNaissance.setAlignment(Element.ALIGN_LEFT);
            document.add(pDateNaissance);
        }
        if ((etudiant.getLieunaissance() != null) && (etudiant.getDepartementnaissance() != null)) {
            Paragraph pLieuNaissance = new Paragraph(
                    applicationContext.getMessage("pdf.certificat.naissance2", null, Locale.getDefault()) + " "
                            + etudiant.getLieunaissance() + " (" + etudiant.getDepartementnaissance() + ")",
                    normal);
            pLieuNaissance.setAlignment(Element.ALIGN_LEFT);
            document.add(pLieuNaissance);
        }

        String anneeEnCours = etudiantController.getAnneeUnivEnCoursToDisplay(MainUI.getCurrent());
        String inscritCertif = "";
        if (inscription.getCod_anu().equals(anneeEnCours)) {
            inscritCertif = applicationContext.getMessage("pdf.certificat.inscrit", null, Locale.getDefault());
        } else {
            inscritCertif = applicationContext.getMessage("pdf.certificat.ete.inscrit", null,
                    Locale.getDefault());
        }
        Paragraph pEstInscrit = new Paragraph("\n" + inscritCertif + " " + inscription.getCod_anu() + "\n ",
                normal);
        pEstInscrit.setAlignment(Element.ALIGN_LEFT);
        document.add(pEstInscrit);

        float[] widths = { 1.5f, 7.5f };
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100f);
        table.addCell(makeCell(applicationContext.getMessage("pdf.diplome", null, Locale.getDefault()) + " :",
                normal));
        table.addCell(makeCell(inscription.getLib_dip(), normal));
        table.addCell(
                makeCell(applicationContext.getMessage("pdf.year", null, Locale.getDefault()) + " :", normal));
        table.addCell(makeCell(inscription.getLib_etp(), normal));
        table.addCell(makeCell(
                applicationContext.getMessage("pdf.composante", null, Locale.getDefault()) + " :", normal));
        table.addCell(makeCell(inscription.getLib_comp(), normal));
        document.add(table);

        document.add(new Paragraph(" "));

        float[] widthsSignataire = { 2f, 1.3f };
        PdfPTable tableSignataire = new PdfPTable(widthsSignataire);
        tableSignataire.setWidthPercentage(100f);
        tableSignataire.addCell(makeCellSignataire("", normal));
        tableSignataire
                .addCell(makeCellSignataire(
                        applicationContext.getMessage("pdf.certificat.fait1", null, Locale.getDefault()) + " "
                                + configController.getCertScolLieuEdition() + applicationContext.getMessage(
                                        "pdf.certificat.fait2", null, Locale.getDefault())
                                + " " + date,
                        normal));
        tableSignataire.addCell(makeCellSignataire("", normal));
        tableSignataire.addCell(makeCellSignataire(signataire.getNom_sig(), normal));
        //ajout signature
        if (signataire.getImg_sig_std() != null && signataire.getImg_sig_std().length > 0) { //MODIF 09/10/2012
            tableSignataire.addCell(makeCellSignataire("", normal));
            LOG.debug(signataire.getImg_sig_std().toString());
            Image imageSignature = Image.getInstance(signataire.getImg_sig_std());

            float scaleRatio = 100 / imageSignature.getHeight();
            float newWidth = scaleRatio * imageSignature.getWidth();
            imageSignature.scaleAbsolute(newWidth, 100);
            imageSignature.setAbsolutePosition(350, 225);
            document.add(imageSignature);

        }

        document.add(tableSignataire);

        // Ajout tampon
        if (configController.getCertScolTampon() != null && !configController.getCertScolTampon().equals("")) {
            Image imageTampon = Image.getInstance(configController.getCertScolTampon());
            float scaleTampon = 100 / imageTampon.getWidth();
            float newHeigthTampon = scaleTampon * imageTampon.getHeight();
            imageTampon.scaleAbsolute(100, newHeigthTampon);
            imageTampon.setAbsolutePosition(415, 215);
            document.add(imageTampon);
        }

    } catch (BadElementException e) {
        LOG.error("Erreur  la gnration du certificat : BadElementException ", e);
    } catch (MalformedURLException e) {
        LOG.error("Erreur  la gnration du certificat : MalformedURLException ", e);
    } catch (IOException e) {
        LOG.error("Erreur  la gnration du certificat : IOException ", e);
    } catch (DocumentException e) {
        LOG.error("Erreur  la gnration du certificat : DocumentException ", e);
    }
    // step 6: fermeture du document.
    document.close();

}

From source file:fr.univlorraine.mondossierweb.controllers.InscriptionController.java

License:Apache License

private PdfPCell makeCellSignataire(String str, Font font) {
    PdfPCell cell = makeCell(str, font);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    return cell;
}