Example usage for com.lowagie.text Paragraph getSpacingBefore

List of usage examples for com.lowagie.text Paragraph getSpacingBefore

Introduction

In this page you can find the example usage for com.lowagie.text Paragraph getSpacingBefore.

Prototype

public float getSpacingBefore() 

Source Link

Document

Gets the spacing before this paragraph.

Usage

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

License:Open Source License

@Override
protected void visitPicture(CTPicture picture, Float offsetX,
        org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.STRelFromH.Enum relativeFromH,
        Float offsetY,// w w  w . j a  va 2  s . c o m
        org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.STRelFromV.Enum relativeFromV,
        STWrapText.Enum wrapText, IITextContainer pdfParentContainer) throws Exception {

    CTPositiveSize2D ext = picture.getSpPr().getXfrm().getExt();
    long x = ext.getCx();
    long y = ext.getCy();

    byte[] pictureData = super.getPictureBytes(picture);
    if (pictureData != null) {
        try {
            Image img = Image.getInstance(pictureData);
            img.scaleAbsolute(emu2points(x), emu2points(y));

            IITextContainer parentOfParentContainer = pdfParentContainer.getITextContainer();
            if (parentOfParentContainer != null && parentOfParentContainer instanceof PdfPCell) {
                parentOfParentContainer.addElement(img);
            } else {
                float chunkOffsetX = 0;
                if (offsetX != null) {
                    if (STRelFromH.CHARACTER.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.COLUMN.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.INSIDE_MARGIN.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.LEFT_MARGIN.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.MARGIN.equals(relativeFromH)) {
                        chunkOffsetX = pdfDocument.left() + offsetX;
                    } else if (STRelFromH.OUTSIDE_MARGIN.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.PAGE.equals(relativeFromH)) {
                        chunkOffsetX = offsetX - pdfDocument.left();
                    }
                }

                float chunkOffsetY = 0;
                boolean useExtendedImage = false;
                if (STRelFromV.PARAGRAPH.equals(relativeFromV)) {
                    useExtendedImage = true;
                }

                if (useExtendedImage) {
                    ExtendedImage extImg = new ExtendedImage(img, -offsetY);

                    if (STRelFromV.PARAGRAPH.equals(relativeFromV)) {
                        chunkOffsetY = -extImg.getScaledHeight();
                    }

                    Chunk chunk = new Chunk(extImg, chunkOffsetX, chunkOffsetY, false);
                    pdfParentContainer.addElement(chunk);
                }
                /*
                 * float chunkOffsetY = 0; if ( wrapText != null ) { chunkOffsetY = -img.getScaledHeight(); }
                 * boolean useExtendedImage = offsetY != null; // if ( STRelFromV.PARAGRAPH.equals( relativeFromV )
                 * ) // { // useExtendedImage = true; // } // if ( useExtendedImage ) { float imgY = -offsetY; if (
                 * pdfHeader != null ) { float headerY = pdfHeader.getY() != null ? pdfHeader.getY() : 0; imgY += -
                 * img.getScaledHeight() + headerY; } ExtendedImage extImg = new ExtendedImage( img, imgY ); // if (
                 * STRelFromV.PARAGRAPH.equals( relativeFromV ) ) // { // chunkOffsetY = -extImg.getScaledHeight();
                 * // } Chunk chunk = new Chunk( extImg, chunkOffsetX, chunkOffsetY, false );
                 * pdfParentContainer.addElement( chunk ); }
                 */
                else {
                    if (pdfParentContainer instanceof Paragraph) {
                        // I don't know why but we need add some spacing before in the paragraph
                        // otherwise the image cut the text of the below paragraph (see FormattingTests JUnit)?
                        Paragraph paragraph = (Paragraph) pdfParentContainer;
                        paragraph.setSpacingBefore(paragraph.getSpacingBefore() + 5f);
                    }
                    pdfParentContainer.addElement(new Chunk(img, chunkOffsetX, chunkOffsetY, false));
                }
            }

        } catch (Exception e) {
            LOGGER.severe(e.getMessage());
        }

    }
}

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

License:Open Source License

@Override
protected void visitPicture(CTPicture picture, Float offsetX,
        org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.STRelFromH.Enum relativeFromH,
        Float offsetY,/*from   w w w  .  j  a v  a2 s.c  o m*/
        org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.STRelFromV.Enum relativeFromV,
        STWrapText.Enum wrapText, IITextContainer pdfParentContainer) throws Exception {

    CTPositiveSize2D ext = picture.getSpPr().getXfrm().getExt();
    long x = ext.getCx();
    long y = ext.getCy();

    XWPFPictureData pictureData = super.getPictureData(picture);
    if (pictureData != null) {
        try {
            Image img = Image.getInstance(pictureData.getData());
            img.scaleAbsolute(emu2points(x), emu2points(y));

            IITextContainer parentOfParentContainer = pdfParentContainer.getITextContainer();
            if (parentOfParentContainer != null && parentOfParentContainer instanceof PdfPCell) {
                parentOfParentContainer.addElement(img);
            } else {
                float chunkOffsetX = 0;
                if (offsetX != null) {
                    if (STRelFromH.CHARACTER.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.COLUMN.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.INSIDE_MARGIN.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.LEFT_MARGIN.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.MARGIN.equals(relativeFromH)) {
                        chunkOffsetX = pdfDocument.left() + offsetX;
                    } else if (STRelFromH.OUTSIDE_MARGIN.equals(relativeFromH)) {
                        chunkOffsetX = offsetX;
                    } else if (STRelFromH.PAGE.equals(relativeFromH)) {
                        chunkOffsetX = offsetX - pdfDocument.left();
                    }
                }

                float chunkOffsetY = 0;
                boolean useExtendedImage = false;
                if (STRelFromV.PARAGRAPH.equals(relativeFromV)) {
                    useExtendedImage = true;
                }

                if (useExtendedImage) {
                    ExtendedImage extImg = new ExtendedImage(img, -offsetY);

                    if (STRelFromV.PARAGRAPH.equals(relativeFromV)) {
                        chunkOffsetY = -extImg.getScaledHeight();
                    }

                    Chunk chunk = new Chunk(extImg, chunkOffsetX, chunkOffsetY, false);
                    pdfParentContainer.addElement(chunk);
                }
                /*
                 * float chunkOffsetY = 0; if ( wrapText != null ) {
                 * chunkOffsetY = -img.getScaledHeight(); } boolean
                 * useExtendedImage = offsetY != null; // if (
                 * STRelFromV.PARAGRAPH.equals( relativeFromV ) ) // { //
                 * useExtendedImage = true; // } // if ( useExtendedImage )
                 * { float imgY = -offsetY; if ( pdfHeader != null ) { float
                 * headerY = pdfHeader.getY() != null ? pdfHeader.getY() :
                 * 0; imgY += - img.getScaledHeight() + headerY; }
                 * ExtendedImage extImg = new ExtendedImage( img, imgY ); //
                 * if ( STRelFromV.PARAGRAPH.equals( relativeFromV ) ) // {
                 * // chunkOffsetY = -extImg.getScaledHeight(); // } Chunk
                 * chunk = new Chunk( extImg, chunkOffsetX, chunkOffsetY,
                 * false ); pdfParentContainer.addElement( chunk ); }
                 */
                else {
                    if (pdfParentContainer instanceof Paragraph) {
                        // I don't know why but we need add some spacing
                        // before in the paragraph
                        // otherwise the image cut the text of the below
                        // paragraph (see FormattingTests JUnit)?
                        Paragraph paragraph = (Paragraph) pdfParentContainer;
                        paragraph.setSpacingBefore(paragraph.getSpacingBefore() + 5f);
                    }
                    pdfParentContainer.addElement(new Chunk(img, chunkOffsetX, chunkOffsetY, false));
                }
            }

        } catch (Exception e) {
            LOGGER.severe(e.getMessage());
        }

    }
}

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedParagraph.java

License:Open Source License

public void setSpacingBefore(Paragraph paragraph) {
    setSpacingBefore(paragraph.getSpacingBefore());
}