Example usage for com.lowagie.text.pdf PdfName LINK

List of usage examples for com.lowagie.text.pdf PdfName LINK

Introduction

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

Prototype

PdfName LINK

To view the source code for com.lowagie.text.pdf PdfName LINK.

Click Source Link

Document

A name

Usage

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);
                        }//from   www .j a  v a2 s .  c om

                        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);
            }
        }
    }
}