Example usage for com.lowagie.text.pdf PdfAction PdfAction

List of usage examples for com.lowagie.text.pdf PdfAction PdfAction

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfAction PdfAction.

Prototype


public PdfAction(String filename, int page) 

Source Link

Document

Constructs a new PdfAction of Subtype GoToR.

Usage

From source file:org.areasy.common.doclet.document.tags.TagA.java

License:Open Source License

public Element toElement(String text) {
    String addr = getAttribute("href");

    if (addr == null || !DefaultConfiguration.isLinksCreationActive())
        addr = "";
    if (!isPre())
        text = DocletUtility.stripLineFeeds(text);

    Element aChunk;//from  w ww. j  a va 2  s . c  om
    if (addr.startsWith("locallink")) {
        boolean plainText = addr.startsWith("locallinkplain");
        String dest = addr.substring(addr.indexOf(':') + 1).trim();

        setCode(!plainText);

        return new LinkPhrase(dest, text, Math.max(9, (int) getFont().size()), plainText);
    } else if (addr.equalsIgnoreCase("newpage"))
        return super.toElement(text);
    else if (addr.startsWith("http://") || addr.startsWith("https://")) {
        try {
            URL url = new URL(addr);
            return new Chunk(text, getFont()).setAnchor(url);
        } catch (MalformedURLException e) {
            log.error("Malformed URL: " + addr);
        }
    } else {
        String fileName = addr.trim();
        String anchorName = "";

        int hashIndex = addr.indexOf('#');

        if (hashIndex >= 0) {
            fileName = addr.substring(0, hashIndex).trim();
            anchorName = addr.substring(hashIndex + 1).trim();
        }

        boolean isLocalAnchor = (fileName.length() == 0 && anchorName.length() > 0);
        File file = null;

        try {
            if (fileName.length() > 0)
                file = new File(DocletUtility.getFilePath(fileName));
            else
                file = State.getCurrentFile();
        } catch (FileNotFoundException e) {
            log.debug("Could not find linked file " + fileName);
        }

        if (isLocalAnchor || Destinations.isValidDestinationFile(file)) {
            String fullAnchor = Destinations.createAnchorDestination(file, anchorName);

            PdfAction action = new PdfAction("", "");
            action.remove(PdfName.F);
            action.put(PdfName.S, PdfName.GOTO);
            action.put(PdfName.D, new PdfString(fullAnchor));

            aChunk = new Phrase();

            Chunk chunk = createChunk(text);
            ((Phrase) aChunk).add(chunk.setAction(action));

            return aChunk;
        }
    }

    if (getAttribute("name") != null)
        setLink(false); // no underline for anchors

    Font font = getFont();
    font.setColor(0, 0, 0);

    aChunk = new Chunk(text, font);

    setLink(false);

    return aChunk;
}

From source file:org.eclipse.birt.report.engine.emitter.pdf.PDFPage.java

License:Open Source License

/**
 * Creates a PdfAction.//from w  w w  .j  a  v a2  s.c  om
 *
 * @param hyperlink
 *            the hyperlink.
 * @param bookmark
 *            the bookmark.
 * @param target
 *            if target equals "_blank", the target will be opened in a new
 *            window, else the target will be opened in the current window.
 * @return the created PdfAction.
 */
private PdfAction createPdfAction(String hyperlink, String bookmark, String target, int type) {
    // patch from Ales Novy
    if ("_top".equalsIgnoreCase(target) || "_parent".equalsIgnoreCase(target)
            || "_blank".equalsIgnoreCase(target) || "_self".equalsIgnoreCase(target))
    // Opens the target in a new window.
    {
        if (hyperlink == null)
            hyperlink = "";
        boolean isUrl = hyperlink.startsWith("http");
        if (!isUrl) {
            Matcher matcher = PAGE_LINK_PATTERN.matcher(hyperlink);
            if (matcher.find()) {
                String fileName = matcher.group(1);
                String pageNumber = matcher.group(matcher.groupCount());
                return new PdfAction(fileName, Integer.valueOf(pageNumber));
            }
        }
        return new PdfAction(hyperlink);
    } else

    // Opens the target in the current window.
    {
        if (type == IHyperlinkAction.ACTION_BOOKMARK) {
            return PdfAction.gotoLocalPage(bookmark, false);
        } else {
            return PdfAction.gotoRemotePage(hyperlink, bookmark, false, false);
        }
    }
}