Example usage for com.lowagie.text Paragraph setExtraParagraphSpace

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

Introduction

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

Prototype

public void setExtraParagraphSpace(float extraParagraphSpace) 

Source Link

Document

Setter for property extraParagraphSpace.

Usage

From source file:net.scs.reader.virtualprinter.PdfPrinter.java

License:Open Source License

private void printCurrentPage() {
    // first create a new page
    pdfdoc.newPage();//from  w  w  w.  j  a v  a  2 s  .  c  o m
    pdfdoc.setPageCount(currentPage++);

    boolean emptypage = true;
    // second write the content
    for (VirtualLine currentLine : getLinesOnCurrentPage()) {
        emptypage = false;
        Paragraph p = new Paragraph();
        p.setSpacingAfter(0.0f);
        p.setSpacingBefore(0.0f);
        p.setExtraParagraphSpace(0.0f);
        p.setLeading(leading);
        currentLine.position(0);
        StringBuilder sb = new StringBuilder();
        boolean isbold = false;
        if (!currentLine.hasNext()) {
            // empty lines need at least one character
            sb.append(printerConfig.NL);
        }
        while (currentLine.hasNext()) {
            final EnhancedCharacter echar = currentLine.next();
            // Workaround, replace 'normal spaces' with 'non-breaking-spaces'
            // <a href="http://sourceforge.net/tracker/?func=detail&aid=2866002&group_id=15255&atid=315255">
            //     Multiline paragraph, leading spaces are ignored problem - ID: 2866002
            // </a>
            char c = (echar.getChar() == SP) ? NBSP : echar.getChar();
            if (isbold == echar.isBold()) {
                sb.append(c);
            } else {
                p.add(new Chunk(sb.toString(), (isbold) ? fontbold : font));
                sb = new StringBuilder();
                sb.append(c);
                isbold = !isbold; // flip it
            }
        }
        p.add(new Chunk(sb.toString(), (isbold) ? fontbold : font));
        try {
            pdfdoc.add(p);
        } catch (DocumentException e) {
            // transform into RuntimeException
            throw new RuntimeException(e);
        }
    }
    if (emptypage) {
        try {
            pdfdoc.add(new Paragraph(Character.toString(NBSP)));
        } catch (DocumentException e) {
            // transform into RuntimeException
            throw new RuntimeException(e);
        }
    }
}