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.viewerpreferences; 18 19 import org.apache.pdfbox.cos.COSBase; 20 import org.apache.pdfbox.cos.COSDictionary; 21 22 import org.apache.pdfbox.pdmodel.common.COSObjectable; 23 24 /** 25 * This is the document viewing preferences. 26 * 27 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 28 * @version $Revision: 1.3 $ 29 */ 30 public class PDViewerPreferences implements COSObjectable 31 { 32 /** 33 * From PDF Reference: "Neither document outline nor thumbnail images visible". 34 */ 35 public static final String NON_FULL_SCREEN_PAGE_MODE_USE_NONE = "UseNone"; 36 /** 37 * From PDF Reference: "Document outline visible". 38 */ 39 public static final String NON_FULL_SCREEN_PAGE_MODE_USE_OUTLINES = "UseOutlines"; 40 /** 41 * From PDF Reference: "Thumbnail images visible". 42 */ 43 public static final String NON_FULL_SCREEN_PAGE_MODE_USE_THUMBS = "UseThumbs"; 44 /** 45 * From PDF Reference: "Optional content group panel visible". 46 */ 47 public static final String NON_FULL_SCREEN_PAGE_MODE_USE_OPTIONAL_CONTENT = "UseOC"; 48 49 /** 50 * Reading direction. 51 */ 52 public static final String READING_DIRECTION_L2R = "L2R"; 53 /** 54 * Reading direction. 55 */ 56 public static final String READING_DIRECTION_R2L = "R2L"; 57 58 /** 59 * Boundary constant. 60 */ 61 public static final String BOUNDARY_MEDIA_BOX = "MediaBox"; 62 /** 63 * Boundary constant. 64 */ 65 public static final String BOUNDARY_CROP_BOX = "CropBox"; 66 /** 67 * Boundary constant. 68 */ 69 public static final String BOUNDARY_BLEED_BOX = "BleedBox"; 70 /** 71 * Boundary constant. 72 */ 73 public static final String BOUNDARY_TRIM_BOX = "TrimBox"; 74 /** 75 * Boundary constant. 76 */ 77 public static final String BOUNDARY_ART_BOX = "ArtBox"; 78 79 80 private COSDictionary prefs; 81 82 /** 83 * Constructor that is used for a preexisting dictionary. 84 * 85 * @param dic The underlying dictionary. 86 */ 87 public PDViewerPreferences( COSDictionary dic ) 88 { 89 prefs = dic; 90 } 91 92 /** 93 * This will get the underlying dictionary that this object wraps. 94 * 95 * @return The underlying info dictionary. 96 */ 97 public COSDictionary getDictionary() 98 { 99 return prefs; 100 } 101 102 /** 103 * Convert this standard java object to a COS object. 104 * 105 * @return The cos object that matches this Java object. 106 */ 107 public COSBase getCOSObject() 108 { 109 return prefs; 110 } 111 112 /** 113 * Get the toolbar preference. 114 * 115 * @return the toolbar preference. 116 */ 117 public boolean hideToolbar() 118 { 119 return prefs.getBoolean( "HideToolbar", false ); 120 } 121 122 /** 123 * Set the toolbar preference. 124 * 125 * @param value Set the toolbar preference. 126 */ 127 public void setHideToolbar( boolean value ) 128 { 129 prefs.setBoolean( "HideToolbar", value ); 130 } 131 132 /** 133 * Get the menubar preference. 134 * 135 * @return the menubar preference. 136 */ 137 public boolean hideMenubar() 138 { 139 return prefs.getBoolean( "HideMenubar", false ); 140 } 141 142 /** 143 * Set the menubar preference. 144 * 145 * @param value Set the menubar preference. 146 */ 147 public void setHideMenubar( boolean value ) 148 { 149 prefs.setBoolean( "HideMenubar", value ); 150 } 151 152 /** 153 * Get the window UI preference. 154 * 155 * @return the window UI preference. 156 */ 157 public boolean hideWindowUI() 158 { 159 return prefs.getBoolean( "HideWindowUI", false ); 160 } 161 162 /** 163 * Set the window UI preference. 164 * 165 * @param value Set the window UI preference. 166 */ 167 public void setHideWindowUI( boolean value ) 168 { 169 prefs.setBoolean( "HideWindowUI", value ); 170 } 171 172 /** 173 * Get the fit window preference. 174 * 175 * @return the fit window preference. 176 */ 177 public boolean fitWindow() 178 { 179 return prefs.getBoolean( "FitWindow", false ); 180 } 181 182 /** 183 * Set the fit window preference. 184 * 185 * @param value Set the fit window preference. 186 */ 187 public void setFitWindow( boolean value ) 188 { 189 prefs.setBoolean( "FitWindow", value ); 190 } 191 192 /** 193 * Get the center window preference. 194 * 195 * @return the center window preference. 196 */ 197 public boolean centerWindow() 198 { 199 return prefs.getBoolean( "CenterWindow", false ); 200 } 201 202 /** 203 * Set the center window preference. 204 * 205 * @param value Set the center window preference. 206 */ 207 public void setCenterWindow( boolean value ) 208 { 209 prefs.setBoolean( "CenterWindow", value ); 210 } 211 212 /** 213 * Get the display doc title preference. 214 * 215 * @return the display doc title preference. 216 */ 217 public boolean displayDocTitle() 218 { 219 return prefs.getBoolean( "DisplayDocTitle", false ); 220 } 221 222 /** 223 * Set the display doc title preference. 224 * 225 * @param value Set the display doc title preference. 226 */ 227 public void setDisplayDocTitle( boolean value ) 228 { 229 prefs.setBoolean( "DisplayDocTitle", value ); 230 } 231 232 /** 233 * Get the non full screen page mode preference. 234 * 235 * @return the non full screen page mode preference. 236 */ 237 public String getNonFullScreenPageMode() 238 { 239 return prefs.getNameAsString( "NonFullScreenPageMode", NON_FULL_SCREEN_PAGE_MODE_USE_NONE); 240 } 241 242 /** 243 * Set the non full screen page mode preference. 244 * 245 * @param value Set the non full screen page mode preference. 246 */ 247 public void setNonFullScreenPageMode( String value ) 248 { 249 prefs.setName( "NonFullScreenPageMode", value ); 250 } 251 252 /** 253 * Get the reading direction preference. 254 * 255 * @return the reading direction preference. 256 */ 257 public String getReadingDirection() 258 { 259 return prefs.getNameAsString( "Direction", READING_DIRECTION_L2R); 260 } 261 262 /** 263 * Set the reading direction preference. 264 * 265 * @param value Set the reading direction preference. 266 */ 267 public void setReadingDirection( String value ) 268 { 269 prefs.setName( "Direction", value ); 270 } 271 272 /** 273 * Get the ViewArea preference. See BOUNDARY_XXX constants. 274 * 275 * @return the ViewArea preference. 276 */ 277 public String getViewArea() 278 { 279 return prefs.getNameAsString( "ViewArea", BOUNDARY_CROP_BOX); 280 } 281 282 /** 283 * Set the ViewArea preference. See BOUNDARY_XXX constants. 284 * 285 * @param value Set the ViewArea preference. 286 */ 287 public void setViewArea( String value ) 288 { 289 prefs.setName( "ViewArea", value ); 290 } 291 292 /** 293 * Get the ViewClip preference. See BOUNDARY_XXX constants. 294 * 295 * @return the ViewClip preference. 296 */ 297 public String getViewClip() 298 { 299 return prefs.getNameAsString( "ViewClip", BOUNDARY_CROP_BOX); 300 } 301 302 /** 303 * Set the ViewClip preference. See BOUNDARY_XXX constants. 304 * 305 * @param value Set the ViewClip preference. 306 */ 307 public void setViewClip( String value ) 308 { 309 prefs.setName( "ViewClip", value ); 310 } 311 312 /** 313 * Get the PrintArea preference. See BOUNDARY_XXX constants. 314 * 315 * @return the PrintArea preference. 316 */ 317 public String getPrintArea() 318 { 319 return prefs.getNameAsString( "PrintArea", BOUNDARY_CROP_BOX); 320 } 321 322 /** 323 * Set the PrintArea preference. See BOUNDARY_XXX constants. 324 * 325 * @param value Set the PrintArea preference. 326 */ 327 public void setPrintArea( String value ) 328 { 329 prefs.setName( "PrintArea", value ); 330 } 331 332 /** 333 * Get the PrintClip preference. See BOUNDARY_XXX constants. 334 * 335 * @return the PrintClip preference. 336 */ 337 public String getPrintClip() 338 { 339 return prefs.getNameAsString( "PrintClip", BOUNDARY_CROP_BOX); 340 } 341 342 /** 343 * Set the PrintClip preference. See BOUNDARY_XXX constants. 344 * 345 * @param value Set the PrintClip preference. 346 */ 347 public void setPrintClip( String value ) 348 { 349 prefs.setName( "PrintClip", value ); 350 } 351 }