2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination;
19 import java.io.IOException;
21 import org.apache.pdfbox.cos.COSArray;
22 import org.apache.pdfbox.cos.COSBase;
23 import org.apache.pdfbox.cos.COSName;
24 import org.apache.pdfbox.cos.COSString;
26 import org.apache.pdfbox.pdmodel.common.PDDestinationOrAction;
29 * This represents a destination in a PDF document.
31 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
32 * @version $Revision: 1.6 $
34 public abstract class PDDestination implements PDDestinationOrAction
38 * This will create a new destination depending on the type of COSBase
41 * @param base The base level object.
43 * @return A new destination.
45 * @throws IOException If the base cannot be converted to a Destination.
47 public static PDDestination create( COSBase base ) throws IOException
49 PDDestination retval = null;
52 //this is ok, just return null.
54 else if( base instanceof COSArray && ((COSArray)base).size() > 0 )
56 COSArray array = (COSArray)base;
57 COSName type = (COSName)array.getObject( 1 );
58 String typeString = type.getName();
59 if( typeString.equals( PDPageFitDestination.TYPE ) ||
60 typeString.equals( PDPageFitDestination.TYPE_BOUNDED ))
62 retval = new PDPageFitDestination( array );
64 else if( typeString.equals( PDPageFitHeightDestination.TYPE ) ||
65 typeString.equals( PDPageFitHeightDestination.TYPE_BOUNDED ))
67 retval = new PDPageFitHeightDestination( array );
69 else if( typeString.equals( PDPageFitRectangleDestination.TYPE ) )
71 retval = new PDPageFitRectangleDestination( array );
73 else if( typeString.equals( PDPageFitWidthDestination.TYPE ) ||
74 typeString.equals( PDPageFitWidthDestination.TYPE_BOUNDED ))
76 retval = new PDPageFitWidthDestination( array );
78 else if( typeString.equals( PDPageXYZDestination.TYPE ) )
80 retval = new PDPageXYZDestination( array );
84 throw new IOException( "Unknown destination type:" + type );
87 else if( base instanceof COSString )
89 retval = new PDNamedDestination( (COSString)base );
91 else if( base instanceof COSName )
93 retval = new PDNamedDestination( (COSName)base );
97 throw new IOException( "Error: can't convert to Destination " + base );
103 * Return a string representation of this class.
105 * @return A human readable string.
107 public String toString()
109 return super.toString();