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