This represents an outline in a pdf document.
Method from org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem Detail: |
public PDPage findDestinationPage(PDDocument doc) throws IOException {
PDPage page = null;
PDDestination rawDest = getDestination();
if( rawDest == null )
{
PDAction outlineAction = getAction();
if( outlineAction instanceof PDActionGoTo )
{
rawDest = ((PDActionGoTo)outlineAction).getDestination();
}
else if( outlineAction == null )
{
//if the outline action is null then this outline does not refer
//to anything and we will just return null.
}
else
{
throw new OutlineNotLocalException( "Error: Outline does not reference a local page." );
}
}
PDPageDestination pageDest = null;
if( rawDest instanceof PDNamedDestination )
{
//if we have a named destination we need to lookup the PDPageDestination
PDNamedDestination namedDest = (PDNamedDestination)rawDest;
PDDocumentNameDictionary namesDict = doc.getDocumentCatalog().getNames();
if( namesDict != null )
{
PDDestinationNameTreeNode destsTree = namesDict.getDests();
if( destsTree != null )
{
pageDest = (PDPageDestination)destsTree.getValue( namedDest.getNamedDestination() );
}
}
}
else if( rawDest instanceof PDPageDestination)
{
pageDest = (PDPageDestination) rawDest;
}
else if( rawDest == null )
{
//if the destination is null then we will simply return a null page.
}
else
{
throw new IOException( "Error: Unknown destination type " + rawDest );
}
if( pageDest != null )
{
page = pageDest.getPage();
if( page == null )
{
int pageNumber = pageDest.getPageNumber();
if( pageNumber != -1 )
{
List allPages = doc.getDocumentCatalog().getAllPages();
page = (PDPage)allPages.get( pageNumber );
}
}
}
return page;
}
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 methods will throw the OutlineNotLocationException |
public PDAction getAction() {
return PDActionFactory.createAction( (COSDictionary)node.getDictionaryObject( "A" ) );
}
Get the action of this node. |
public PDDestination getDestination() throws IOException {
return PDDestination.create( node.getDictionaryObject( "Dest" ) );
}
Get the page destination of this node. |
public PDOutlineItem getNextSibling() {
PDOutlineItem last = null;
COSDictionary lastDic = (COSDictionary)node.getDictionaryObject( "Next" );
if( lastDic != null )
{
last = new PDOutlineItem( lastDic );
}
return last;
}
Return the next sibling or null if there is no next sibling. |
public PDOutlineNode getParent() {
return super.getParent();
}
|
public PDOutlineItem getPreviousSibling() {
PDOutlineItem last = null;
COSDictionary lastDic = (COSDictionary)node.getDictionaryObject( "Prev" );
if( lastDic != null )
{
last = new PDOutlineItem( lastDic );
}
return last;
}
Return the previous sibling or null if there is no sibling. |
public PDStructureElement getStructureElement() {
PDStructureElement se = null;
COSDictionary dic = (COSDictionary)node.getDictionaryObject( "SE" );
if( dic != null )
{
se = new PDStructureElement( dic );
}
return se;
}
Get the structure element of this node. |
public PDColorState getTextColor() {
PDColorState retval = null;
COSArray csValues = (COSArray)node.getDictionaryObject( "C" );
if( csValues == null )
{
csValues = new COSArray();
csValues.growToSize( 3, new COSFloat( 0 ) );
node.setItem( "C", csValues );
}
retval = new PDColorState(csValues);
retval.setColorSpace( PDDeviceRGB.INSTANCE );
return retval;
}
Get the text color of this node. Default is black and this method
will never return null. |
public String getTitle() {
return node.getString( "Title" );
}
Get the title of this node. |
public void insertSiblingAfter(PDOutlineItem item) {
item.setParent( getParent() );
PDOutlineItem next = getNextSibling();
setNextSibling( item );
item.setPreviousSibling( this );
if( next != null )
{
item.setNextSibling( next );
next.setPreviousSibling( item );
}
updateParentOpenCount( 1 );
}
Insert a sibling after this node. |
public boolean isBold() {
return BitFlagHelper.getFlag( node, "F", BOLD_FLAG );
}
A flag telling if the text should be bold. |
public boolean isItalic() {
return BitFlagHelper.getFlag( node, "F", ITALIC_FLAG );
}
A flag telling if the text should be italic. |
public void setAction(PDAction action) {
node.setItem( "A", action );
}
Set the action for this node. |
public void setBold(boolean bold) {
BitFlagHelper.setFlag( node, "F", BOLD_FLAG, bold );
}
Set the bold property of the text. |
public void setDestination(PDDestination dest) {
node.setItem( "Dest", dest );
}
Set the page destination for this node. |
public void setDestination(PDPage page) {
PDPageXYZDestination dest = null;
if( page != null )
{
dest = new PDPageXYZDestination();
dest.setPage( page );
}
setDestination( dest );
}
A convenience method that will create an XYZ destination using only the defaults. |
public void setItalic(boolean italic) {
BitFlagHelper.setFlag( node, "F", ITALIC_FLAG, italic );
}
Set the italic property of the text. |
protected void setNextSibling(PDOutlineNode outlineNode) {
node.setItem( "Next", outlineNode );
}
Set the next sibling, this will be maintained by this class. |
protected void setPreviousSibling(PDOutlineNode outlineNode) {
node.setItem( "Prev", outlineNode );
}
Set the previous sibling, this will be maintained by this class. |
public void setStructuredElement(PDStructureElement structureElement) {
node.setItem( "SE", structureElement );
}
Set the structure element for this node. |
public void setTextColor(PDColorState textColor) {
node.setItem( "C", textColor.getCOSColorSpaceValue() );
}
Set the text color for this node. The colorspace must be a PDDeviceRGB. |
public void setTextColor(Color textColor) {
COSArray array = new COSArray();
array.add( new COSFloat( textColor.getRed()/255f));
array.add( new COSFloat( textColor.getGreen()/255f));
array.add( new COSFloat( textColor.getBlue()/255f));
node.setItem( "C", array );
}
Set the text color for this node. The colorspace must be a PDDeviceRGB. |
public void setTitle(String title) {
node.setString( "Title", title );
}
Set the title for this node. |