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 21 import org.apache.pdfbox.pdmodel.common.PDTextStream; 22 import org.apache.pdfbox.cos.COSBase; 23 24 import java.io.IOException; 25 26 import java.util.Calendar; 27 28 /** 29 * This class represents the additonal fields of a Markup type Annotation. 30 * 31 * 32 * @author Paul King 33 * @version $Revision: 1.1 $ 34 */ 35 public abstract class PDAnnotationMarkup extends PDAnnotation 36 { 37 38 /* 39 * The various values of the reply type as defined in the PDF 1.7 reference 40 * Table 170 41 */ 42 43 /** 44 * Constant for an annotation reply type. 45 */ 46 public static final String RT_REPLY = "R"; 47 48 /** 49 * Constant for an annotation reply type. 50 */ 51 public static final String RT_GROUP = "Group"; 52 53 /** 54 * Constructor. 55 */ 56 public PDAnnotationMarkup() 57 { 58 super(); 59 } 60 61 /** 62 * Constructor. 63 * 64 * @param dict 65 * The annotations dictionary. 66 */ 67 public PDAnnotationMarkup( COSDictionary dict ) 68 { 69 super( dict ); 70 } 71 72 /** 73 * Retrieve the string used as the title of the popup window shown when open 74 * and active (by convention this identifies who added the annotation). 75 * 76 * @return The title of the popup. 77 */ 78 public String getTitlePopup() 79 { 80 return getDictionary().getString( "T" ); 81 } 82 83 /** 84 * Set the string used as the title of the popup window shown when open and 85 * active (by convention this identifies who added the annotation). 86 * 87 * @param t 88 * The title of the popup. 89 */ 90 public void setTitlePopup( String t ) 91 { 92 getDictionary().setString( "T", t ); 93 } 94 95 /** 96 * This will retrieve the popup annotation used for entering/editing the 97 * text for this annotation. 98 * 99 * @return the popup annotation. 100 */ 101 public PDAnnotationPopup getPopup() 102 { 103 COSDictionary popup = (COSDictionary) getDictionary().getDictionaryObject( "Popup" ); 104 if (popup != null) 105 { 106 return new PDAnnotationPopup( popup ); 107 } 108 else 109 { 110 return null; 111 } 112 } 113 114 /** 115 * This will set the popup annotation used for entering/editing the text for 116 * this annotation. 117 * 118 * @param popup 119 * the popup annotation. 120 */ 121 public void setPopup( PDAnnotationPopup popup ) 122 { 123 getDictionary().setItem( "Popup", popup ); 124 } 125 126 /** 127 * This will retrieve the constant opacity value used when rendering the 128 * annotation (excluing any popup). 129 * 130 * @return the constant opacity value. 131 */ 132 public float getConstantOpacity() 133 { 134 return getDictionary().getFloat( "CA", 1 ); 135 } 136 137 /** 138 * This will set the constant opacity value used when rendering the 139 * annotation (excluing any popup). 140 * 141 * @param ca 142 * the constant opacity value. 143 */ 144 public void setConstantOpacity( float ca ) 145 { 146 getDictionary().setFloat( "CA", ca ); 147 } 148 149 /** 150 * This will retrieve the rich text stream which is displayed in the popup 151 * window. 152 * 153 * @return the rich text stream. 154 */ 155 public PDTextStream getRichContents() 156 { 157 COSBase rc = getDictionary().getDictionaryObject( "RC" ); 158 if (rc != null) 159 { 160 return PDTextStream.createTextStream( rc ); 161 } 162 else 163 { 164 return null; 165 } 166 } 167 168 /** 169 * This will set the rich text stream which is displayed in the popup window. 170 * 171 * @param rc 172 * the rich text stream. 173 */ 174 public void setRichContents( PDTextStream rc ) 175 { 176 getDictionary().setItem( "RC", rc); 177 } 178 179 /** 180 * This will retrieve the date and time the annotation was created. 181 * 182 * @return the creation date/time. 183 * @throws IOException 184 * if there is a format problem when converting the date. 185 */ 186 public Calendar getCreationDate() throws IOException 187 { 188 return getDictionary().getDate( "CreationDate" ); 189 } 190 191 /** 192 * This will set the the date and time the annotation was created. 193 * 194 * @param creationDate 195 * the date and time the annotation was created. 196 */ 197 public void setCreationDate( Calendar creationDate ) 198 { 199 getDictionary().setDate( "CreationDate", creationDate ); 200 } 201 202 /** 203 * This will retrieve the annotation to which this one is "In Reply To" the 204 * actual relationship is specified by the RT entry. 205 * 206 * @return the other annotation. 207 * @throws IOException 208 * if there is an error with the annotation. 209 */ 210 public PDAnnotation getInReplyTo() throws IOException 211 { 212 COSBase irt = getDictionary().getDictionaryObject( "IRT" ); 213 return PDAnnotation.createAnnotation( irt ); 214 } 215 216 /** 217 * This will set the annotation to which this one is "In Reply To" the 218 * actual relationship is specified by the RT entry. 219 * 220 * @param irt the annotation this one is "In Reply To". 221 */ 222 public void setInReplyTo( PDAnnotation irt ) 223 { 224 getDictionary().setItem( "IRT", irt ); 225 } 226 227 /** 228 * This will retrieve the short description of the subject of the annotation. 229 * 230 * @return the subject. 231 */ 232 public String getSubject() 233 { 234 return getDictionary().getString( "Subj" ); 235 } 236 237 /** 238 * This will set the short description of the subject of the annotation. 239 * 240 * @param subj short description of the subject. 241 */ 242 public void setSubject( String subj ) 243 { 244 getDictionary().setString( "Subj", subj ); 245 } 246 247 /** 248 * This will retrieve the Reply Type (relationship) with the annotation in 249 * the IRT entry See the RT_* constants for the available values. 250 * 251 * @return the relationship. 252 */ 253 public String getReplyType() 254 { 255 return getDictionary().getNameAsString( "RT", RT_REPLY ); 256 } 257 258 /** 259 * This will set the Reply Type (relationship) with the annotation in the 260 * IRT entry See the RT_* constants for the available values. 261 * 262 * @param rt the reply type. 263 */ 264 public void setReplyType( String rt ) 265 { 266 getDictionary().setName( "RT", rt ); 267 } 268 269 /** 270 * This will retrieve the intent of the annotation The values and meanings 271 * are specific to the actual annotation See the IT_* constants for the 272 * annotation classes. 273 * 274 * @return the intent 275 */ 276 public String getIntent() 277 { 278 return getDictionary().getNameAsString( "IT" ); 279 } 280 281 /** 282 * This will set the intent of the annotation The values and meanings are 283 * specific to the actual annotation See the IT_* constants for the 284 * annotation classes. 285 * 286 * @param it the intent 287 */ 288 public void setIntent( String it ) 289 { 290 getDictionary().setName( "IT", it ); 291 } 292 293 /** 294 * This will return the external data dictionary. 295 * 296 * @return the external data dictionary 297 */ 298 public PDExternalDataDictionary getExternalData() 299 { 300 COSBase exData = this.getDictionary().getDictionaryObject("ExData"); 301 if (exData instanceof COSDictionary) 302 { 303 return new PDExternalDataDictionary((COSDictionary) exData); 304 } 305 return null; 306 } 307 308 /** 309 * This will set the external data dictionary. 310 * 311 * @param externalData the external data dictionary 312 */ 313 public void setExternalData(PDExternalDataDictionary externalData) 314 { 315 this.getDictionary().setItem("ExData", externalData); 316 } 317 318 }