Search in sources :

Example 1 with PDPageDestination

use of com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination in project PdfBox-Android by TomRoush.

the class Splitter method processAnnotations.

private void processAnnotations(PDPage imported) throws IOException {
    List<PDAnnotation> annotations = imported.getAnnotations();
    for (PDAnnotation annotation : annotations) {
        if (annotation instanceof PDAnnotationLink) {
            PDAnnotationLink link = (PDAnnotationLink) annotation;
            PDDestination destination = link.getDestination();
            if (destination == null && link.getAction() != null) {
                PDAction action = link.getAction();
                if (action instanceof PDActionGoTo) {
                    destination = ((PDActionGoTo) action).getDestination();
                }
            }
            if (destination instanceof PDPageDestination) {
                // TODO preserve links to pages within the split result
                ((PDPageDestination) destination).setPage(null);
            }
        }
        // TODO preserve links to pages within the split result
        annotation.setPage(null);
    }
}
Also used : PDAction(com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction) PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDPageDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination) PDDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) PDActionGoTo(com.tom_roush.pdfbox.pdmodel.interactive.action.PDActionGoTo)

Example 2 with PDPageDestination

use of com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination in project PdfBox-Android by TomRoush.

the class TestTextStripper method findOutlineItemDestPageNum.

private int findOutlineItemDestPageNum(PDDocument doc, PDOutlineItem oi) throws IOException {
    PDPageDestination pageDest = (PDPageDestination) oi.getDestination();
    // two methods to get the page index, the result should be identical!
    int indexOfPage = doc.getPages().indexOf(oi.findDestinationPage(doc));
    int pageNum = pageDest.retrievePageNumber();
    assertEquals(indexOfPage, pageNum);
    return pageNum;
}
Also used : PDPageDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination)

Example 3 with PDPageDestination

use of com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination in project PdfBox-Android by TomRoush.

the class PDActionGoTo method setDestination.

/**
 * This will set the destination to jump to.
 *
 * @param d The destination.
 *
 * @throws IllegalArgumentException if the destination is not a page dictionary object.
 */
public void setDestination(PDDestination d) {
    if (d instanceof PDPageDestination) {
        PDPageDestination pageDest = (PDPageDestination) d;
        COSArray destArray = pageDest.getCOSObject();
        if (destArray.size() >= 1) {
            COSBase page = destArray.getObject(0);
            if (!(page instanceof COSDictionary)) {
                throw new IllegalArgumentException("Destination of a GoTo action must be " + "a page dictionary object");
            }
        }
    }
    getCOSObject().setItem(COSName.D, d);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDPageDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 4 with PDPageDestination

use of com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination in project PdfBox-Android by TomRoush.

the class PDDocumentCatalog method findNamedDestinationPage.

/**
 * Find the page destination from a named destination.
 * @param namedDest the named destination.
 * @return a PDPageDestination object or null if not found.
 * @throws IOException if there is an error creating the PDPageDestination object.
 */
public PDPageDestination findNamedDestinationPage(PDNamedDestination namedDest) throws IOException {
    PDPageDestination pageDestination = null;
    PDDocumentNameDictionary namesDict = getNames();
    if (namesDict != null) {
        PDDestinationNameTreeNode destsTree = namesDict.getDests();
        if (destsTree != null) {
            pageDestination = destsTree.getValue(namedDest.getNamedDestination());
        }
    }
    if (pageDestination == null) {
        // Look up /Dests dictionary from catalog
        PDDocumentNameDestinationDictionary nameDestDict = getDests();
        if (nameDestDict != null) {
            String name = namedDest.getNamedDestination();
            pageDestination = (PDPageDestination) nameDestDict.getDestination(name);
        }
    }
    return pageDestination;
}
Also used : PDPageDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination)

Example 5 with PDPageDestination

use of com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination in project PdfBox-Android by TomRoush.

the class PDOutlineItem method findDestinationPage.

/**
 * This method will attempt to find the page in this PDF document that this outline points to.
 * If the outline does not point to anything then this method will return null. If the outline
 * is an action that is not a GoTo action then this method will also return null.
 *
 * @param doc The document to get the page from.
 *
 * @return The page that this outline will go to when activated or null if it does not point to
 * anything.
 * @throws IOException If there is an error when trying to find the page.
 */
public PDPage findDestinationPage(PDDocument doc) throws IOException {
    PDDestination dest = getDestination();
    if (dest == null) {
        PDAction outlineAction = getAction();
        if (outlineAction instanceof PDActionGoTo) {
            dest = ((PDActionGoTo) outlineAction).getDestination();
        }
    }
    if (dest == null) {
        return null;
    }
    PDPageDestination pageDestination = null;
    if (dest instanceof PDNamedDestination) {
        pageDestination = doc.getDocumentCatalog().findNamedDestinationPage((PDNamedDestination) dest);
        if (pageDestination == null) {
            return null;
        }
    } else if (dest instanceof PDPageDestination) {
        pageDestination = (PDPageDestination) dest;
    } else {
        throw new IOException("Error: Unknown destination type " + dest);
    }
    PDPage page = pageDestination.getPage();
    if (page == null) {
        // Malformed PDF: local destinations must have a page object,
        // not a page number, these are meant for remote destinations.
        int pageNumber = pageDestination.getPageNumber();
        if (pageNumber != -1) {
            page = doc.getPage(pageNumber);
        }
    }
    return page;
}
Also used : PDAction(com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction) PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDNamedDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination) PDPageDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination) PDDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination) IOException(java.io.IOException) PDActionGoTo(com.tom_roush.pdfbox.pdmodel.interactive.action.PDActionGoTo)

Aggregations

PDPageDestination (com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination)8 COSArray (com.tom_roush.pdfbox.cos.COSArray)3 COSBase (com.tom_roush.pdfbox.cos.COSBase)3 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)3 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)3 PDActionGoTo (com.tom_roush.pdfbox.pdmodel.interactive.action.PDActionGoTo)3 PDDestination (com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination)3 PDDocumentCatalog (com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog)2 PDAction (com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction)2 PDAnnotation (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation)2 IOException (java.io.IOException)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)1 COSName (com.tom_roush.pdfbox.cos.COSName)1 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)1 COSStream (com.tom_roush.pdfbox.cos.COSStream)1 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)1 PDDocumentInformation (com.tom_roush.pdfbox.pdmodel.PDDocumentInformation)1 PDDocumentNameDestinationDictionary (com.tom_roush.pdfbox.pdmodel.PDDocumentNameDestinationDictionary)1 PDDocumentNameDictionary (com.tom_roush.pdfbox.pdmodel.PDDocumentNameDictionary)1 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)1