Example usage for com.itextpdf.text Section getTitle

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

Introduction

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

Prototype

public Paragraph getTitle() 

Source Link

Document

Returns the title, preceded by a certain number of sectionnumbers.

Usage

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

License:Apache License

/**
 * //from www .  java 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

@Override
public void secondPass(InputStream firstPass, OutputStream orig) throws IOException {
    PdfReader reader = null;/*from  ww w.j  a v  a  2 s .  c  om*/
    VectorPrintDocument vpd = (VectorPrintDocument) outer.getDocument();
    try {
        reader = new PdfReader(firstPass);
        prepareToc();
        // init fresh components for second pass styling
        StylerFactory _stylerFactory = outer.getStylerFactory().getClass().newInstance();
        StylerFactoryHelper.SETTINGS_ANNOTATION_PROCESSOR.initSettings(_stylerFactory, outer.getSettings());
        _stylerFactory.setLayerManager(outer.getElementProducer());
        _stylerFactory.setImageLoader(outer.getElementProducer());
        outer.getStyleHelper().setStylerFactory(_stylerFactory);
        EventHelper event = outer.getEventHelper().getClass().newInstance();
        event.setItextStylerFactory(_stylerFactory);
        event.setElementProvider(outer.getElementProducer());
        ((DefaultElementProducer) outer.getElementProducer()).setPh(event);
        Document d = new VectorPrintDocument(event, _stylerFactory, outer.getStyleHelper());
        PdfWriter w = PdfWriter.getInstance(d, orig);
        w.setPageEvent(event);
        outer.getStyleHelper().setVpd((VectorPrintDocument) d);
        _stylerFactory.setDocument(d, w);
        DocumentStyler ds = _stylerFactory.getDocumentStyler();
        outer.getStyleHelper().style(d, null, StyleHelper.toCollection(ds));
        d.open();
        ds.styleAfterOpen(d, null);
        List outline = SimpleBookmark.getBookmark(reader);
        if (!ds.getValue(DocumentSettings.TOCAPPEND, Boolean.class)) {
            printToc(d, w, vpd);
            if (outline != null) {
                int cur = w.getCurrentPageNumber();
                SimpleBookmark.shiftPageNumbers(outline, cur, null);
            }
            d.newPage();
        }
        outer.getSettings().put(ReportConstants.DEBUG, Boolean.FALSE.toString());
        for (int p = 1; p <= reader.getNumberOfPages(); p++) {
            Image page = Image.getInstance(w.getImportedPage(reader, p));
            page.setAbsolutePosition(0, 0);
            d.setPageSize(page);
            d.newPage();
            Chunk i = new Chunk(" ");
            if (vpd.getToc().containsKey(p)) {
                Section s = null;
                for (Map.Entry<Integer, List<Section>> e : vpd.getToc().entrySet()) {
                    if (e.getKey() == p) {
                        s = e.getValue().get(0);
                        break;
                    }
                }
                i.setLocalDestination(s.getTitle().getContent());
            }
            d.add(i);
            w.getDirectContent().addImage(page);
            w.freeReader(reader);
        }
        if (_stylerFactory.getDocumentStyler().getValue(DocumentSettings.TOCAPPEND, Boolean.class)) {
            printToc(d, w, vpd);
        }
        w.setOutlines(outline);
        if (outer.isWasDebug()) {
            event.setLastPage(outer.getWriter().getCurrentPageNumber());
            d.setPageSize(new Rectangle(ItextHelper.mmToPts(297), ItextHelper.mmToPts(210)));
            d.setMargins(5, 5, 5, 5);
            d.newPage();
            outer.getSettings().put(ReportConstants.DEBUG, Boolean.TRUE.toString());
            event.setDebugHereAfter(true);
            DebugHelper.appendDebugInfo(w, d, outer.getSettings(), _stylerFactory);
        }
        d.close();
    } catch (VectorPrintException | DocumentException | InstantiationException | IllegalAccessException ex) {
        throw new VectorPrintRuntimeException(ex);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

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.j  av a 2s  .co m
    }
    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);
}

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

/**
 * Das Element wird mit Datentyp, seinen Attributen und Kindelementen
 * geschrieben.//  www.j a v a 2s  .  com
 * 
 * @param currElement
 *            Zu behandelndes Element
 * @param currChapter
 *            Kapitel, zu dem das Element hinzugefgt wird
 * @param chapterEntry
 *            Eintrag des Kapitels fr das Inhaltsverzeichnis
 * @param schemaQueues
 *            Queues mit allen Elementen fr die einzelnen Schemas
 */
private void behandleElement(XSElementDecl currElement, Chapter currChapter, ContPdfEntry chapterEntry,
        Map<String, Queue<XSElementDecl>> schemaQueues) throws DocumentException {
    // Fr jedes Element eine Section; Titel ist der Elementname

    // eine Zeile Abstand
    docPdf.add(getEmptyLineText());

    // Referenz des Elements
    String currReferenzString = getReferenceForElement(currElement);

    // Titel des Elements inkl. Sprungmarke
    Chunk chunkElem = getChunkElement(currElement.getName());
    chunkElem.setLocalDestination(currReferenzString);

    Paragraph currElemPara = new Paragraph(getChunkElement(""));
    currElemPara.add(chunkElem);
    Section currSection = currChapter.addSection(currElemPara);

    // Eintrag fr Inhaltsverzeichnis (Element)
    listEntries.add(new ContPdfEntry(chapterEntry, currSection.getTitle().getContent(), currReferenzString,
            currPageNumber));

    // Sektion dem Dokument (vorlufig) hinzufgen (wichtig fr das
    // Aktualisieren der Seitenzahl)
    currSection.setComplete(false);
    docPdf.add(currSection);

    // Anmerkung zum Element
    XSAnnotation ann = currElement.getAnnotation();
    if (ann != null) {
        // Abstand
        currSection.add(getEmptyLineTextHalf());

        String beschreibung = ann.getAnnotation().toString();
        currSection.add(getParagraphTextItalic(beschreibung));
    }

    // Abstand
    currSection.add(getEmptyLineTextHalf());

    // Datentyp
    Paragraph paraTyp = new Paragraph();
    XSType currType = currElement.getType();
    paraTyp.add(getPhraseTextBold("Datentyp: "));
    String strTyp = getNameWithPrefix(currType);
    if (currType.isLocal()) {
        strTyp = "<lokal definiert>";
    }
    paraTyp.add(getPhraseText(strTyp + "\n"));

    // Basistyp
    if ((currType.getDerivationMethod() == XSType.RESTRICTION)
            || (currType.getDerivationMethod() == XSType.EXTENSION)) {
        paraTyp.add(getPhraseTextBold("basiert auf: "));
        paraTyp.add(getPhraseText(getNameWithPrefix(currType.getBaseType()) + "\n"));
    }
    currSection.add(paraTyp);

    // Attribute (falls vorhanden)
    behandleAttribute(currType, currSection);

    // Kind-Elemente (falls vorhanden)
    if (currType.isComplexType()) {
        // Gruppentyp (sequence oder choice)
        String strCompositor = getCompositorStr(currType.asComplexType());
        if (strCompositor.length() > 0) {
            // Abstand
            currSection.add(getEmptyLineTextHalf());

            currSection.add(getParagraphTextBold(strCompositor + "-Elemente:"));
            behandleKindElemente(currElement, currSection, schemaQueues);
        }
    }

    // Sektion dem Dokument (endgltig) hinzufgen
    currSection.setComplete(true);
    docPdf.add(currSection);
}