Example usage for com.lowagie.text Chunk Chunk

List of usage examples for com.lowagie.text Chunk Chunk

Introduction

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

Prototype

public Chunk(DrawInterface separator) 

Source Link

Document

Creates a separator Chunk.

Usage

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

License:Open Source License

public void applyStyles(Style style) {
    this.lastStyleApplied = style;

    Map<Integer, StyleListProperties> listPropertiesMap = style.getListPropertiesMap();
    if (listPropertiesMap != null) {
        StyleListProperties listProperties = getListProperties(listPropertiesMap, listLevel);
        if (listProperties != null) {
            String bulletChar = listProperties.getBulletChar();
            if (bulletChar != null) {
                // list item label is a char
                Chunk symbol = new Chunk(bulletChar);

                StyleTextProperties textProperties = listProperties.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }/*  w w  w  .  j av a2  s .  c o m*/
                }

                super.setListSymbol(symbol);
            }

            Image image = listProperties.getImage();
            if (image != null) {
                // list item label is an image
                Float width = listProperties.getWidth();
                if (width != null) {
                    image.scaleAbsoluteWidth(width);
                }

                Float height = listProperties.getHeight();
                if (height != null) {
                    image.scaleAbsoluteHeight(height);
                }

                super.setListSymbol(new Chunk(image, 0.0f, 0.0f));
            }

            if (bulletChar == null && image == null) {
                // list item label is a number
                Chunk symbol = new Chunk("");

                StyleTextProperties textProperties = listProperties.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                Integer startValue = listProperties.getStartValue();
                if (startValue != null) {
                    super.setFirst(startValue);
                }

                StyleNumFormat numFormat = listProperties.getNumFormat();
                if (numFormat != null) {
                    String numPrefix = listProperties.getNumPrefix();
                    if (numPrefix != null) {
                        super.setPreSymbol(numPrefix);
                        symbol = new Chunk(numPrefix, symbol.getFont());
                    }

                    String numSuffix = listProperties.getNumSuffix();
                    if (numSuffix != null) {
                        super.setPostSymbol(numSuffix);
                        symbol.append(numSuffix);
                    }

                    super.setNumbered(true);
                    super.setLettered(numFormat.isAlphabetical());
                    this.romanNumbered = numFormat.isRoman();
                    super.setLowercase(numFormat.isLowercase());
                }

                super.setListSymbol(symbol);
            }

            // set indentation, it is specified in different way by Open Office and MsWord
            Float marginLeft = listProperties.getMarginLeft();
            Float textIndent = listProperties.getTextIndent();
            Float spaceBefore = listProperties.getSpaceBefore();
            Float minLabelWidth = listProperties.getMinLabelWidth();
            if (marginLeft != null && textIndent != null) {
                // ODT generated by Open Office
                super.setIndentationLeft(Math.max(marginLeft + textIndent, 0.0f));
                super.setSymbolIndent(Math.max(-textIndent, 0.0f));
            } else if (spaceBefore != null && minLabelWidth != null) {
                // ODT generated by MsWord
                super.setIndentationLeft(Math.max(spaceBefore, 0.0f));
                super.setSymbolIndent(Math.max(minLabelWidth, 0.0f));
            }
        }
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
private void postProcessEmptyParagraph() {
    // add space if this paragraph is empty
    // otherwise its height will be zero
    boolean empty = true;
    ArrayList<Chunk> chunks = getChunks();
    for (Chunk chunk : chunks) {
        if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) {
            empty = false;/*from  ww w.j  a v a 2  s  .co  m*/
            break;
        }
    }
    if (empty) {
        super.add(new Chunk(ODFUtils.TAB_STR));
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
private void postProcessBookmarks() {
    // add space if last chunk is a bookmark
    // otherwise the bookmark will disappear from pdf
    ArrayList<Chunk> chunks = getChunks();
    if (chunks.size() > 0) {
        Chunk lastChunk = chunks.get(chunks.size() - 1);
        String localDestination = null;
        if (lastChunk.getAttributes() != null) {
            localDestination = (String) lastChunk.getAttributes().get(Chunk.LOCALDESTINATION);
        }//from   w  ww. jav  a2  s.c  o m
        if (localDestination != null) {
            super.add(new Chunk(ODFUtils.NON_BREAKING_SPACE_STR));
        }
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public Element getElement() {
    boolean empty = true;
    ArrayList<Chunk> chunks = getChunks();
    for (Chunk chunk : chunks) {
        if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) {
            empty = false;/*from  ww  w  .j av a2s  .c om*/
            break;
        }
    }
    if (empty) {
        super.add(new Chunk(ODFUtils.TAB_STR));
    }
    return this;
}

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

License:Open Source License

public Element getElement() {
    if (chunk == null) {
        if (inTableOfContent) {
            chunk = new Chunk(this);
        } else {/*from ww w .j  av a 2s.  c  o  m*/
            chunk = new Chunk(leaderText, font);
        }
    }
    return chunk;
}

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

License:Open Source License

@Override
protected void visitTabs(CTTabs tabs, IITextContainer pdfParagraphContainer) throws Exception {
    if (currentRunX == null) {
        Paragraph paragraph = null;/*from   w ww  .  j  a  va  2  s.c  o  m*/
        if (pdfParagraphContainer instanceof Paragraph) {
            paragraph = (Paragraph) pdfParagraphContainer;
        } else {
            paragraph = (Paragraph) ((StylableAnchor) pdfParagraphContainer).getITextContainer();
        }
        currentRunX = paragraph.getFirstLineIndent();
        List<Chunk> chunks = paragraph.getChunks();
        for (Chunk chunk : chunks) {
            currentRunX += chunk.getWidthPoint();
        }
    } else {
        if (currentRunX >= pdfDocument.getPageWidth()) {
            currentRunX = 0f;
        }
    }

    Float tabPosition = null;
    STTabTlc.Enum tabLeader = null;
    STTabJc.Enum tabVal = null;
    boolean useDefaultTabStop = false;
    if (tabs != null) {
        List<CTTabStop> tabList = tabs.getTabList();

        CTTabStop tabStop = getTabStop(tabList);
        if (tabStop != null) {

            float lastX = DxaUtil.dxa2points(tabStop.getPos().floatValue());
            if (lastX > currentRunX) {
                tabPosition = lastX;
                tabLeader = tabStop.getLeader();
                tabVal = tabStop.getVal();
            } else {
                useDefaultTabStop = true;
            }
        }
    }
    if (tabs == null || useDefaultTabStop) {
        // default tab
        float defaultTabStop = stylesDocument.getDefaultTabStop();
        float pageWidth = pdfDocument.getPageWidth();
        int nbInterval = (int) (pageWidth / defaultTabStop);
        Float lastX = getTabStopPosition(currentRunX, defaultTabStop, nbInterval);
        if (lastX != null) {
            tabPosition = lastX;
        }
    }

    if (tabPosition != null) {
        currentRunX = tabPosition;
        // tab leader : Specifies the character which shall be used to fill
        // in the space created by a tab
        // which
        // ends
        // at this custom tab stop. This character shall be repeated as
        // required to completely fill the
        // tab spacing generated by the tab character.
        VerticalPositionMark mark = createVerticalPositionMark(tabLeader);
        Chunk pdfTab = null;
        if (STTabJc.RIGHT.equals(tabVal)) {
            pdfTab = new Chunk(mark);
        } else {
            pdfTab = new Chunk(mark, currentRunX);
        }
        pdfParagraphContainer.addElement(pdfTab);
    }
}

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

License:Open Source License

@Override
protected void visitBookmark(CTBookmark bookmark, XWPFParagraph paragraph, IITextContainer paragraphContainer)
        throws Exception {
    // destination for a local anchor
    // chunk with empty text does not work as local anchor
    // so we create chunk with invisible but not empty text content
    // if bookmark is the last chunk in a paragraph something must be added
    // after or it does not work
    Chunk chunk = new Chunk(TAB);
    chunk.setLocalDestination(bookmark.getName());
    paragraphContainer.addElement(chunk);
}

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

License:Open Source License

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    try {/*from   w  w w  .j a  va  2  s . c om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("NestedTable.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(1);

        PdfPTable nestedTable = new PdfPTable(2);

        PdfPCell cell = new PdfPCell(nestedTable);

        PdfPCell cell1 = new PdfPCell();
        cell1.addElement(new Chunk("cell1"));
        nestedTable.addCell(cell1);

        PdfPCell cell2 = new PdfPCell();
        cell2.addElement(new Chunk("cell2"));
        nestedTable.addCell(cell2);

        table.addCell(cell);

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

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

License:Open Source License

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    try {// www.  j  av a 2s  . c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("NestedTable2.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(1);

        PdfPTable nestedTable = new PdfPTable(2);
        PdfPCell cell1 = new PdfPCell();
        cell1.addElement(new Chunk("cell1"));
        nestedTable.addCell(cell1);

        PdfPCell cell2 = new PdfPCell();
        cell2.addElement(new Chunk("cell2"));
        nestedTable.addCell(cell2);

        Paragraph paragraph = new Paragraph();
        paragraph.add(new Chunk("eeeeeeeeee"));
        paragraph.add(nestedTable);

        PdfPCell cell = new PdfPCell(paragraph);
        //cell.addElement( nestedTable );
        //cell.addElement( new Chunk("cell3") );
        //cell.
        table.addCell(cell);

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

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

License:Open Source License

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    try {//from  w  w w. java2  s . c  o  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TableWithAlignment.pdf"));

        document.open();

        PdfPTable table = new PdfPTable(2);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);

        table.setWidths(new float[] { 5, 10 });
        table.setWidthPercentage(10);

        PdfPCell cell1 = new PdfPCell();
        cell1.addElement(new Chunk("cell1"));
        table.addCell(cell1);

        PdfPCell cell2 = new PdfPCell();
        cell2.addElement(new Chunk("cell2"));
        table.addCell(cell2);

        table.setSpacingBefore(-100);

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}