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() 

Source Link

Document

Create an empty action.

Usage

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

License:Open Source License

/**
 * Creates entries for all the given bookmark entry objects.
 * If any of them has child nodes, the method calls itself
 * recursively to process them as well./*from w w  w.j a va 2s.  c  om*/
 *
 * @param parent  The parent PDF outline object.
 * @param entries The bookmark entries for which to add outline objects.
 */
private static void createBookmarks(PdfOutline parent, BookmarkEntry[] entries) {
    if (entries == null)
        return;

    for (int i = 0; i < entries.length; i++) {
        String name = entries[i].getDestinationName();

        PdfAction action = null;

        if (name == null)
            action = new PdfAction();
        else
            action = PdfAction.gotoLocalPage(name, false);

        PdfOutline outline = new PdfOutline(parent, action, entries[i].getLabel());
        outline.setOpen(false);

        createBookmarks(outline, entries[i].getChildren());
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java

License:Open Source License

private PdfAction createActionForLink(final String target) {
    if (StringUtils.isEmpty(target)) {
        return null;
    }//w  w w. ja  va 2 s .c o m
    final PdfAction action = new PdfAction();
    if (target.startsWith("#")) {
        // its a local link ..
        action.put(PdfName.S, PdfName.GOTO);
        action.put(PdfName.D, new PdfString(target.substring(1)));
    } else {
        action.put(PdfName.S, PdfName.URI);
        action.put(PdfName.URI, new PdfString(target));
    }
    return action;
}

From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java

License:Open Source License

private void processLink(RenderingContext c, Box box) {
    Element elem = box.getElement();
    if (elem != null) {
        NamespaceHandler handler = _sharedContext.getNamespaceHandler();
        String uri = handler.getLinkUri(elem);
        if (uri != null) {
            if (uri.length() > 1 && uri.charAt(0) == '#') {
                String anchor = uri.substring(1);
                Box target = _sharedContext.getBoxById(anchor);
                if (target != null) {
                    PdfDestination dest = createDestination(c, target);

                    if (dest != null) {
                        PdfAction action = new PdfAction();
                        if (!"".equals(handler.getAttributeValue(elem, "onclick"))) {
                            action = PdfAction.javaScript(handler.getAttributeValue(elem, "onclick"), _writer);
                        } else {
                            action.put(PdfName.S, PdfName.GOTO);
                            action.put(PdfName.D, dest);
                        }//  w ww.  j a  v a  2 s  . c o m

                        com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
                        if (targetArea == null) {
                            return;
                        }

                        targetArea.setBorder(0);
                        targetArea.setBorderWidth(0);

                        PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(),
                                targetArea.getBottom(), targetArea.getRight(), targetArea.getTop(), action);
                        annot.put(PdfName.SUBTYPE, PdfName.LINK);
                        annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0));
                        annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0));
                        _writer.addAnnotation(annot);
                    }
                }
            } else if (uri.indexOf("://") != -1) {
                PdfAction action = new PdfAction(uri);

                com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
                if (targetArea == null) {
                    return;
                }
                PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(),
                        targetArea.getRight(), targetArea.getTop(), action);
                annot.put(PdfName.SUBTYPE, PdfName.LINK);

                annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0));
                annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0));
                _writer.addAnnotation(annot);
            }
        }
    }
}