1 31 package org.pdfbox.pdmodel; 32 33 import java.io.IOException ; 34 35 import java.util.Calendar ; 36 37 import org.pdfbox.cos.COSBase; 38 import org.pdfbox.cos.COSDictionary; 39 import org.pdfbox.cos.COSName; 40 41 import org.pdfbox.pdmodel.common.COSObjectable; 42 43 51 public class PDDocumentInformation implements COSObjectable 52 { 53 private static final COSName TITLE = COSName.getPDFName( "Title" ); 54 private static final COSName AUTHOR = COSName.getPDFName( "Author" ); 55 private static final COSName SUBJECT = COSName.getPDFName( "Subject" ); 56 private static final COSName KEYWORDS = COSName.getPDFName( "Keywords" ); 57 private static final COSName CREATOR = COSName.getPDFName( "Creator" ); 58 private static final COSName PRODUCER = COSName.getPDFName( "Producer" ); 59 private static final COSName CREATION_DATE = COSName.getPDFName( "CreationDate" ); 60 private static final COSName MODIFICATION_DATE = COSName.getPDFName( "ModDate" ); 61 private static final COSName TRAPPED = COSName.getPDFName( "Trapped" ); 62 private COSDictionary info; 63 64 65 68 public PDDocumentInformation() 69 { 70 info = new COSDictionary(); 71 } 72 73 78 public PDDocumentInformation( COSDictionary dic ) 79 { 80 info = dic; 81 } 82 83 88 public COSDictionary getDictionary() 89 { 90 return info; 91 } 92 93 98 public COSBase getCOSObject() 99 { 100 return info; 101 } 102 103 108 public String getTitle() 109 { 110 return info.getString( TITLE ); 111 } 112 113 118 public void setTitle( String title ) 119 { 120 info.setString( TITLE, title ); 121 } 122 123 128 public String getAuthor() 129 { 130 return info.getString( AUTHOR ); 131 } 132 133 138 public void setAuthor( String author ) 139 { 140 info.setString( AUTHOR, author ); 141 } 142 143 148 public String getSubject() 149 { 150 return info.getString( SUBJECT ); 151 } 152 153 158 public void setSubject( String subject ) 159 { 160 info.setString( SUBJECT, subject ); 161 } 162 163 168 public String getKeywords() 169 { 170 return info.getString( KEYWORDS ); 171 } 172 173 178 public void setKeywords( String keywords ) 179 { 180 info.setString( KEYWORDS, keywords ); 181 } 182 183 188 public String getCreator() 189 { 190 return info.getString( CREATOR ); 191 } 192 193 198 public void setCreator( String creator ) 199 { 200 info.setString( CREATOR, creator ); 201 } 202 203 208 public String getProducer() 209 { 210 return info.getString( PRODUCER ); 211 } 212 213 218 public void setProducer( String producer ) 219 { 220 info.setString( PRODUCER, producer ); 221 } 222 223 230 public Calendar getCreationDate() throws IOException 231 { 232 return info.getDate( CREATION_DATE ); 233 } 234 235 240 public void setCreationDate( Calendar date ) 241 { 242 info.setDate( CREATION_DATE, date ); 243 } 244 245 252 public Calendar getModificationDate() throws IOException 253 { 254 return info.getDate( MODIFICATION_DATE ); 255 } 256 257 262 public void setModificationDate( Calendar date ) 263 { 264 info.setDate( MODIFICATION_DATE, date ); 265 } 266 267 273 public String getTrapped() 274 { 275 return info.getNameAsString( TRAPPED ); 276 } 277 278 288 public String getCustomMetadataValue(String fieldName) 289 { 290 return info.getString( fieldName ); 291 } 292 293 299 public void setCustomMetadataValue( String fieldName, String fieldValue ) 300 { 301 info.setString( fieldName, fieldValue ); 302 } 303 304 310 public void setTrapped( String value ) 311 { 312 if( value != null && 313 !value.equals( "True" ) && 314 !value.equals( "False" ) && 315 !value.equals( "Unknown" ) ) 316 { 317 throw new RuntimeException ( "Valid values for trapped are " + 318 "'True', 'False', or 'Unknown'" ); 319 } 320 321 info.setName( TRAPPED, value ); 322 } 323 } | Popular Tags |