List of usage examples for com.lowagie.text.pdf PdfTemplate rectangle
public void rectangle(float x, float y, float w, float h)
From source file:classroom.filmfestival_c.Movies22.java
public static void main(String[] args) { // step 1/* w ww . j ava2 s . co m*/ Document document = new Document(new Rectangle(WIDTH, HEIGHT)); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FORM)); writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); // top part of the card cb.setColorFill(RED); cb.rectangle(0, mm2pt(57f), WIDTH, HEIGHT - mm2pt(57f)); cb.fill(); cb.setColorFill(BLACK); cb.rectangle(0, mm2pt(61), WIDTH, mm2pt(21f)); cb.fill(); cb.setColorFill(WHITE); Image kubrick = Image.getInstance(KUBRICK); kubrick.scaleToFit(WIDTH, mm2pt(21)); kubrick.setAbsolutePosition(0, mm2pt(61)); cb.addImage(kubrick); Image logo = Image.getInstance(LOGO); logo.scaleToFit(mm2pt(14), mm2pt(14)); logo.setAbsolutePosition(mm2pt(37), mm2pt(65)); cb.addImage(logo); cb.beginText(); cb.setFontAndSize(FONT, 7); cb.showTextAligned(Element.ALIGN_CENTER, "Flanders International Film Festival-Ghent", WIDTH / 2, mm2pt(58.5f), 0); cb.endText(); // bottom part of the card TextField filmfestival = new TextField(writer, new Rectangle(0, 0, WIDTH, mm2pt(9)), "filmfestival"); filmfestival.setBackgroundColor(GRAY); filmfestival.setTextColor(WHITE); filmfestival.setText("www.filmfestival.be"); filmfestival.setFontSize(14); filmfestival.setOptions(TextField.READ_ONLY); filmfestival.setAlignment(Element.ALIGN_CENTER); writer.addAnnotation(filmfestival.getTextField()); cb.beginText(); cb.moveText(mm2pt(1.5f), mm2pt(12)); cb.setFontAndSize(FONT, 21); cb.setColorFill(RED); cb.showText("10"); cb.setColorFill(BLUE); cb.showText("/"); cb.setColorFill(RED); cb.showText("21"); cb.setColorFill(BLUE); cb.showText("OCT"); cb.setColorFill(GREEN); cb.showText("2006"); cb.endText(); cb.setColorStroke(BLUE); cb.moveTo(mm2pt(24.5f), mm2pt(29)); cb.lineTo(mm2pt(24.5f), mm2pt(36)); cb.moveTo(mm2pt(24.5f), mm2pt(48)); cb.lineTo(mm2pt(24.5f), mm2pt(54)); cb.stroke(); // central part of the card PushbuttonField photo = new PushbuttonField(writer, new Rectangle(mm2pt(3), mm2pt(29), mm2pt(24), mm2pt(54)), "photo"); PdfTemplate t1 = cb.createTemplate(mm2pt(21), mm2pt(25)); t1.setColorFill(GRAY); t1.rectangle(0, 0, mm2pt(21), mm2pt(25)); t1.fill(); photo.setTemplate(t1); photo.setLayout(PushbuttonField.LAYOUT_ICON_ONLY); writer.addAnnotation(photo.getField()); TextField type = new TextField(writer, new Rectangle(mm2pt(26), mm2pt(46), WIDTH - mm2pt(1.5f), mm2pt(54)), "type"); type.setTextColor(GRAY); type.setText("TYPE"); type.setFontSize(0); writer.addAnnotation(type.getTextField()); TextField number = new TextField(writer, new Rectangle(mm2pt(26), mm2pt(44), WIDTH - mm2pt(1.5f), mm2pt(48)), "number"); number.setText("N\u00b0 0000000"); number.setFontSize(8); writer.addAnnotation(number.getTextField()); TextField name = new TextField(writer, new Rectangle(mm2pt(26), mm2pt(28), WIDTH - mm2pt(1.5f), mm2pt(40)), "name"); name.setText("Name"); name.setFontSize(8); name.setOptions(TextField.MULTILINE); writer.addAnnotation(name.getTextField()); PushbuttonField barcode = new PushbuttonField(writer, new Rectangle(mm2pt(3), mm2pt(23), WIDTH - mm2pt(3), mm2pt(28)), "barcode"); PdfTemplate t2 = cb.createTemplate(WIDTH - mm2pt(6), mm2pt(5)); t2.setColorFill(GRAY); t2.rectangle(0, 0, WIDTH - mm2pt(6), mm2pt(5)); t2.fill(); barcode.setTemplate(t2); barcode.setLayout(PushbuttonField.LAYOUT_ICON_ONLY); writer.addAnnotation(barcode.getField()); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // step 4 document.close(); }
From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java
License:Open Source License
private PdfTemplate createPasswordLetterTemplate(PdfWriter writer) throws Exception { IWBundle iwb = getIWApplicationContext().getIWMainApplication() .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER); PdfContentByte cb = writer.getDirectContent(); float tempLength = 511f; float tempHeight = getPointsFromMM(40); PdfTemplate template = cb.createTemplate(tempLength, tempHeight); if (addTemplateHeader()) { BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); String mail_zip = iwb.getProperty("commune.mail_zip"); String mail_name = iwb.getProperty("commune.mail_name"); float convLengt = 100f; float convHeight = 60f; template.rectangle(0f, 0f, convLengt, convHeight); template.moveTo(0f, 0f);//from w w w. j a va2s. c o m template.lineTo(convLengt, convHeight); template.moveTo(convLengt, 0f); template.lineTo(0f, convHeight); template.stroke(); template.beginText(); template.setFontAndSize(bf, 11f); template.setTextMatrix(5f, 40f); template.showText(mail_name); template.endText(); template.beginText(); template.setFontAndSize(bf, 11f); template.setTextMatrix(5f, 25f); template.showText(mail_zip); template.endText(); Image porto = Image.getInstance(iwb.getResourcesRealPath() + "/shared/porto_betalt.jpg"); porto.scaleAbsolute(60f, 60f); // Image portoA =Image.getInstance(iwb.getResourcesRealPath()+ // "/shared/porto_a_logo.jpg"); // float Awidth = 2.3f*60f; // portoA.scaleToFit(Awidth,60f); float portoXPos = tempLength - 90f; // float portoAXPos = portoXPos-Awidth-5f; template.addImage(porto, 60f, 0f, 0f, 60f, portoXPos, 0); // template.addImage(portoA,Awidth,0f,0f,60f,portoAXPos,0); } return template; }