1 20 package gnu.jpdf; 21 22 import java.awt.*; 23 import java.io.*; 24 import java.util.*; 25 26 34 public class PDFAnnot extends PDFObject implements Serializable 35 { 36 42 43 46 public static final short SOLID = 0; 47 48 51 public static final short DASHED = 1; 52 53 57 public static final short BEVELED = 2; 58 59 63 public static final short INSET = 3; 64 65 68 public static final short UNDERLINED = 4; 69 70 73 private String subtype; 74 75 78 private int l,b,r,t; 79 80 83 private String s; 84 85 88 private static final int FULL_PAGE = -9999; 89 90 93 private PDFObject dest; 94 95 99 private int fl,fb,fr,ft; 100 101 104 private PDFBorder border; 105 106 114 protected PDFAnnot(String s,int l,int b,int r,int t) { 115 super("/Annot"); 116 subtype = s; 117 this.l = l; 118 this.b = b; 119 this.r = r; 120 this.t = t; 121 } 122 123 131 public PDFAnnot(int l,int b,int r,int t,String s) { 132 this("/Text",l,b,r,t); 133 this.s = s; 134 } 135 136 144 public PDFAnnot(int l,int b,int r,int t,PDFObject dest) { 145 this("/Link",l,b,r,t); 146 this.dest = dest; 147 this.fl = FULL_PAGE; } 149 150 160 public PDFAnnot(int l,int b,int r,int t, 161 PDFObject dest, 162 int fl,int fb,int fr,int ft 163 ) { 164 this("/Link",l,b,r,t); 165 this.dest = dest; 166 this.fl = fl; 167 this.fb = fb; 168 this.fr = fr; 169 this.ft = ft; 170 } 171 172 185 public void setBorder(short style,double width) { 186 border = new PDFBorder(style,width); 187 pdfDocument.add(border); 188 } 189 190 202 public void setBorder(double width,double dash[]) { 203 border = new PDFBorder(width,dash); 204 pdfDocument.add(border); 205 } 206 207 213 public void write(OutputStream os) throws IOException { 214 writeStart(os); 216 217 os.write("/Subtype ".getBytes()); 219 os.write(subtype.getBytes()); 220 os.write("\n/Rect [".getBytes()); 221 os.write(Integer.toString(l).getBytes()); 222 os.write(" ".getBytes()); 223 os.write(Integer.toString(b).getBytes()); 224 os.write(" ".getBytes()); 225 os.write(Integer.toString(r).getBytes()); 226 os.write(" ".getBytes()); 227 os.write(Integer.toString(t).getBytes()); 228 os.write("]\n".getBytes()); 229 230 if(border==null) { 232 os.write("/Border [0 0 0]\n".getBytes()); 233 } else { 237 os.write("/BS ".getBytes()); 238 os.write(border.toString().getBytes()); 239 os.write("\n".getBytes()); 240 } 241 242 if(subtype.equals("/Text")) { 244 os.write("/Contents ".getBytes()); 245 os.write(PDFStringHelper.makePDFString(s).getBytes()); 246 os.write("\n".getBytes()); 247 } else if(subtype.equals("/Link")) { 248 os.write("/Dest [".getBytes()); 249 os.write(dest.toString().getBytes()); 250 if(fl==FULL_PAGE) 251 os.write(" /Fit]".getBytes()); 252 else { 253 os.write(" /FitR ".getBytes()); 254 os.write(Integer.toString(fl).getBytes()); 255 os.write(" ".getBytes()); 256 os.write(Integer.toString(fb).getBytes()); 257 os.write(" ".getBytes()); 258 os.write(Integer.toString(fr).getBytes()); 259 os.write(" ".getBytes()); 260 os.write(Integer.toString(ft).getBytes()); 261 os.write("]".getBytes()); 262 } 263 os.write("\n".getBytes()); 264 } 265 266 writeEnd(os); 268 } 269 } 270 | Popular Tags |