Example usage for com.itextpdf.text Chunk setLocalGoto

List of usage examples for com.itextpdf.text Chunk setLocalGoto

Introduction

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

Prototype


public Chunk setLocalGoto(final String name) 

Source Link

Document

Sets a local goto for this Chunk.

Usage

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private void processMacro(String buf, BaseFont base, Map it, Paragraph p)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    List<String> list = LightUtil.splitMacro(buf, '$');
    for (String ss : list) {
        Chunk ch = null;
        if (ss.equals("${pageNumber}")) {
            PdfWriter writer = getWriter();
            if (writer != null)
                ss = writer.getPageNumber() + "";
            else//from  w  w w. j ava  2s . c o  m
                ss = ThreadHelper.get("pageNumber") + "";
        } else if (ss.equals("${pageCount}")) {
            ss = ThreadHelper.get("pageCount") + "";
        } else if (ss.equals("${newPage}")) {
            ch = Chunk.NEXTPAGE;
        } else if (ss.equals("${newLine}")) {
            ch = Chunk.NEWLINE;
        }
        if (ch == null)
            ch = new Chunk(ss, new Font(base));
        applyFont(ch, it);

        String gt = MapUtil.getStr(it, "goto", null);
        if (gt != null) {
            ch.setLocalGoto(gt);
        }

        p.add(ch);
    }
}

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. jav a 2 s.  c o 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

/**
 * Erzeugt das Inhaltsverzeichnis aus den bereits vorhandenen Elementen in
 * der Liste <code>listEntries</code>.
 * // w  w  w.  j a  v a 2s . com
 * @param docPdf
 *            Zieldokument, falls Inhaltsverzeichnis nicht temporr erzeugt
 *            wird
 * @param temp
 *            Gibt an, ob das Inhaltsverzeichnis temporr in einer neuen
 *            Datei/Dokument erzeugt werden soll
 * @return Anzahl der Seiten
 * @throws DocumentException
 * @throws IOException
 */
private int erzeugeInhaltsverzeichnis(Document docPdf, boolean temp) throws DocumentException, IOException {

    int anzPages = 0;
    Document docInhalt = docPdf;
    String filePathTempInhaltString = "";

    if (temp) {
        // temp. Dateinamen bestimmen
        File fileDokuFile = new File(dateiname);
        filePathTempInhaltString = fileDokuFile.getParent() + "/tmp_inhalt.pdf";
        // Neues Dokument erzeugen
        docInhalt = initPdfWriterAndDocument(filePathTempInhaltString, false);
    }

    // berschrift
    Chapter currChapter = new Chapter(getParagraphChapter("Inhaltsverzeichnis"), 0);
    // 0, damit keine Nummerierung
    currChapter.setNumberDepth(0);
    docInhalt.add(currChapter);
    // eine Zeile Abstand
    docInhalt.add(getEmptyLineTextHalf());

    for (ContPdfEntry currEntry : listEntries) {

        // Eintrag erzeugen inkl. Abstand
        String strEintrag = currEntry.getBezeichnung() + "  ";
        Chunk chunkBezeichnung;
        Chunk chunkSeitenzahlChunk;
        if (currEntry.getParentEntry() == null) {
            // 1. Ebene => fett, Abstand davor einfgen
            docInhalt.add(getEmptyLineTextHalf());
            chunkBezeichnung = getChunkTextBold(strEintrag);
            chunkSeitenzahlChunk = getChunkTextBold("" + currEntry.getPageNumber());
        } else {
            // 2. Ebene
            chunkBezeichnung = getChunkText(strEintrag);
            chunkSeitenzahlChunk = getChunkText("" + currEntry.getPageNumber());
        }
        // Referenz setzen
        chunkBezeichnung.setLocalGoto(currEntry.getDestination());
        chunkSeitenzahlChunk.setLocalGoto(currEntry.getDestination());
        // Abstandzeichen generieren, Breite auffllen
        float widthAbstand = docInhalt.getPageSize().getWidth() * 0.81f;
        ;
        while (chunkBezeichnung.getWidthPoint() <= widthAbstand) {
            chunkBezeichnung.append(".");
        }

        // Tabelle erzeugen und formatieren
        PdfPTable currTable = new PdfPTable(2);
        currTable.setWidthPercentage(100f);
        currTable.setWidths(new int[] { 96, 4 });

        // Inhalte einfgen
        // Zelle Bezeichnung
        PdfPCell currCellBezeichnung = new PdfPCell(new Phrase(chunkBezeichnung));
        currCellBezeichnung.setBorder(0);
        currCellBezeichnung.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);

        // Zelle Seitennummer
        PdfPCell currCellPageNumberCell = new PdfPCell(new Phrase(chunkSeitenzahlChunk));
        currCellPageNumberCell.setBorder(0);
        currCellPageNumberCell.setHorizontalAlignment(Element.ALIGN_RIGHT);

        // Zellen zur Tabelle hinzufgen
        currTable.addCell(currCellBezeichnung);
        currTable.addCell(currCellPageNumberCell);

        docInhalt.add(currTable);
    }

    if (temp) {
        // Dokument schlieen
        docInhalt.close();

        // Anzahl der Seitenzahlen bestimmen
        PdfReader reader = new PdfReader(filePathTempInhaltString);
        anzPages = reader.getNumberOfPages();
        reader.close();

        // temp. Datei lschen
        File currFileInhaltFile = new File(filePathTempInhaltString);
        currFileInhaltFile.delete();
    }
    return anzPages;
}

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

License:Apache License

private Chunk getChunkTextBoldWithReference(String text, String reference) {
    Chunk chunkText = new Chunk(text, FontFactory.getFont(fontNameStandard, fontSizeText, Font.BOLD));
    // Referenz setzen
    chunkText.setLocalGoto(reference);
    // Unterstreichen
    chunkText.setUnderline(new BaseColor(0x00, 0x0f, 0xFF), 0.5f, 0.0f, -4f, 0.0f,
            PdfContentByte.LINE_CAP_BUTT);
    return chunkText;
}

From source file:fr.ybonnel.breizhcamppdf.PdfRenderer.java

License:Apache License

private void remplirCellWithTalk(PdfPCell cell, Talk talk) throws DocumentException, IOException {
    Image image = AvatarService.INSTANCE.getImage(
            PdfRenderer.class.getResource("/formats/" + talk.getFormat().replaceAll(" ", "") + ".png"));

    float[] widths = { 0.15f, 0.85f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100f);//from ww w  .jav a 2  s . c om
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.addCell(image);
    PdfPCell subCell = new PdfPCell();
    Chunk chunk = new Chunk(talk.getTitle(), talkFont);
    chunk.setLocalGoto("talk" + talk.getId());
    Paragraph titleTalk = new Paragraph();
    titleTalk.add(chunk);
    titleTalk.setAlignment(Paragraph.ALIGN_CENTER);
    subCell.addElement(titleTalk);
    Paragraph track = new Paragraph(new Phrase(talk.getTrack(), themeFont));
    track.setAlignment(Paragraph.ALIGN_CENTER);

    subCell.addElement(track);
    TalkDetail detail = TalkService.INSTANCE.getTalkDetail(talk);
    if (detail != null) {
        for (Speaker speaker : detail.getSpeakers()) {
            Paragraph speakerText = new Paragraph(speaker.getFullname(), speakerFont);
            speakerText.setAlignment(Paragraph.ALIGN_CENTER);
            subCell.addElement(speakerText);
        }
    }
    subCell.setBorder(Rectangle.NO_BORDER);
    table.addCell(subCell);
    cell.setBackgroundColor(mapTrack.get(talk.getTrack()));
    cell.addElement(table);
}

From source file:fr.ybonnel.breizhcamppdf.RoomPdfRenderer.java

License:Apache License

private void remplirCellWithTalk(PdfPCell cell, Talk talk) throws DocumentException, IOException {
    Image image = AvatarService.INSTANCE.getImage(
            RoomPdfRenderer.class.getResource("/formats/" + talk.getFormat().replaceAll(" ", "") + ".png"));

    float[] widths = { 0.05f, 0.95f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100f);/*from   ww w  .j  av a2  s  . com*/
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.addCell(image);
    PdfPCell subCell = new PdfPCell();
    Chunk chunk = new Chunk(talk.getTitle(), talkFont);
    chunk.setLocalGoto("talk" + talk.getId());
    Paragraph titleTalk = new Paragraph();
    titleTalk.add(chunk);
    titleTalk.setAlignment(Paragraph.ALIGN_CENTER);
    subCell.addElement(titleTalk);
    Paragraph track = new Paragraph(new Phrase(talk.getTrack(), themeFont));
    track.setAlignment(Paragraph.ALIGN_CENTER);

    subCell.addElement(track);
    TalkDetail detail = TalkService.INSTANCE.getTalkDetail(talk);
    if (detail != null) {
        for (Speaker speaker : detail.getSpeakers()) {
            Paragraph speakerText = new Paragraph(speaker.getFullname(), speakerFont);
            speakerText.setAlignment(Paragraph.ALIGN_CENTER);
            subCell.addElement(speakerText);
        }
    }
    subCell.setBorder(Rectangle.NO_BORDER);
    table.addCell(subCell);
    cell.setBackgroundColor(mapTrack.get(talk.getTrack()));
    cell.addElement(table);
}