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

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

Introduction

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

Prototype

PdfName D

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

Click Source Link

Document

A name

Usage

From source file:it.flavianopetrocchi.jpdfbookmarks.itextbookmarksconverter.iTextBookmarksConverter.java

License:Open Source License

private void setActionInBookmark(Bookmark bookmark, PdfDictionary action) {
    PdfObject dest;//from  w w w  .  ja va  2s .  c o m
    if (PdfName.GOTO.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        dest = PdfReader.getPdfObjectRelease(action.get(PdfName.D));
        if (dest != null) {
            mapGotoBookmark(bookmark, dest);
        }
    } else if (PdfName.URI.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        bookmark.setType(BookmarkType.Uri);
        bookmark.setUri(((PdfString) PdfReader.getPdfObjectRelease(action.get(PdfName.URI))).toUnicodeString());
    } else if (PdfName.GOTOR.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        bookmark.setRemoteDestination(true);
        PdfObject file = PdfReader.getPdfObjectRelease(action.get(PdfName.F));
        if (file != null) {
            if (file.isString()) {
                String path = Ut.onWindowsReplaceBackslashWithSlash(((PdfString) file).toUnicodeString());
                bookmark.setRemoteFilePath(path);
            } else if (file.isDictionary()) {
                file = PdfReader.getPdfObject(((PdfDictionary) file).get(PdfName.F));
                if (file.isString()) {
                    bookmark.setRemoteFilePath(((PdfString) file).toUnicodeString());
                }
            }
        }
        dest = PdfReader.getPdfObjectRelease(action.get(PdfName.D));
        if (dest != null) {
            if (dest.isString()) {
                bookmark.setNamedDestination(dest.toString());
            } else if (dest.isName()) {
                bookmark.setNamedDestination(PdfName.decodeName(dest.toString()));
                bookmark.setNamedAsName(true);
            } else if (dest.isArray()) {
                PdfArray arr = (PdfArray) dest;
                PdfReader remoteReader;
                try {
                    //                        File remoteFile = new File(bookmark.getRemoteFilePath());
                    //                        if (!remoteFile.isAbsolute()) {
                    //                            File openedFile = new File(filePath);
                    //                            String containingFolder = openedFile.getParent();
                    //                            String remotePath = containingFolder + File.separator + bookmark.getRemoteFilePath();
                    //                            remoteFile = new File(remotePath);
                    //                        }
                    File remoteFile = Ut.createAbsolutePath(new File(filePath),
                            new File(bookmark.getRemoteFilePath()));
                    remoteReader = new PdfReader(remoteFile.getCanonicalPath());
                    makeBookmarkParam(remoteReader, bookmark, arr, null);
                    remoteReader.close();
                } catch (IOException ex) {
                    //System.out.println(ex.getMessage());
                } finally {
                }
            }
        }
        PdfObject newWindow = PdfReader.getPdfObjectRelease(action.get(PdfName.NEWWINDOW));
        if (newWindow != null) {
            bookmark.setNewWindow(((PdfBoolean) newWindow).booleanValue());
        }
    } else if (PdfName.LAUNCH.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        bookmark.setType(BookmarkType.Launch);
        PdfObject file = PdfReader.getPdfObjectRelease(action.get(PdfName.F));
        if (file == null) {
            file = PdfReader.getPdfObjectRelease(action.get(PdfName.WIN));
        }
        if (file != null) {
            if (file.isString()) {
                bookmark.setFileToLaunch(((PdfString) file).toUnicodeString());
            } else if (file.isDictionary()) {
                file = PdfReader.getPdfObjectRelease(((PdfDictionary) file).get(PdfName.F));
                if (file.isString()) {
                    bookmark.setFileToLaunch(((PdfString) file).toUnicodeString());
                }
            }
        }
    } else if (PdfName.HIDE.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        bookmark.setType(BookmarkType.Hide);
        PdfObject annotation = PdfReader.getPdfObjectRelease(action.get(PdfName.T));
        if (annotation != null) {
            if (annotation.isDictionary()) {
            } else if (annotation.isArray()) {
            } else if (annotation.isString()) {
                bookmark.setFieldNameToHide(((PdfString) annotation).toUnicodeString());
            }
        }
        PdfBoolean hide = (PdfBoolean) PdfReader.getPdfObjectRelease(action.get(PdfName.H));
        if (hide != null) {
            bookmark.setHide(hide.booleanValue());
        }
    } else {
        bookmark.setType(BookmarkType.Unknown);
    }
}

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;//ww  w. j  ava 2s. co m
    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.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;
    }/*from w w  w .  j a  v  a 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);
                        }/*from   w w w .  ja va2  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);
            }
        }
    }
}