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.annotation;
19 import java.io.IOException;
21 import org.apache.pdfbox.cos.COSDictionary;
22 import org.apache.pdfbox.cos.COSName;
23 import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
26 * This is the class that represents a file attachement.
28 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
29 * @version $Revision: 1.2 $
31 public class PDAnnotationFileAttachment extends PDAnnotationMarkup
34 * See get/setAttachmentName.
36 public static final String ATTACHMENT_NAME_PUSH_PIN = "PushPin";
38 * See get/setAttachmentName.
40 public static final String ATTACHMENT_NAME_GRAPH = "Graph";
42 * See get/setAttachmentName.
44 public static final String ATTACHMENT_NAME_PAPERCLIP = "Paperclip";
46 * See get/setAttachmentName.
48 public static final String ATTACHMENT_NAME_TAG = "Tag";
51 * The type of annotation.
53 public static final String SUB_TYPE = "FileAttachment";
58 public PDAnnotationFileAttachment()
61 getDictionary().setItem( COSName.SUBTYPE, COSName.getPDFName( SUB_TYPE ) );
65 * Creates a Link annotation from a COSDictionary, expected to be
66 * a correct object definition.
68 * @param field the PDF objet to represent as a field.
70 public PDAnnotationFileAttachment(COSDictionary field)
76 * Return the attached file.
78 * @return The attached file.
80 * @throws IOException If there is an error creating the file spec.
82 public PDFileSpecification getFile() throws IOException
84 return PDFileSpecification.createFS( getDictionary().getDictionaryObject( "FS" ) );
88 * Set the attached file.
90 * @param file The file that is attached.
92 public void setFile( PDFileSpecification file )
94 getDictionary().setItem( "FS", file );
98 * This is the name used to draw the type of attachment.
99 * See the ATTACHMENT_NAME_XXX constants.
101 * @return The name that describes the visual cue for the attachment.
103 public String getAttachmentName()
105 return getDictionary().getNameAsString( "Name", ATTACHMENT_NAME_PUSH_PIN );
109 * Set the name used to draw the attachement icon.
110 * See the ATTACHMENT_NAME_XXX constants.
112 * @param name The name of the visual icon to draw.
114 public void setAttachementName( String name )
116 getDictionary().setName( "Name", name );