Example usage for com.lowagie.text Element ALIGN_LEFT

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

Introduction

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

Prototype

int ALIGN_LEFT

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

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private PdfPCell buildBodyTextCell(String value, boolean even, boolean first, boolean last) {
    PdfPCell cell = new PdfPCell(new Phrase(value));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    if (even) {/*from   w ww  . ja v  a2s  .com*/
        cell.setGrayFill(0.8f);
    }
    setBorder(cell, first, last);
    // cell.setRotation(rotation);
    return cell;
}

From source file:de.tr1.cooperator.manager.web.CreateSubscriberListAction.java

License:Open Source License

/**
 * This method is called by the struts-framework if the submit-button is pressed.
 * It creates a PDF-File and puts in into the output-stream of the response.
 *///from   w  w w  .  ja v a 2 s.  c om
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    CreateSubscriberListForm myForm = (CreateSubscriberListForm) form;
    boolean bSortByName;

    if (myForm.getSortBy().equals(myForm.SORTBYPN))
        bSortByName = false;
    else
        bSortByName = true;

    //create Collection for the results...
    Event eEvent = EventManager.getInstance().getEventByID(myForm.getEventID());
    Collection cSubscriberList = UserManager.getInstance().getUsersByCollection(eEvent.getSubscriberList());
    Collection cExamResults = EventResultManager.getInstance().getResults(eEvent.getID());

    Iterator cSubscriberListIT = cSubscriberList.iterator();
    Collection cSubscriberResultList = new ArrayList();

    while (cSubscriberListIT.hasNext()) {
        User CurUser = (User) cSubscriberListIT.next();
        String UserPNR = CurUser.getPersonalNumber();

        Iterator cExamResultsIT = cExamResults.iterator();
        ExamResult curExamResult = null;
        String ResultUserPNR = null;
        while (cExamResultsIT.hasNext()) {
            curExamResult = (ExamResult) cExamResultsIT.next();

            ResultUserPNR = curExamResult.getUserPersonalNumber();
            if (UserPNR.equals(ResultUserPNR))
                break;
        }

        if (UserPNR.equals(ResultUserPNR)) {
            if (bSortByName) {
                UserResultSortByName URS = new UserResultSortByName(CurUser, "" + curExamResult.getResult());
                cSubscriberResultList.add(URS);
            } else {
                UserResultSortByPersonalNumber URS = new UserResultSortByPersonalNumber(CurUser,
                        "" + curExamResult.getResult());
                cSubscriberResultList.add(URS);
            }
        } else {
            if (bSortByName) {
                UserResultSortByName URS = new UserResultSortByName(CurUser, "-");
                cSubscriberResultList.add(URS);
            } else {
                UserResultSortByPersonalNumber URS = new UserResultSortByPersonalNumber(CurUser, "-");
                cSubscriberResultList.add(URS);
            }
        }

    }

    //sort List
    Collections.sort((List) cSubscriberResultList);

    BaseFont bf;
    //36pt = 0.5inch
    Document document = new Document(PageSize.A4, 36, 36, 72, 72);

    try {
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    } catch (Exception e) {
        Log.addLog("CreateSubscriberListAction: Error creating BaseFont: " + e);
        //2do: add ErrorMessage and return to inputFormular!
        return mapping.findForward("GeneralFailure");
    }

    //calculate the number of cols and their width
    int cols = 0;
    ArrayList alWidth = new ArrayList();
    float boldItalicFactor = 1.2f;
    if (myForm.getShowNumber())
        alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_NUMBER, TABLEHEADER_FONTSIZE)));

    if (myForm.getShowPersonalNumber())
        alWidth.add(new Float(
                boldItalicFactor * bf.getWidthPoint(TABLEHEADER_PERSONALNUMBER, TABLEHEADER_FONTSIZE)));

    if (myForm.getShowName())
        alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_NAME, TABLEHEADER_FONTSIZE)));

    if (myForm.getShowEmail())
        alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_EMAIL, TABLEHEADER_FONTSIZE)));

    if (myForm.getShowResult())
        alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_RESULT, TABLEHEADER_FONTSIZE)));

    if (myForm.getAddInfoField())
        alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_INFO, TABLEHEADER_FONTSIZE)));

    if (myForm.getAddSignField())
        alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_SIGN, TABLEHEADER_FONTSIZE)));

    cols = alWidth.size();

    float totalWidth = 0;
    //calculate the whole length
    Iterator alIterator = alWidth.iterator();
    for (; alIterator.hasNext(); totalWidth += ((Float) alIterator.next()).floatValue())
        ;

    //calculate relativ width for the table
    float[] width = new float[cols];
    alIterator = alWidth.iterator();
    int i = 0;
    while (alIterator.hasNext()) {
        float pixLength = ((Float) alIterator.next()).floatValue();
        //alWidthRelativ.add( new Float( pixLength/totalWidth ) );
        width[i] = pixLength / totalWidth;
        i++;
    }

    //needed for the shrink (enlarge?)
    float shrinkFactor;

    try {
        //1st: set correct outputstream
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());

        //1.5st: set content-stuff
        response.setContentType("application/pdf");

        //2nd: set EventManager for PageEvents to Helper
        writer.setPageEvent(
                new CreateSubscriberListActionHelper(myForm.getHeaderLeft(), myForm.getHeaderRight()));

        //3rd: open document for editing the content
        document.open();

        //4th: add content
        Phrase pInfoText = new Phrase(myForm.getInfoText(), new Font(bf, 12, Font.BOLD));
        document.add(pInfoText);

        //PdfPTable( cols )
        PdfPTable table = new PdfPTable(width);

        float documentWidth = document.right() - document.left();
        if (documentWidth < totalWidth) {
            table.setTotalWidth(documentWidth);
            shrinkFactor = documentWidth / totalWidth;
        } else {
            table.setTotalWidth(totalWidth);
            shrinkFactor = 1;
        }
        table.setLockedWidth(true);

        Font headerFont = new Font(bf, TABLEHEADER_FONTSIZE * shrinkFactor, Font.BOLDITALIC);
        Font cellFont = new Font(bf, TABLECELL_FONTSIZE * shrinkFactor, Font.NORMAL);

        if (myForm.getShowNumber())
            table.addCell(new Phrase(TABLEHEADER_NUMBER, headerFont));
        if (myForm.getShowPersonalNumber())
            table.addCell(new Phrase(TABLEHEADER_PERSONALNUMBER, headerFont));
        if (myForm.getShowName())
            table.addCell(new Phrase(TABLEHEADER_NAME, headerFont));
        if (myForm.getShowEmail())
            table.addCell(new Phrase(TABLEHEADER_EMAIL, headerFont));
        if (myForm.getShowResult())
            table.addCell(new Phrase(TABLEHEADER_RESULT, headerFont));
        if (myForm.getAddInfoField())
            table.addCell(new Phrase(TABLEHEADER_INFO, headerFont));
        if (myForm.getAddSignField())
            table.addCell(new Phrase(TABLEHEADER_SIGN, headerFont));

        //fill table
        Iterator iSRL = cSubscriberResultList.iterator();
        int counter = 1;
        while (iSRL.hasNext()) {
            UserResult curResult = (UserResult) iSRL.next();

            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (myForm.getShowNumber())
                table.addCell(new Phrase("" + counter++, cellFont));

            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            if (myForm.getShowPersonalNumber())
                table.addCell(new Phrase(curResult.getPersonalNumber(), cellFont));

            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            if (myForm.getShowName())
                table.addCell(new Phrase(curResult.getSurname() + ", " + curResult.getFirstName(), cellFont));
            if (myForm.getShowEmail())
                table.addCell(new Phrase(curResult.getEmailAddress(), cellFont));
            if (myForm.getShowResult())
                table.addCell(new Phrase(curResult.getResult(), cellFont));
            if (myForm.getAddInfoField())
                table.addCell(new Phrase("", cellFont));
            if (myForm.getAddSignField())
                table.addCell(new Phrase("", cellFont));
        }

        //set how many rows are header...
        table.setHeaderRows(1);

        document.add(table);

        //5th: close document, write the output to the stream...
        document.close();
    } catch (Exception de) {
        Log.addLog("CreateSubscriberListAction: Error creating PDF: " + de);
    }

    //we dont need to return a forward, because we write directly to the outputstream!
    return null;
}

From source file:de.xirp.report.ReportGenerator.java

License:Open Source License

/**
 * Adds a/*from ww w.j a v  a 2  s .c o  m*/
 * {@link de.xirp.report.data.ContentPartText text}
 * item to the PDF {@link com.lowagie.text.Document}.
 * 
 * @param item
 *            The item to add.
 * @throws DocumentException
 *             if something went wrong adding the page.
 * @see de.xirp.report.data.ContentPartText
 * @see com.lowagie.text.Document
 */
private static void addText(ContentPartText item) throws DocumentException {
    for (ContentPartTextParagraph cptp : item.getParagraphs()) {
        if (!cptp.getHeader().equals("")) { //$NON-NLS-1$
            para = getParagraph(cptp.getHeader(), PARA_HEADER, Element.ALIGN_LEFT);
            document.add(para);
        }
        para = getParagraph(cptp.getText(), TEXT, Element.ALIGN_JUSTIFIED);
        document.add(para);
        addSkip();
    }
}

From source file:desktopbugtracker.export.PdfAlign.java

License:Open Source License

public int toITextElement() {
    switch (this) {
    case CENTER://from   w w w  .  java  2 s .c o  m
        return Element.ALIGN_CENTER;
    default:
        return Element.ALIGN_LEFT;
    }
}

From source file:domain.reports.menu.PDFReportMenu.java

License:LGPL

/**
 * Return a report section formatted as a table
 * @param data//from www  .  j av  a2s. co m
 * @return
 */
PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable {

    //cols
    PdfPTable datatable = new PdfPTable(2);

    //header
    datatable.getDefaultCell().setPadding(1);
    int headerwidths[] = { 50, 50 }; // percentage
    datatable.setWidths(headerwidths);
    datatable.setWidthPercentage(70); // percentage
    datatable.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell c = null;
    String v = "";

    //encabezados de columnas
    c = new PdfPCell(new Phrase("ITEMS DEL MEN", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setColspan(2);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Item del men", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Servicio", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    while (detail.next()) {
        v = detail.getString("description");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(c);

        v = detail.getString("path");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(c);
    }

    datatable.setSpacingBefore(20);
    return datatable;

}

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

License:Open Source License

public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) {
    if (font.getBaseFont() != null && font.getSize() > 0.0 && leaderText.trim().length() > 0) {
        // create text to fit tab width
        float width = urx - llx;
        String txt = "";
        while (true) {
            Chunk tmp = new Chunk(txt + leaderText, font);
            if (tmp.getWidthPoint() <= width) {
                txt += leaderText;//from   w  ww  .j a va  2s.  c o m
            } else {
                break;
            }
        }
        // compute x offset - as if tab were right aligned
        float xoffset = width - new Chunk(txt, font).getWidthPoint();
        // compute y offset - use StylableParagraph mechanism
        Chunk tmp = StylableParagraph.createAdjustedChunk(txt, font, lineHeight, lineHeightProportional);
        float yoffset = tmp.getTextRise();
        // draw
        canvas.saveState();
        canvas.beginText();
        canvas.setFontAndSize(font.getBaseFont(), font.getSize());
        canvas.showTextAligned(Element.ALIGN_LEFT, txt, llx + xoffset, y + yoffset, 0.0f);
        canvas.endText();
        canvas.restoreState();
    }
}

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  .  jav  a 2s  . 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   ww  w .  j av  a2  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 ww  . j  av a  2 s  . c  om

    // 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);
    }/*from  w w  w  .j av  a  2  s .  c om*/
    // 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;
}