1 50 51 package com.lowagie.text.pdf; 52 import java.io.IOException ; 53 54 import com.lowagie.text.Rectangle; 55 56 59 60 public class PdfTemplate extends PdfContentByte { 61 public static final int TYPE_TEMPLATE = 1; 62 public static final int TYPE_IMPORTED = 2; 63 public static final int TYPE_PATTERN = 3; 64 protected int type; 65 66 protected PdfIndirectReference thisReference; 67 68 69 protected PageResources pageResources; 70 71 72 73 protected Rectangle bBox = new Rectangle(0, 0); 74 75 protected PdfArray matrix; 76 77 protected PdfTransparencyGroup group; 78 79 protected PdfOCG layer; 80 81 84 85 protected PdfTemplate() { 86 super(null); 87 type = TYPE_TEMPLATE; 88 } 89 90 95 96 PdfTemplate(PdfWriter wr) { 97 super(wr); 98 type = TYPE_TEMPLATE; 99 pageResources = new PageResources(); 100 pageResources.addDefaultColor(wr.getDefaultColorspace()); 101 thisReference = writer.getPdfIndirectReference(); 102 } 103 104 117 public static PdfTemplate createTemplate(PdfWriter writer, float width, float height) { 118 return createTemplate(writer, width, height, null); 119 } 120 121 static PdfTemplate createTemplate(PdfWriter writer, float width, float height, PdfName forcedName) { 122 PdfTemplate template = new PdfTemplate(writer); 123 template.setWidth(width); 124 template.setHeight(height); 125 writer.addDirectTemplateSimple(template, forcedName); 126 return template; 127 } 128 129 134 135 public void setWidth(float width) { 136 bBox.setLeft(0); 137 bBox.setRight(width); 138 } 139 140 145 146 public void setHeight(float height) { 147 bBox.setBottom(0); 148 bBox.setTop(height); 149 } 150 151 156 public float getWidth() { 157 return bBox.getWidth(); 158 } 159 160 165 166 public float getHeight() { 167 return bBox.getHeight(); 168 } 169 170 public Rectangle getBoundingBox() { 171 return bBox; 172 } 173 174 public void setBoundingBox(Rectangle bBox) { 175 this.bBox = bBox; 176 } 177 178 182 public void setLayer(PdfOCG layer) { 183 this.layer = layer; 184 } 185 186 190 public PdfOCG getLayer() { 191 return layer; 192 } 193 194 public void setMatrix(float a, float b, float c, float d, float e, float f) { 195 matrix = new PdfArray(); 196 matrix.add(new PdfNumber(a)); 197 matrix.add(new PdfNumber(b)); 198 matrix.add(new PdfNumber(c)); 199 matrix.add(new PdfNumber(d)); 200 matrix.add(new PdfNumber(e)); 201 matrix.add(new PdfNumber(f)); 202 } 203 204 PdfArray getMatrix() { 205 return matrix; 206 } 207 208 213 214 public PdfIndirectReference getIndirectReference() { 215 return thisReference; 216 } 217 218 public void beginVariableText() { 219 content.append("/Tx BMC "); 220 } 221 222 public void endVariableText() { 223 content.append("EMC "); 224 } 225 226 231 232 PdfObject getResources() { 233 return getPageResources().getResources(); 234 } 235 236 241 242 PdfStream getFormXObject() throws IOException { 243 return new PdfFormXObject(this); 244 } 245 246 251 252 public PdfContentByte getDuplicate() { 253 PdfTemplate tpl = new PdfTemplate(); 254 tpl.writer = writer; 255 tpl.pdf = pdf; 256 tpl.thisReference = thisReference; 257 tpl.pageResources = pageResources; 258 tpl.bBox = new Rectangle(bBox); 259 tpl.group = group; 260 tpl.layer = layer; 261 if (matrix != null) { 262 tpl.matrix = new PdfArray(matrix); 263 } 264 tpl.separator = separator; 265 return tpl; 266 } 267 268 public int getType() { 269 return type; 270 } 271 272 PageResources getPageResources() { 273 return pageResources; 274 } 275 276 280 public PdfTransparencyGroup getGroup() { 281 return this.group; 282 } 283 284 288 public void setGroup(PdfTransparencyGroup group) { 289 this.group = group; 290 } 291 292 } | Popular Tags |