Example usage for com.itextpdf.text Section getDepth

List of usage examples for com.itextpdf.text Section getDepth

Introduction

In this page you can find the example usage for com.itextpdf.text Section getDepth.

Prototype

public int getDepth() 

Source Link

Document

Returns the depth of this section.

Usage

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * //w ww  . j  a  v  a 2s .  c  o m
 * Section  ?
 *
 * @param chapter section?  chapter ?
 * @param text section title
 * @param sectionNo section Number
 * @return Section
 */
public static Section getSection(Section chapter, String text) {
    Section section = chapter.addSection(text);
    String title = section.getTitle().getContent();

    Chunk c;
    if (section.getDepth() >= 3) {
        c = new Chunk(text, fnSection2);
    } else {
        c = new Chunk(text, fnSection);
    }
    c.setLocalDestination(title);

    Paragraph sectionPh = new Paragraph();
    sectionPh.add(c);
    sectionPh.setSpacingBefore(8);
    sectionPh.setSpacingAfter(3);
    if (section.getDepth() >= 3)
        sectionPh.setIndentationLeft(23);

    section.setTitle(sectionPh);
    return section;
}

From source file:com.vectorprint.report.itext.TocOutputStream.java

License:Open Source License

private void printToc(Document d, PdfWriter w, VectorPrintDocument vpd)
        throws VectorPrintException, InstantiationException, IllegalAccessException, DocumentException {
    DocumentStyler ds = outer.getStylerFactory().getDocumentStyler();
    if (ds.getValue(DocumentSettings.TOCAPPEND, Boolean.class)) {
        d.add(Chunk.NEXTPAGE);/*from   ww  w.ja v  a2  s. com*/
    }
    if (outer.isWasDebug()) {
        outer.getSettings().put(ReportConstants.DEBUG, Boolean.TRUE.toString());
        PdfContentByte canvas = w.getDirectContent();
        outer.startLayerInGroup(ReportConstants.DEBUG, canvas);
        BaseFont bf = DebugHelper.debugFont(canvas, outer.getSettings());
        canvas.showTextAligned(Element.ALIGN_RIGHT,
                "FOR DEBUG INFO IN THE DOCUMENT TURN OFF TOC (-DocumentSettings.toc=false)", d.right(),
                d.getPageSize().getHeight() - ItextHelper.getTextHeight("F", bf, 8), 0);
        canvas.endLayer();
    }
    ElementProducer ep = outer.getElementProducer();
    StylerFactory sf = outer.getStylerFactory();
    PdfPTable tocTable = ep.createElement(null, PdfPTable.class, sf.getStylers(DocumentSettings.TOCTABLEKEY));
    for (Map.Entry<Integer, List<Section>> e : vpd.getToc().entrySet()) {
        String link = null;
        for (Section s : e.getValue()) {
            if (ds.isParameterSet(DocumentSettings.TOCMAXDEPTH)
                    && ds.getValue(DocumentSettings.TOCMAXDEPTH, Integer.class) < s.getDepth()) {
                continue;
            }
            if (link == null) {
                link = s.getTitle().getContent();
            }
            Chunk c = ep.createElement(s.getTitle().getContent(), Chunk.class,
                    sf.getStylers(DocumentSettings.TOCTITLESTYLEKEY));
            if (ds.getValue(DocumentSettings.TOCDOTS, Boolean.class)) {
                float tw = ItextHelper.getTextWidth(c);
                float cw = tocTable.getAbsoluteWidths()[0];
                float dw = ItextHelper.getTextWidth(
                        ep.createElement(".", Chunk.class, sf.getStylers(DocumentSettings.TOCTITLESTYLEKEY)))
                        * 1.5f;
                int numDots = (int) ((cw > tw) ? (cw - tw) / dw : 0);
                char[] dots = new char[numDots];
                Arrays.fill(dots, '.');
                c = ep.createElement(s.getTitle().getContent() + "  " + String.valueOf(dots), Chunk.class,
                        sf.getStylers(DocumentSettings.TOCTITLESTYLEKEY));
            }
            c.setLocalGoto(link);
            tocTable.addCell(
                    ep.createElement(c, PdfPCell.class, sf.getStylers(DocumentSettings.TOCTITLESTYLEKEY)));
            c = ep.createElement(e.getKey(), Chunk.class, sf.getStylers(DocumentSettings.TOCNRSTYLEKEY));
            c.setLocalGoto(link);
            tocTable.addCell(
                    ep.createElement(c, PdfPCell.class, sf.getStylers(DocumentSettings.TOCNRSTYLEKEY)));
        }
    }
    d.add(tocTable);
}