1 50 51 package com.lowagie.text.pdf; 52 import java.io.IOException ; 53 import java.io.OutputStream ; 54 55 74 75 public abstract class PdfObject { 76 77 79 80 public static final int BOOLEAN = 1; 81 82 83 public static final int NUMBER = 2; 84 85 86 public static final int STRING = 3; 87 88 89 public static final int NAME = 4; 90 91 92 public static final int ARRAY = 5; 93 94 95 public static final int DICTIONARY = 6; 96 97 98 public static final int STREAM = 7; 99 100 101 public static final int NULL = 8; 102 103 104 public static final int INDIRECT = 10; 105 106 107 public static final String NOTHING = ""; 108 109 112 public static final String TEXT_PDFDOCENCODING = "PDF"; 113 114 115 public static final String TEXT_UNICODE = "UnicodeBig"; 116 117 119 120 protected byte[] bytes; 121 122 123 protected int type; 124 125 128 protected PRIndirectReference indRef; 129 130 132 137 138 protected PdfObject(int type) { 139 this.type = type; 140 } 141 142 148 149 protected PdfObject(int type, String content) { 150 this.type = type; 151 bytes = PdfEncodings.convertToBytes(content, null); 152 } 153 154 160 161 protected PdfObject(int type, byte[] bytes) { 162 this.bytes = bytes; 163 this.type = type; 164 } 165 166 168 174 175 public void toPdf(PdfWriter writer, OutputStream os) throws IOException { 176 if (bytes != null) 177 os.write(bytes); 178 } 179 180 184 public byte[] getBytes() { 185 return bytes; 186 } 187 188 192 public boolean canBeInObjStm() { 193 return (type >= 1 && type <= 6) || type == 8; 194 } 195 196 208 209 213 218 219 public String toString() { 220 if (bytes == null) 221 return super.toString(); 222 else 223 return PdfEncodings.convertToString(bytes, null); 224 } 225 226 239 240 public int length() { 241 return toString().length(); 242 } 243 244 249 250 protected void setContent(String content) { 251 bytes = PdfEncodings.convertToBytes(content, null); 252 } 253 254 256 261 262 public int type() { 263 return type; 264 } 265 266 271 272 public boolean isNull() { 273 return (this.type == NULL); 274 } 275 276 281 282 public boolean isBoolean() { 283 return (this.type == BOOLEAN); 284 } 285 286 291 292 public boolean isNumber() { 293 return (this.type == NUMBER); 294 } 295 296 301 302 public boolean isString() { 303 return (this.type == STRING); 304 } 305 306 311 312 public boolean isName() { 313 return (this.type == NAME); 314 } 315 316 321 322 public boolean isArray() { 323 return (this.type == ARRAY); 324 } 325 326 331 332 public boolean isDictionary() { 333 return (this.type == DICTIONARY); 334 } 335 336 341 342 public boolean isStream() { 343 return (this.type == STREAM); 344 } 345 346 350 public boolean isIndirect() { 351 return (this.type == INDIRECT); 352 } 353 354 358 public PRIndirectReference getIndRef() { 359 return this.indRef; 360 } 361 362 366 public void setIndRef(PRIndirectReference indRef) { 367 this.indRef = indRef; 368 } 369 } 370 | Popular Tags |