1 /* 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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. 16 */ 17 package org.apache.pdfbox.pdmodel.interactive.annotation; 18 19 import org.apache.pdfbox.cos.COSDictionary; 20 import org.apache.pdfbox.cos.COSName; 21 22 /** 23 * This is the class that represents a text annotation. 24 * 25 * @author Paul King 26 * @version $Revision: 1.1 $ 27 */ 28 public class PDAnnotationText extends PDAnnotationMarkup 29 { 30 31 /* 32 * The various values of the Text as defined in the PDF 1.7 reference Table 33 * 172 34 */ 35 36 /** 37 * Constant for the name of a text annotation. 38 */ 39 public static final String NAME_COMMENT = "Comment"; 40 41 /** 42 * Constant for the name of a text annotation. 43 */ 44 public static final String NAME_KEY = "Key"; 45 46 /** 47 * Constant for the name of a text annotation. 48 */ 49 public static final String NAME_NOTE = "Note"; 50 51 /** 52 * Constant for the name of a text annotation. 53 */ 54 public static final String NAME_HELP = "Help"; 55 56 /** 57 * Constant for the name of a text annotation. 58 */ 59 public static final String NAME_NEW_PARAGRAPH = "NewParagraph"; 60 61 /** 62 * Constant for the name of a text annotation. 63 */ 64 public static final String NAME_PARAGRAPH = "Paragraph"; 65 66 /** 67 * Constant for the name of a text annotation. 68 */ 69 public static final String NAME_INSERT = "Insert"; 70 71 /** 72 * The type of annotation. 73 */ 74 public static final String SUB_TYPE = "Text"; 75 76 /** 77 * Constructor. 78 */ 79 public PDAnnotationText() 80 { 81 super(); 82 getDictionary() 83 .setItem( COSName.SUBTYPE, COSName.getPDFName( SUB_TYPE ) ); 84 } 85 86 /** 87 * Creates a Text annotation from a COSDictionary, expected to be a correct 88 * object definition. 89 * 90 * @param field 91 * the PDF object to represent as a field. 92 */ 93 public PDAnnotationText( COSDictionary field ) 94 { 95 super( field ); 96 } 97 98 /** 99 * This will set initial state of the annotation, open or closed. 100 * 101 * @param open 102 * Boolean value, true = open false = closed 103 */ 104 public void setOpen( boolean open ) 105 { 106 getDictionary().setBoolean( COSName.getPDFName( "Open" ), open ); 107 } 108 109 /** 110 * This will retrieve the initial state of the annotation, open Or closed 111 * (default closed). 112 * 113 * @return The initial state, true = open false = closed 114 */ 115 public boolean getOpen() 116 { 117 return getDictionary().getBoolean( COSName.getPDFName( "Open" ), false ); 118 } 119 120 /** 121 * This will set the name (and hence appearance, AP taking precedence) For 122 * this annotation. See the NAME_XXX constants for valid values. 123 * 124 * @param name 125 * The name of the annotation 126 */ 127 public void setName( String name ) 128 { 129 getDictionary().setName( COSName.NAME, name ); 130 } 131 132 /** 133 * This will retrieve the name (and hence appearance, AP taking precedence) 134 * For this annotation. The default is NOTE. 135 * 136 * @return The name of this annotation, see the NAME_XXX constants. 137 */ 138 public String getName() 139 { 140 return getDictionary().getNameAsString( COSName.NAME, NAME_NOTE ); 141 } 142 143 /** 144 * This will retrieve the annotation state. 145 * 146 * @return the annotation state 147 */ 148 public String getState() 149 { 150 return this.getDictionary().getString("State"); 151 } 152 153 /** 154 * This will set the annotation state. 155 * 156 * @param state the annotation state 157 */ 158 public void setState(String state) 159 { 160 this.getDictionary().setString("State", state); 161 } 162 163 /** 164 * This will retrieve the annotation state model. 165 * 166 * @return the annotation state model 167 */ 168 public String getStateModel() 169 { 170 return this.getDictionary().getString("StateModel"); 171 } 172 173 /** 174 * This will set the annotation state model. 175 * Allowed values are "Marked" and "Review" 176 * 177 * @param stateModel the annotation state model 178 */ 179 public void setStateModel(String stateModel) 180 { 181 this.getDictionary().setString("StateModel", stateModel); 182 } 183 184 }