Example usage for com.lowagie.text Chunk setLocalGoto

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

Introduction

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

Prototype


public Chunk setLocalGoto(String name) 

Source Link

Document

Sets a local goto for this Chunk.

Usage

From source file:com.develog.utils.report.engine.export.JRPdfExporter.java

License:Open Source License

/**
 *
 *//*from ww  w .  ja va 2 s.co  m*/
protected void exportImage(JRPrintImage printImage) throws DocumentException, IOException {
    pdfContentByte.setRGBColorFill(printImage.getBackcolor().getRed(), printImage.getBackcolor().getGreen(),
            printImage.getBackcolor().getBlue());

    int borderOffset = 0;
    float borderCorrection = 0f;
    float lineWidth = 1f;
    boolean isLineDotted = false;

    switch (printImage.getPen()) {
    case JRGraphicElement.PEN_DOTTED: {
        borderOffset = 0;
        borderCorrection = 0f;
        lineWidth = 1f;
        isLineDotted = true;
        break;
    }
    case JRGraphicElement.PEN_4_POINT: {
        borderOffset = 2;
        borderCorrection = 0f;
        lineWidth = 4f;
        isLineDotted = false;
        break;
    }
    case JRGraphicElement.PEN_2_POINT: {
        borderOffset = 1;
        borderCorrection = 0f;
        lineWidth = 2f;
        isLineDotted = false;
        break;
    }
    case JRGraphicElement.PEN_THIN: {
        borderOffset = 0;
        borderCorrection = 0.25f;
        lineWidth = 0.5f;
        isLineDotted = false;
        break;
    }
    case JRGraphicElement.PEN_NONE: {
        borderOffset = 0;
        borderCorrection = 0.5f;
        lineWidth = 1f;
        isLineDotted = false;

        break;
    }
    case JRGraphicElement.PEN_1_POINT:
    default: {
        borderOffset = 0;
        borderCorrection = 0f;
        lineWidth = 1f;
        isLineDotted = false;
        break;
    }
    }

    if (printImage.getMode() == JRElement.MODE_OPAQUE) {
        pdfContentByte.setRGBColorStroke(printImage.getBackcolor().getRed(),
                printImage.getBackcolor().getGreen(), printImage.getBackcolor().getBlue());
        pdfContentByte.setLineWidth(0.1f);
        pdfContentByte.setLineDash(0f);
        pdfContentByte.rectangle(printImage.getX() - borderCorrection,
                jasperPrint.getPageHeight() - printImage.getY() + borderCorrection,
                printImage.getWidth() + 2 * borderCorrection - 1,
                -printImage.getHeight() - 2 * borderCorrection + 1);
        pdfContentByte.fillStroke();
    }

    int availableImageWidth = printImage.getWidth() - 2 * borderOffset;
    availableImageWidth = (availableImageWidth < 0) ? 0 : availableImageWidth;

    int availableImageHeight = printImage.getHeight() - 2 * borderOffset;
    availableImageHeight = (availableImageHeight < 0) ? 0 : availableImageHeight;

    int xoffset = 0;
    int yoffset = 0;

    if (printImage.getImageData() != null && availableImageWidth > 0 && availableImageHeight > 0) {
        //java.awt.Image awtImage = JRImageLoader.loadImage(printImage.getImageData());

        //com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor());
        //com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(awtImage, null);
        com.lowagie.text.Image image = null;

        float xalignFactor = 0f;
        switch (printImage.getHorizontalAlignment()) {
        case JRAlignment.HORIZONTAL_ALIGN_RIGHT: {
            xalignFactor = 1f;
            break;
        }
        case JRAlignment.HORIZONTAL_ALIGN_CENTER: {
            xalignFactor = 0.5f;
            break;
        }
        case JRAlignment.HORIZONTAL_ALIGN_LEFT:
        default: {
            xalignFactor = 0f;
            break;
        }
        }

        float yalignFactor = 0f;
        switch (printImage.getVerticalAlignment()) {
        case JRAlignment.VERTICAL_ALIGN_BOTTOM: {
            yalignFactor = 1f;
            break;
        }
        case JRAlignment.VERTICAL_ALIGN_MIDDLE: {
            yalignFactor = 0.5f;
            break;
        }
        case JRAlignment.VERTICAL_ALIGN_TOP:
        default: {
            yalignFactor = 0f;
            break;
        }
        }

        switch (printImage.getScaleImage()) {
        case JRImage.SCALE_IMAGE_CLIP: {
            java.awt.Image awtImage = JRImageLoader.loadImage(printImage.getImageData());
            //image = com.lowagie.text.Image.getInstance(awtImage, null);

            int awtWidth = awtImage.getWidth(null);
            int awtHeight = awtImage.getHeight(null);

            xoffset = (int) (xalignFactor * (availableImageWidth - awtWidth));
            yoffset = (int) (yalignFactor * (availableImageHeight - awtHeight));

            int minWidth = Math.min(awtWidth, availableImageWidth);
            int minHeight = Math.min(awtHeight, availableImageHeight);

            BufferedImage bi = new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_RGB);

            Graphics g = bi.getGraphics();
            g.setColor(printImage.getBackcolor());
            g.fillRect(0, 0, minWidth, minHeight);
            g.drawImage(awtImage, (xoffset > 0 ? 0 : xoffset), (yoffset > 0 ? 0 : yoffset), null);

            xoffset = (xoffset < 0 ? 0 : xoffset);
            yoffset = (yoffset < 0 ? 0 : yoffset);

            //awtImage = bi.getSubimage(0, 0, minWidth, minHeight);
            awtImage = bi;

            //image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor());
            image = com.lowagie.text.Image.getInstance(awtImage, null);

            break;
        }
        case JRImage.SCALE_IMAGE_FILL_FRAME: {
            try {
                image = com.lowagie.text.Image.getInstance(printImage.getImageData());
                imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
            } catch (Exception e) {
                java.awt.Image awtImage = JRImageLoader.loadImage(printImage.getImageData());
                image = com.lowagie.text.Image.getInstance(awtImage, null);
            }
            image.scaleAbsolute(availableImageWidth, availableImageHeight);
            break;
        }
        case JRImage.SCALE_IMAGE_RETAIN_SHAPE:
        default: {
            try {
                image = com.lowagie.text.Image.getInstance(printImage.getImageData());
                imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
            } catch (Exception e) {
                java.awt.Image awtImage = JRImageLoader.loadImage(printImage.getImageData());
                image = com.lowagie.text.Image.getInstance(awtImage, null);
            }
            image.scaleToFit(availableImageWidth, availableImageHeight);

            xoffset = (int) (xalignFactor * (availableImageWidth - image.plainWidth()));
            yoffset = (int) (yalignFactor * (availableImageHeight - image.plainHeight()));

            xoffset = (xoffset < 0 ? 0 : xoffset);
            yoffset = (yoffset < 0 ? 0 : yoffset);

            break;
        }
        }

        /*
        image.setAbsolutePosition(
           printImage.getX() + borderOffset,
           jasperPrint.getPageHeight() - printImage.getY() - image.scaledHeight() - borderOffset
           );
                
        pdfContentByte.addImage(image);
        */

        Chunk chunk = new Chunk(image, -0.5f, 0.5f);

        if (printImage.getAnchorName() != null) {
            chunk.setLocalDestination(printImage.getAnchorName());
        }

        switch (printImage.getHyperlinkType()) {
        case JRHyperlink.HYPERLINK_TYPE_REFERENCE: {
            if (printImage.getHyperlinkReference() != null) {
                chunk.setAnchor(printImage.getHyperlinkReference());
            }
            break;
        }
        case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: {
            if (printImage.getHyperlinkAnchor() != null) {
                chunk.setLocalGoto(printImage.getHyperlinkAnchor());
            }
            break;
        }
        case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: {
            if (printImage.getHyperlinkPage() != null) {
                chunk.setLocalGoto("JR_PAGE_ANCHOR_" + printImage.getHyperlinkPage().toString());
            }
            break;
        }
        case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: {
            if (printImage.getHyperlinkReference() != null && printImage.getHyperlinkAnchor() != null) {
                chunk.setRemoteGoto(printImage.getHyperlinkReference(), printImage.getHyperlinkAnchor());
            }
            break;
        }
        case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: {
            if (printImage.getHyperlinkReference() != null && printImage.getHyperlinkPage() != null) {
                chunk.setRemoteGoto(printImage.getHyperlinkReference(),
                        printImage.getHyperlinkPage().intValue());
            }
            break;
        }
        case JRHyperlink.HYPERLINK_TYPE_NONE:
        default: {
            break;
        }
        }

        ColumnText colText = new ColumnText(pdfContentByte);
        colText.setSimpleColumn(new Phrase(chunk), printImage.getX() + xoffset + borderOffset,
                jasperPrint.getPageHeight() - printImage.getY() - image.scaledHeight() - yoffset - borderOffset,
                printImage.getX() + xoffset + borderOffset + image.scaledWidth(),
                jasperPrint.getPageHeight() - printImage.getY() - yoffset - borderOffset, image.scaledHeight(),
                Element.ALIGN_LEFT);

        colText.go();
    }

    if (printImage.getPen() != JRGraphicElement.PEN_NONE) {
        pdfContentByte.setRGBColorStroke(printImage.getForecolor().getRed(),
                printImage.getForecolor().getGreen(), printImage.getForecolor().getBlue());

        pdfContentByte.setLineWidth(lineWidth);

        if (isLineDotted) {
            pdfContentByte.setLineDash(5f, 3f, 0f);
        } else {
            pdfContentByte.setLineDash(0f);
        }

        pdfContentByte.rectangle(printImage.getX() - borderCorrection,
                jasperPrint.getPageHeight() - printImage.getY() + borderCorrection,
                printImage.getWidth() + 2 * borderCorrection - 1,
                -printImage.getHeight() - 2 * borderCorrection + 1);

        pdfContentByte.stroke();
    }
}

From source file:com.develog.utils.report.engine.export.JRPdfExporter.java

License:Open Source License

/**
 * /*from  w  w w .jav a  2s. c o  m*/
 */
protected Chunk getHyperlinkInfoChunk(JRPrintText text) {
    Chunk chunk = new Chunk(EMPTY_STRING);

    if (text.getAnchorName() != null) {
        chunk.setLocalDestination(text.getAnchorName());
    }

    switch (text.getHyperlinkType()) {
    case JRHyperlink.HYPERLINK_TYPE_REFERENCE: {
        if (text.getHyperlinkReference() != null) {
            chunk.setAnchor(text.getHyperlinkReference());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: {
        if (text.getHyperlinkAnchor() != null) {
            chunk.setLocalGoto(text.getHyperlinkAnchor());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: {
        if (text.getHyperlinkPage() != null) {
            chunk.setLocalGoto("JR_PAGE_ANCHOR_" + text.getHyperlinkPage().toString());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: {
        if (text.getHyperlinkReference() != null && text.getHyperlinkAnchor() != null) {
            chunk.setRemoteGoto(text.getHyperlinkReference(), text.getHyperlinkAnchor());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: {
        if (text.getHyperlinkReference() != null && text.getHyperlinkPage() != null) {
            chunk.setRemoteGoto(text.getHyperlinkReference(), text.getHyperlinkPage().intValue());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_NONE:
    default: {
        break;
    }
    }

    return chunk;
}

From source file:com.dlya.facturews.DlyaPdfExporter2.java

License:Open Source License

/**
 *
 *///from w ww  .j  av a2 s.  c  om
protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link) {
    if (link != null) {
        switch (link.getHyperlinkTypeValue()) {
        case REFERENCE: {
            if (link.getHyperlinkReference() != null) {
                switch (link.getHyperlinkTargetValue()) {
                case BLANK: {
                    chunk.setAction(PdfAction.javaScript("if (app.viewerVersion < 7)" + "{this.getURL(\""
                            + link.getHyperlinkReference() + "\");}" + "else {app.launchURL(\""
                            + link.getHyperlinkReference() + "\", true);};", pdfWriter));
                    break;
                }
                case SELF:
                default: {
                    chunk.setAnchor(link.getHyperlinkReference());
                    break;
                }
                }
            }
            break;
        }
        case LOCAL_ANCHOR: {
            if (link.getHyperlinkAnchor() != null) {
                chunk.setLocalGoto(link.getHyperlinkAnchor());
            }
            break;
        }
        case LOCAL_PAGE: {
            if (link.getHyperlinkPage() != null) {
                chunk.setLocalGoto(
                        JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + link.getHyperlinkPage().toString());
            }
            break;
        }
        case REMOTE_ANCHOR: {
            if (link.getHyperlinkReference() != null && link.getHyperlinkAnchor() != null) {
                chunk.setRemoteGoto(link.getHyperlinkReference(), link.getHyperlinkAnchor());
            }
            break;
        }
        case REMOTE_PAGE: {
            if (link.getHyperlinkReference() != null && link.getHyperlinkPage() != null) {
                chunk.setRemoteGoto(link.getHyperlinkReference(), link.getHyperlinkPage().intValue());
            }
            break;
        }
        case CUSTOM: {
            if (hyperlinkProducerFactory != null) {
                String hyperlink = hyperlinkProducerFactory.produceHyperlink(link);
                if (hyperlink != null) {
                    switch (link.getHyperlinkTargetValue()) {
                    case BLANK: {
                        chunk.setAction(
                                PdfAction.javaScript(
                                        "if (app.viewerVersion < 7)" + "{this.getURL(\"" + hyperlink + "\");}"
                                                + "else {app.launchURL(\"" + hyperlink + "\", true);};",
                                        pdfWriter));
                        break;
                    }
                    case SELF:
                    default: {
                        chunk.setAnchor(hyperlink);
                        break;
                    }
                    }
                }
            }
        }
        case NONE:
        default: {
            break;
        }
        }
    }
}

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

private PageStats generatePDF(List<SongNode> songList, File outputFile) throws IOException, DocumentException {
    logger.info("Starting export to PDF file {}.", outputFile.getAbsolutePath());

    // Initialize Writer
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
    PageStats pageStats = new PageStats();
    writer.setPageEvent(pageStats);/*  w ww. ja va  2s. c om*/

    // Initialize document
    document.setPageSize(PageSize.A4);
    document.setMargins(35 * POINTS_PER_MM, 10 * POINTS_PER_MM, 7 * POINTS_PER_MM, 7 * POINTS_PER_MM);
    document.setMarginMirroring(true);

    document.open();

    // Add QR codes
    Element qrCodeSection = buildQrCodeSection();
    document.add(qrCodeSection);

    // Line separator
    document.add(verseSpacing);
    document.add(new LineSeparator());
    document.add(verseSpacing);

    // Build TOC
    Chunk tocTitle = new Chunk("SONG BOOK - TABLE OF CONTENTS", songTitleFont);
    tocTitle.setLocalDestination("TOC");
    document.add(new Paragraph(tocTitle));
    for (int i = 0; i < songList.size(); i++) {
        SongNode songNode = songList.get(i);
        int chapterNumber = i + 1;
        Chunk tocEntry = new Chunk(chapterNumber + ". " + songNode.getTitle(), textFont);
        tocEntry.setLocalGoto("SONG::" + chapterNumber);
        document.add(new Paragraph(tocEntry));
    }
    document.newPage();
    pageStats.setSectionLength("TOC", pageStats.getCurrentPage() - 1);

    // Build document
    for (int i = 0; i < songList.size(); i++) {
        // Get song node
        SongNode songNode = songList.get(i);

        // Mark song start
        int songStartPage = pageStats.getCurrentPage();

        // Write song
        document.add(buildChapter(songNode, i + 1));
        document.newPage();

        // Record song length
        pageStats.setSectionLength(songNode.getTitle(), pageStats.getCurrentPage() - songStartPage);
    }

    // Close document
    document.close();

    logger.info("COMPLETED export to PDF file {}.", outputFile.getAbsolutePath());

    return pageStats;
}

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

private Chapter buildChapter(SongNode songNode, int chapterNumber) {
    // Title/*from   ww  w.  j a  v a2 s.  c  o  m*/
    Chunk chapterTitle = new Chunk(songNode.getTitle(), songTitleFont);
    chapterTitle.setLocalDestination("SONG::" + chapterNumber);
    chapterTitle.setLocalGoto("TOC");

    Chapter chapter = new Chapter(new Paragraph(chapterTitle), chapterNumber);
    for (VerseNode verseNode : songNode.getVerseList()) {
        processVerse(verseNode, chapter);
    }
    return chapter;
}

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

License:LGPL

/**
 *
 *//*w w  w.ja v a2  s.com*/
protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link) {
    switch (link.getHyperlinkType()) {
    case JRHyperlink.HYPERLINK_TYPE_REFERENCE: {
        if (link.getHyperlinkReference() != null) {
            switch (link.getHyperlinkTarget()) {
            case JRHyperlink.HYPERLINK_TARGET_BLANK: {
                chunk.setAction(PdfAction.javaScript("if (app.viewerVersion < 7)" + "{this.getURL(\""
                        + link.getHyperlinkReference() + "\");}" + "else {app.launchURL(\""
                        + link.getHyperlinkReference() + "\", true);};", pdfWriter));
                break;
            }
            case JRHyperlink.HYPERLINK_TARGET_SELF:
            default: {
                chunk.setAnchor(link.getHyperlinkReference());
                break;
            }
            }
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: {
        if (link.getHyperlinkAnchor() != null) {
            chunk.setLocalGoto(link.getHyperlinkAnchor());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: {
        if (link.getHyperlinkPage() != null) {
            chunk.setLocalGoto(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + link.getHyperlinkPage().toString());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: {
        if (link.getHyperlinkReference() != null && link.getHyperlinkAnchor() != null) {
            chunk.setRemoteGoto(link.getHyperlinkReference(), link.getHyperlinkAnchor());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: {
        if (link.getHyperlinkReference() != null && link.getHyperlinkPage() != null) {
            chunk.setRemoteGoto(link.getHyperlinkReference(), link.getHyperlinkPage().intValue());
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_CUSTOM: {
        if (hyperlinkProducerFactory != null) {
            String hyperlink = hyperlinkProducerFactory.produceHyperlink(link);
            if (hyperlink != null) {
                switch (link.getHyperlinkTarget()) {
                case JRHyperlink.HYPERLINK_TARGET_BLANK: {
                    chunk.setAction(
                            PdfAction.javaScript(
                                    "if (app.viewerVersion < 7)" + "{this.getURL(\"" + hyperlink + "\");}"
                                            + "else {app.launchURL(\"" + hyperlink + "\", true);};",
                                    pdfWriter));
                    break;
                }
                case JRHyperlink.HYPERLINK_TARGET_SELF:
                default: {
                    chunk.setAnchor(hyperlink);
                    break;
                }
                }
            }
        }
    }
    case JRHyperlink.HYPERLINK_TYPE_NONE:
    default: {
        break;
    }
    }
}

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

License:Open Source License

/**
 * Creates a link to a destination in the document. This method
 * does nothing if the given destination is invalid.
 *//*from   w  ww.j  a va 2 s .com*/
public static void createLinkTo(ProgramElementDoc doc, Chunk chunk) {
    String destination = doc.qualifiedName();
    if (destinations.get(destination) != null)
        chunk.setLocalGoto(destination);
}

From source file:org.areasy.common.doclet.document.elements.LinkPhrase.java

License:Open Source License

/**
 * Initializes the link chunk with given values.
 *
 * @param destination The original destination as defined
 *                    in the javadoc./*w w w . j a  v  a 2  s  .  c o  m*/
 * @param label       The text label for the link
 * @param font        The base font for the link (for example, could be
 *                    a bold italic font in case of a "deprecated" tag).
 */
private void init(String destination, String label, Font font) {
    if (label == null)
        label = destination;

    String createLinksProp = DefaultConfiguration.getString(ARG_CREATE_LINKS, ARG_VAL_NO);
    if (createLinksProp.equalsIgnoreCase(ARG_VAL_NO))
        destination = null;

    super.font = font;

    Chunk chunk = new Chunk("");
    chunk.append(label);

    if (destination != null && Destinations.isValid(destination))
        chunk.setLocalGoto(destination);

    add(chunk);
}