Example usage for com.lowagie.text Chunk setLocalDestination

List of usage examples for com.lowagie.text Chunk setLocalDestination

Introduction

In this page you can find the example usage for com.lowagie.text Chunk setLocalDestination.

Prototype

public Chunk setLocalDestination(String name) 

Source Link

Document

Sets a local destination for this Chunk.

Usage

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java

License:Open Source License

@Override
protected void visitBookmark(CTBookmark bookmark, XWPFParagraph paragraph, IITextContainer paragraphContainer)
        throws Exception {
    // destination for a local anchor
    // chunk with empty text does not work as local anchor
    // so we create chunk with invisible but not empty text content
    // if bookmark is the last chunk in a paragraph something must be added
    // after or it does not work
    Chunk chunk = new Chunk(TAB);
    chunk.setLocalDestination(bookmark.getName());
    paragraphContainer.addElement(chunk);
}

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

License:LGPL

protected void writePageAnchor(int pageIndex) throws DocumentException {
    Map pdfFontAttrs = getDefaultPdfFontAttributes();
    Chunk chunk;
    if (pdfFontAttrs == null) {
        chunk = new Chunk(" ");
    } else {/*from www . jav  a  2s  .c o m*/
        Font pdfFont = getFont(pdfFontAttrs);
        chunk = new Chunk(" ", pdfFont);
    }

    chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1));

    ColumnText colText = new ColumnText(pdfContentByte);
    colText.setSimpleColumn(new Phrase(chunk), 0, jasperPrint.getPageHeight(), 1, 1, 0, Element.ALIGN_LEFT);

    colText.go();
}

From source file:org.areasy.common.doclet.Doclet.java

License:Open Source License

/**
 * Processes one Java package of the whole API.
 *
 * @param packageDoc The javadoc information for the package.
 * @throws Exception//from   w ww . j a va  2 s  . c o m
 */
private void printPackage(PackageDoc packageDoc, ClassDoc[] packageClasses) throws Exception {
    State.setCurrentPackage(packageDoc.name());
    State.setCurrentDoc(packageDoc);

    Document.newPage();

    String packageName = State.getCurrentPackage();

    // Text "package"
    State.setCurrentClass("");

    Paragraph label = new Paragraph((float) 22.0, LB_PACKAGE, Fonts.getFont(TEXT_FONT, BOLD, 18));
    Document.add(label);

    Paragraph titlePara = new Paragraph((float) 30.0, "");
    // Name of the package (large font)
    Chunk titleChunk = new Chunk(packageName, Fonts.getFont(TEXT_FONT, BOLD, 30));
    titleChunk.setLocalDestination(packageName);
    if (State.getCurrentFile() != null) {
        String packageAnchor = Destinations.createAnchorDestination(State.getCurrentFile(), null);
        titlePara.add(PDFUtility.createAnchor(packageAnchor, titleChunk.font()));
    }

    titlePara.add(titleChunk);
    Document.add(titlePara);

    // Some empty space
    Document.add(new Paragraph((float) 20.0, " "));

    State.setContinued(true);

    String packageText = DocletUtility.getComment(packageDoc);
    Element[] objs = HtmlParserWrapper.createPdfObjects(packageText);

    if (objs.length == 0) {
        String packageDesc = DocletUtility.stripLineFeeds(packageText);
        Document.add(new Paragraph((float) 11.0, packageDesc, Fonts.getFont(TEXT_FONT, 10)));
    } else
        PDFUtility.printPdfElements(objs);

    State.setContinued(false);

    State.increasePackageSection();

    printClasses(DocletUtility.sort(packageClasses), packageDoc);
}

From source file:org.areasy.common.doclet.document.Appendices.java

License:Open Source License

private static void printAppendix(AppendixInfo info, BookmarkEntry entry) throws Exception {

    File file = info.file;//from w  w w  .j a v  a 2 s  .c  o m
    State.setCurrentDoc(null);
    State.setCurrentPackage(null);
    State.setCurrentFile(file);
    State.increasePackageChapter();
    State.setCurrentHeaderType(HEADER_APPENDIX);
    State.setContinued(false);
    String label = DefaultConfiguration.getString(ARG_LB_APPENDIX, LB_APPENDIX);
    String fullTitle = label + " " + info.name;
    if (info.title != null)
        fullTitle += ": " + info.title;

    Document.newPage();
    State.setContinued(true);
    State.setCurrentClass(fullTitle);
    String appendixAnchor = Destinations.createAnchorDestination(file, null);
    Bookmarks.addSubBookmark(entry, fullTitle, appendixAnchor);

    if (file.getName().toLowerCase().endsWith(".pdf")) {
        Chunk anchorChunk = PDFUtility.createAnchor(appendixAnchor);
        Document.instance().add(anchorChunk);
        PDFUtility.insertPdfPages(file, info.pages);
    } else {
        String html = DocletUtility.getHTMLBodyContentFromFile(file);
        Chunk titleChunk = new Chunk(fullTitle, Fonts.getFont(TEXT_FONT, BOLD, 22));
        titleChunk.setLocalDestination(appendixAnchor);
        Paragraph titleParagraph = new Paragraph((float) 22.0, titleChunk);
        Document.add(titleParagraph);

        Element[] objs = HtmlParserWrapper.createPdfObjects(html);
        PDFUtility.printPdfElements(objs);
    }

    State.setContinued(false);
    State.setCurrentFile(null);
}

From source file:org.areasy.common.doclet.document.Index.java

License:Open Source License

/**
 * Creates a simple alphabetical index of all
 * classes and members of the API.//from w  w  w  .ja v a 2 s .  co m
 *
 * @throws Exception If the Index could not be created.
 */
public void create() throws Exception {
    if (!DefaultConfiguration.getBooleanConfigValue(ARG_CREATE_INDEX, false)) {
        log.trace("Index creation disabled.");
        return;
    }

    log.trace("Start creating Index...");

    State.setCurrentHeaderType(HEADER_INDEX);
    State.increasePackageChapter();

    // Name of the package (large font)
    pdfDocument.newPage();

    // Create "Index" bookmark
    String label = DefaultConfiguration.getString(ARG_LB_OUTLINE_INDEX, LB_INDEX);
    String dest = "INDEX:";
    Bookmarks.addRootBookmark(label, dest);
    Chunk indexChunk = new Chunk(label, Fonts.getFont(TEXT_FONT, BOLD, 30));
    indexChunk.setLocalDestination(dest);

    Paragraph indexParagraph = new Paragraph((float) 30.0, indexChunk);

    pdfDocument.add(indexParagraph);

    // we grab the ContentByte and do some stuff with it
    PdfContentByte cb = pdfWriter.getDirectContent();
    ColumnText ct = new ColumnText(cb);
    ct.setLeading((float) 9.0);

    float[] right = { 70, 320 };
    float[] left = { 300, 550 };

    // fill index columns with text
    String letter = "";
    Set keys = memberList.keySet();

    // keys must be sorted case unsensitive
    ArrayList sortedKeys = new ArrayList(keys.size());

    // Build sorted list of all entries
    Iterator keysIterator = keys.iterator();
    while (keysIterator.hasNext()) {
        sortedKeys.add(keysIterator.next());
    }
    Collections.sort(sortedKeys, this);

    Iterator realNames = sortedKeys.iterator();

    while (realNames.hasNext()) {
        String memberName = (String) realNames.next();
        String currentLetter = memberName.substring(0, 1).toUpperCase();
        log.trace("Create index entry for " + memberName);

        // Check if next letter in alphabet is reached
        if (currentLetter.equalsIgnoreCase(letter) == false) {
            // If yes, switch to new letter and print it
            letter = currentLetter.toUpperCase();
            Paragraph lphrase = new Paragraph((float) 13.0);
            lphrase.add(new Chunk("\n\n" + letter + "\n", Fonts.getFont(TEXT_FONT, 12)));
            ct.addText(lphrase);
        }

        // Print member name
        Paragraph phrase = new Paragraph((float) 10.0);
        phrase.add(new Chunk("\n" + memberName + "  ", Fonts.getFont(TEXT_FONT, 9)));

        Iterator sortedPages = getSortedPageNumbers(memberName);
        boolean firstNo = true;
        while (sortedPages.hasNext()) {
            Integer pageNo = (Integer) sortedPages.next();
            // Always add 1 to the stored value, because the pages were
            // counted beginning with 0 internally, but their visible
            // numbering starts with 1
            String pageNumberText = String.valueOf(pageNo.intValue() + 1);
            if (!firstNo) {
                phrase.add(new Chunk(", ", Fonts.getFont(TEXT_FONT, 9)));
            }
            phrase.add(new Chunk(pageNumberText, Fonts.getFont(TEXT_FONT, 9)));
            firstNo = false;
        }

        ct.addText(phrase);
    }

    // Now print index by printing columns into document
    int status = 0;
    int column = 0;

    while ((status & ColumnText.NO_MORE_TEXT) == 0) {
        ct.setSimpleColumn(right[column], 60, left[column], 790, 16, Element.ALIGN_LEFT);
        status = ct.go();

        if ((status & ColumnText.NO_MORE_COLUMN) != 0) {
            column++;

            if (column > 1) {
                pdfDocument.newPage();
                column = 0;
            }
        }
    }

    log.trace("Index created.");
}

From source file:org.areasy.common.doclet.utilities.PDFUtility.java

License:Open Source License

/**
 * Returns a Chunk that is an anchor destination for the given label.
 * The Chunk will be empty (have no text), so it can be placed anywhere.
 * The font size can make a difference in the PDF reader's behavior when
 * jumped to -- usually it will make sure to make the entire line height
 * visible./*from   w  w w.  j ava  2s  .c  om*/
 */
public static Chunk createAnchor(String destination, Font font) {
    final String EMPTY_TEXT = "\uFEFF";
    Chunk anchorChunk = new Chunk(EMPTY_TEXT, font);
    anchorChunk.setLocalDestination(destination);

    return anchorChunk;
}