1 21 package gnu.jpdf; 22 23 import java.io.*; 24 import java.util.*; 25 26 34 public abstract class PDFObject implements Serializable 35 { 36 37 45 46 49 private String type; 50 51 54 protected int objser; 55 56 59 protected PDFDocument pdfDocument; 60 61 62 66 public PDFObject(String type) 67 { 68 this.type = type; 69 } 70 71 75 public String getType() 76 { 77 return type; 78 } 79 80 84 public final int getSerialID() 85 { 86 return objser; 87 } 88 89 93 public final PDFDocument getPDFDocument() 94 { 95 return pdfDocument; 96 } 97 98 108 public abstract void write(OutputStream os) throws IOException; 109 110 119 public final void writeStart(OutputStream os) throws IOException 120 { 121 os.write(Integer.toString(objser).getBytes()); 122 os.write(" 0 obj\n<<\n".getBytes()); 123 if(type!=null) { 124 os.write("/Type ".getBytes()); 125 os.write(type.getBytes()); 126 os.write("\n".getBytes()); 127 } 128 } 129 130 131 132 133 142 public final void writeEnd(OutputStream os) throws IOException 143 { 144 os.write(">>\nendobj\n".getBytes()); 145 } 146 147 151 public String toString() 152 { 153 return ""+objser+" 0 R"; 154 } 155 156 162 public static String toArray(Vector v) 163 { 164 if(v.size()==0) 165 return ""; 166 167 StringBuffer b = new StringBuffer (); 168 String bs = "["; 169 for(Enumeration en = v.elements(); en.hasMoreElements(); ) { 170 b.append(bs); 171 b.append(en.nextElement().toString()); 172 bs = " "; 173 } 174 b.append("]"); 175 return b.toString(); 176 } 177 } 178 | Popular Tags |