use of com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction 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.action.PDAction 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