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, float tabPosition) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:net.bull.javamelody.internal.web.pdf.PdfCounterRequestContextReport.java

License:Apache License

private void writeDurations(List<CounterRequestContext> contexts) throws DocumentException, IOException {
    getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

    final Paragraph paragraph = new Paragraph("", cellFont);
    boolean first = true;
    for (final CounterRequestContext context : contexts) {
        if (!first) {
            paragraph.add(new Chunk('\n', cellFont));
        }//from   ww w. ja v a 2 s.c o m
        final int duration = context.getDuration(timeOfSnapshot);
        final Counter parentCounter = context.getParentCounter();
        final PdfCounterReport counterReport = counterReportsByCounterName.get(parentCounter.getName());
        if (parentCounter.getIconName() != null) {
            paragraph.add(new Chunk(getImage(parentCounter.getIconName()), 0, -1));
        }
        final Font slaFont;
        if (counterReport == null) {
            slaFont = infoCellFont;
        } else {
            slaFont = counterReport.getSlaFont(duration);
        }
        paragraph.add(new Phrase(integerFormat.format(duration), slaFont));
        first = false;
    }
    addCell(paragraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfMBeansReport.java

License:Apache License

/**
 * Affiche l'arbre des MBeans./*from  ww w .j  av a2s. c o  m*/
 * @throws DocumentException e
 */
void writeTree() throws DocumentException {
    // MBeans pour la plateforme
    margin = 0;
    final MBeanNode platformNode = mbeans.get(0);
    writeTree(platformNode.getChildren());

    for (final MBeanNode node : mbeans) {
        if (node != platformNode) {
            newPage();
            addToDocument(new Chunk(node.getName(), boldFont));
            margin = 0;
            writeTree(node.getChildren());
        }
    }
}

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 va2 s .  co 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);
        }
    }
}

From source file:net.sf.eclipsecs.ui.stats.export.internal.RTFStatsExporter.java

License:Open Source License

private void createDetailSection(List details, Document doc) throws CoreException, DocumentException {
    Table table = new Table(4);
    table.setSpaceInsideCell(10);/*from  w w  w. j  a  v  a2 s .  c  o  m*/
    table.setAlignment(Element.ALIGN_LEFT);
    table.setWidth(100);
    table.setWidths(new float[] { 30, 30, 10, 30 });

    Cell resourceHeader = new Cell(new Chunk(Messages.MarkerStatsView_fileColumn, tableHeaderAndFooterFont));
    resourceHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    resourceHeader.setHeader(true);
    table.addCell(resourceHeader);
    Cell folderHeader = new Cell(new Chunk(Messages.MarkerStatsView_folderColumn, tableHeaderAndFooterFont));
    folderHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    folderHeader.setHeader(true);
    table.addCell(folderHeader);
    Cell lineHeader = new Cell(new Chunk(Messages.MarkerStatsView_lineColumn, tableHeaderAndFooterFont));
    lineHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    lineHeader.setHeader(true);
    table.addCell(lineHeader);
    Cell messageHeader = new Cell(new Chunk(Messages.MarkerStatsView_messageColumn, tableHeaderAndFooterFont));
    messageHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    messageHeader.setHeader(true);
    table.addCell(messageHeader);

    Cell resourceCell;
    Cell fileCell;
    Cell lineCell;
    Cell messageCell;
    for (Iterator iter = details.iterator(); iter.hasNext();) {
        IMarker marker = (IMarker) iter.next();
        resourceCell = new Cell(new Chunk(marker.getResource().getName(), mainFont));
        table.addCell(resourceCell);
        fileCell = new Cell(new Chunk(marker.getResource().getParent().getFullPath().toString(), mainFont));
        table.addCell(fileCell);
        lineCell = new Cell(new Chunk(marker.getAttribute(IMarker.LINE_NUMBER).toString(), mainFont));
        lineCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(lineCell);
        messageCell = new Cell(new Chunk(marker.getAttribute(IMarker.MESSAGE).toString(), mainFont));
        table.addCell(messageCell);
    }

    doc.add(table);
}

From source file:net.sf.eclipsecs.ui.stats.export.internal.RTFStatsExporter.java

License:Open Source License

private void createSummaryTable(Stats stats, Document doc) throws DocumentException {
    Table table = new Table(2);
    table.setSpaceInsideCell(10);//from   w w w.j  a v  a  2 s .  co  m
    table.setAlignment(Element.ALIGN_LEFT);
    table.setWidth(100);
    table.setWidths(new float[] { 80, 20 });

    Cell typeHeader = new Cell(new Chunk(Messages.MarkerStatsView_kindOfErrorColumn, tableHeaderAndFooterFont));
    typeHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    typeHeader.setHeader(true);
    table.addCell(typeHeader);
    Cell countHeader = new Cell(
            new Chunk(Messages.MarkerStatsView_numberOfErrorsColumn, tableHeaderAndFooterFont));
    countHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    countHeader.setHeader(true);
    table.addCell(countHeader);

    ArrayList markerStatsSortedList = new ArrayList(stats.getMarkerStats());
    Collections.sort(markerStatsSortedList, new Comparator() {
        public int compare(Object arg0, Object arg1) {
            MarkerStat markerStat0 = (MarkerStat) arg0;
            MarkerStat markerStat1 = (MarkerStat) arg1;
            return markerStat1.getCount() - markerStat0.getCount();
        }
    });
    Cell typeCell;
    Cell countCell;
    for (Iterator iter = markerStatsSortedList.iterator(); iter.hasNext();) {
        MarkerStat markerStat = (MarkerStat) iter.next();
        typeCell = new Cell(new Chunk(markerStat.getIdentifiant(), mainFont));
        table.addCell(typeCell);
        countCell = new Cell(new Chunk(markerStat.getCount() + "", mainFont));
        countCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(countCell);
    }

    doc.add(table);
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java

License:LGPL

/**
 *
 *//*ww  w .  j  a  v  a  2  s  . c  o  m*/
protected Chunk getChunk(Map attributes, String text) {
    Font font = getFont(attributes);

    Chunk chunk = new Chunk(text, font);

    Color backcolor = (Color) attributes.get(TextAttribute.BACKGROUND);
    if (backcolor != null) {
        chunk.setBackground(backcolor);
    }

    Object script = attributes.get(TextAttribute.SUPERSCRIPT);
    if (script != null) {
        if (TextAttribute.SUPERSCRIPT_SUPER.equals(script)) {
            chunk.setTextRise(font.leading(1f) / 2);
        } else if (script != null && TextAttribute.SUPERSCRIPT_SUB.equals(script)) {
            chunk.setTextRise(-font.leading(1f) / 2);
        }
    }

    if (splitCharacter != null) {
        chunk.setSplitCharacter(splitCharacter);
    }

    return chunk;
}

From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java

License:Apache License

public void onEndPage(final PdfWriter writer, final Document document) {
    final float bottom = document.bottom();
    final float centerX = getCenterX(document);
    final PdfContentByte canvas = writer.getDirectContent();
    final int rotation = 0;

    final PdfPTable table = new PdfPTable(5);
    table.setTotalWidth(PAGE_NUMBER_TABLE_WIDTH);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setBorder(0);

    table.addCell(TO_FIRST);/*from w  w w.  ja  va 2  s.c om*/
    table.addCell(TO_PREV);
    table.addCell(new Phrase(new Chunk("" + document.getPageNumber(), FONT)));
    table.addCell(TO_NEXT);
    table.addCell(TO_LAST);

    table.writeSelectedRows(0, -1, centerX - (table.getTotalWidth() / 2), bottom - FOOTER_POSITION, canvas);
    if (footerPhrase == null)
        return;
    showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase(footerPhrase), centerX, bottom - FOOTER_POSITION,
            rotation);
}

From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java

License:Apache License

public void setFooterText(final String value) {
    if (value == null) {
        footerPhrase = null;/* w w  w  .j  a v  a2  s  . co  m*/
        return;
    }
    footerPhrase = new Phrase(new Chunk(value, FONT));
}

From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java

License:Apache License

private static Phrase createPageAction(final String caption, final int action) {
    return new Phrase(new Chunk(caption, AFONT).setAction(new PdfAction(action)));
}

From source file:org.apache.poi.xwpf.converter.internal.itext.PDFMapper.java

License:Open Source License

@Override
protected void visitRun(XWPFRun run, IITextContainer pdfContainer) throws Exception {
    CTR ctr = run.getCTR();//from  ww w  . j a  va  2s.com
    // Get family name
    // Get CTRPr from style+defaults
    CTString rStyle = getRStyle(run);
    CTRPr runRprStyle = getRPr(super.getXWPFStyle(rStyle != null ? rStyle.getVal() : null));
    CTRPr rprStyle = getRPr(super.getXWPFStyle(run.getParagraph().getStyleID()));
    CTRPr rprDefault = getRPr(defaults);

    // Font family
    String fontFamily = getFontFamily(run, rprStyle, rprDefault);

    // Get font size
    float fontSize = run.getFontSize();

    // Get font style
    int fontStyle = Font.NORMAL;
    if (isBold(run, runRprStyle, rprStyle, rprDefault)) {
        fontStyle |= Font.BOLD;
    }
    if (isItalic(run, runRprStyle, rprStyle, rprDefault)) {
        fontStyle |= Font.ITALIC;
    }

    // Process color
    Color fontColor = null;
    String hexColor = getFontColor(run, runRprStyle, rprStyle, rprDefault);
    if (StringUtils.isNotEmpty(hexColor)) {
        if (hexColor != null && !"auto".equals(hexColor)) {
            fontColor = ColorRegistry.getInstance().getColor("0x" + hexColor);
        }
    }
    // Get font
    Font font = XWPFFontRegistry.getRegistry().getFont(fontFamily, options.getFontEncoding(), fontSize,
            fontStyle, fontColor);

    UnderlinePatterns underlinePatterns = run.getUnderline();

    boolean singleUnderlined = false;
    switch (underlinePatterns) {
    case SINGLE:
        singleUnderlined = true;
        break;

    default:
        break;
    }

    List<CTBr> brs = ctr.getBrList();
    for (@SuppressWarnings("unused")
    CTBr br : brs) {
        pdfContainer.addElement(Chunk.NEWLINE);
    }

    List<CTText> texts = run.getCTR().getTList();
    for (CTText ctText : texts) {

        Chunk aChunk = new Chunk(ctText.getStringValue(), font);
        if (singleUnderlined)
            aChunk.setUnderline(1, -2);

        pdfContainer.addElement(aChunk);
    }

    super.visitPictures(run, pdfContainer);

    // <w:lastRenderedPageBreak />
    List<CTEmpty> lastRenderedPageBreakList = ctr.getLastRenderedPageBreakList();
    if (lastRenderedPageBreakList != null && lastRenderedPageBreakList.size() > 0) {
        // IText Document#newPage must be called to generate page break.
        // But before that, CTSectPr must be getted to compute pageSize,
        // margins...
        // The CTSectPr <w:pPr><w:sectPr w:rsidR="00AA33F7"
        // w:rsidSect="00607077"><w:pgSz w:w="16838" w:h="11906"
        // w:orient="landscape" />...
        Stack<CTSectPr> sectPrStack = getSectPrStack();
        if (sectPrStack != null && !sectPrStack.isEmpty()) {
            CTSectPr sectPr = sectPrStack.pop();
            applySectPr(sectPr);
        }
        for (CTEmpty lastRenderedPageBreak : lastRenderedPageBreakList) {
            pdfDocument.newPage();
        }
    }
}