List of usage examples for com.lowagie.text.pdf PdfContentByte lineTo
public void lineTo(float x, float y)
From source file:br.org.archimedes.io.pdf.elements.LineExporter.java
License:Open Source License
public void exportElement(Line line, Object outputObject) throws IOException { PDFWriterHelper helper = (PDFWriterHelper) outputObject; PdfContentByte cb = helper.getPdfContentByte(); Point initial = helper.modelToDocument(line.getInitialPoint()); Point ending = helper.modelToDocument(line.getEndingPoint()); float x = (float) initial.getX(); float y = (float) initial.getY(); cb.moveTo(x, y);// ww w . j ava 2s .c o m x = (float) ending.getX(); y = (float) ending.getY(); cb.lineTo(x, y); cb.stroke(); }
From source file:br.org.archimedes.io.pdf.elements.LinePointsExporter.java
License:Open Source License
/** * @param points/* w w w .ja va2 s .c o m*/ * The points that form the line within the helper view area */ public void exportLine(List<Point> points) { PdfContentByte cb = helper.getPdfContentByte(); if (points != null && points.size() == 2) { Point initial = points.get(0); Point ending = points.get(1); float x = (float) initial.getX(); float y = (float) initial.getY(); cb.moveTo(x, y); x = (float) ending.getX(); y = (float) ending.getY(); cb.lineTo(x, y); cb.stroke(); } }
From source file:ch.gpb.elexis.kgexporter.pdf.HeaderFooterPageEvent.java
License:Open Source License
public void onStartPage(PdfWriter writer, Document document) { Rectangle rect = writer.getBoxSize("art"); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(sbHeader), rect.getLeft(), rect.getTop(), 0); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, new Phrase(sDate), rect.getRight(), rect.getTop(), 0); PdfContentByte cb = writer.getDirectContentUnder(); //cb.rectangle(document.left(), document.top(), // document.right() - document.left(), document.top() - 25); /*/*from w w w . j a v a 2s . c o m*/ System.out.println("l: " + document.left()); System.out.println("r: " + document.right()); System.out.println("t: " + document.top()); System.out.println("b: " + document.bottom()); l: 36.0 r: 559.0 t: 806.0 b: 36.0 */ //Rectangle rect2 = new Rectangle(document.top() - 36, document.top() - 36, 559, 1); /* float l = 36f; float r = 36f; float t = 559f; float b = 2f; Rectangle rect2 = new Rectangle(l, r, t, b); //Rectangle rect2 = new Rectangle(36, 36, 559, 1); rect2.setBorder(Rectangle.BOTTOM); rect2.setBorderWidth(0.5f); cb.rectangle(rect2); //cb.setColorStroke(Color.BLACK); */ /* for (int i = 30; i > 0; i--) { System.err.println((float) i / 10); cb.setLineWidth((float) i / 10); cb.moveTo(36, 806 - (5 * i)); cb.lineTo(400, 806 - (5 * i)); cb.stroke(); } cb.moveTo(10, 50); cb.lineTo(559, 50); */ cb.setLineWidth(0.5f); cb.moveTo(30, 791); cb.lineTo(559, 791); cb.stroke(); }
From source file:ch.gpb.elexis.kgexporter.pdf.HeaderFooterPageEvent.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { Rectangle rect = writer.getBoxSize("art"); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(this.sbFooter), rect.getLeft(), rect.getBottom(), 0); /*//from w w w .j a v a2 s. co m ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("Bottom Right"), rect.getRight(), rect.getBottom(), 0); */ PdfContentByte cb = writer.getDirectContentUnder(); cb.setLineWidth(0.5f); cb.moveTo(30, 50); cb.lineTo(559, 50); cb.stroke(); }
From source file:classroom.filmfestival_c.Movies19.java
protected static void drawGrid(PdfWriter writer, List<String> places, String day, float left, float column_width, float top, float row_height) { // CANVAS/*www. j a v a 2 s . com*/ PdfContentByte directcontent = writer.getDirectContent(); Rectangle art = writer.getBoxSize("art"); // LINES directcontent.setLineWidth(1); float bottom = art.getTop(); // rows int rows = places.size(); for (int i = 0; i <= rows; i++) { directcontent.moveTo(art.getLeft(), art.getTop() - (i * row_height)); directcontent.lineTo(art.getRight(), art.getTop() - (i * row_height)); bottom = art.getTop() - (i * row_height); } // Rectangle directcontent.moveTo(art.getLeft(), art.getTop()); directcontent.lineTo(art.getLeft(), bottom); directcontent.moveTo(left, art.getTop()); directcontent.lineTo(left, bottom); directcontent.moveTo(art.getLeft() + (COLUMNS * column_width), art.getTop()); directcontent.lineTo(art.getLeft() + (COLUMNS * column_width), bottom); directcontent.stroke(); // columns directcontent.saveState(); directcontent.setLineWidth(0.3f); directcontent.setColorStroke(SILVER); directcontent.setLineDash(3, 1); for (int i = 2; i < COLUMNS; i++) { directcontent.moveTo(art.getLeft() + (i * column_width), art.getTop()); directcontent.lineTo(art.getLeft() + (i * column_width), bottom); } directcontent.stroke(); directcontent.restoreState(); // TEXT // date directcontent.beginText(); directcontent.setFontAndSize(FONT, 12); directcontent.showTextAligned(Element.ALIGN_RIGHT, day, art.getLeft() - 5, art.getTop(), 90); directcontent.endText(); // time for (int i = 1; i < COLUMNS; i++) { directcontent.beginText(); directcontent.setFontAndSize(FONT, 8); directcontent.showTextAligned(Element.ALIGN_LEFT, TIME[i - 1], art.getLeft() + (i * column_width) + 5, top + 5, 90); directcontent.endText(); } // places for (int i = 0; i < rows; i++) { directcontent.beginText(); directcontent.setFontAndSize(FONT, 12); directcontent.showTextAligned(Element.ALIGN_CENTER, places.get(i), art.getLeft() + 16, art.getTop() - ((i + 0.5f) * row_height), 90); directcontent.endText(); } }
From source file:classroom.filmfestival_c.Movies19.java
protected static void drawMovie(PdfWriter writer, FestivalScreening screening, List<String> places, float minute, float left, float top, float row_height) throws DocumentException { FilmTitle movie = screening.getFilmTitle(); // defining the rectangle int place = places.indexOf(screening.getId().getPlace()); float llx, urx, lly, ury; llx = left + minute * getMinutesAfter930(screening); urx = llx + minute * (screening.getShortfilm() + movie.getDuration()); ury = top - place * row_height;/* www .j a va 2 s . co m*/ lly = top - ((place + 1) * row_height); // FOREGROUND PdfContentByte foreground = writer.getDirectContent(); // rectangle foreground.setColorStroke(BLACK); foreground.setLineWidth(1); foreground.moveTo(urx, lly); foreground.lineTo(llx, lly); foreground.lineTo(llx, ury); foreground.lineTo(urx, ury); foreground.closePathStroke(); // title ColumnText ct = new ColumnText(foreground); ct.setSimpleColumn(new Phrase(movie.getTitle(), SMALLEST), llx, lly, urx, ury, 14, Element.ALIGN_CENTER); ct.go(); // BACKGROUND PdfContentByte background = writer.getDirectContentUnder(); // draw background background.setColorFill(getColor(movie)); background.moveTo(urx, lly); background.lineTo(llx, lly); background.lineTo(llx, ury); background.lineTo(urx, ury); background.fill(); // draw a white P for press screenings if (screening.getPress() == 1) { background.saveState(); background.beginText(); background.setFontAndSize(FONT, 24); background.setColorFill(WHITE); background.showTextAligned(Element.ALIGN_CENTER, "P", (llx + urx) / 2f, (lly + ury) / 2f - 12, 0); background.endText(); background.restoreState(); } // draw shortfilm background.setColorStroke(WHITE); if (screening.getShortfilm() > 0) { background.moveTo(llx + (minute * screening.getShortfilm()), lly); background.lineTo(llx + (minute * screening.getShortfilm()), ury); background.stroke(); } }
From source file:classroom.filmfestival_c.Movies22.java
public static void main(String[] args) { // step 1// w w w . ja va2 s. c om 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:com.actelion.research.spiritapp.print.CagePrinterPDF.java
License:Open Source License
private static void drawCageSeparation(Document doc, PdfContentByte canvas) { canvas.setLineWidth(1f);//from w ww .ja v a 2 s. co m canvas.setColorStroke(Color.BLACK); canvas.moveTo(0, doc.getPageSize().getHeight() / 2); canvas.lineTo(doc.getPageSize().getWidth(), doc.getPageSize().getHeight() / 2); canvas.moveTo(doc.getPageSize().getWidth() / 4, 0); canvas.lineTo(doc.getPageSize().getWidth() / 4, doc.getPageSize().getHeight()); canvas.moveTo(2 * doc.getPageSize().getWidth() / 4, doc.getPageSize().getBottom()); canvas.lineTo(2 * doc.getPageSize().getWidth() / 4, doc.getPageSize().getHeight()); canvas.moveTo(3 * doc.getPageSize().getWidth() / 4, 0); canvas.lineTo(3 * doc.getPageSize().getWidth() / 4, doc.getPageSize().getHeight()); canvas.stroke(); }
From source file:com.estate.pdf.Page.java
protected void drawLine(float x1, float y1, float x2, float y2, Color color) { PdfContentByte cb = writer.getDirectContentUnder(); // Set our line color cb.setColorStroke(color);//from w ww . j a va 2 s.c om cb.setLineWidth(.75f); // do the line cb.moveTo(x1, y1); cb.lineTo(x2, y2); cb.stroke(); }
From source file:com.estate.pdf.Page.java
protected void drawSpacingGrid(Rectangle rct, float spacing, Color color) { PdfContentByte cb = writer.getDirectContentUnder(); cb.setLineWidth(.25f);/*w w w. j av a 2s . co m*/ cb.setColorStroke(color); for (float x = 0; x < rct.getRight(); x += spacing) { cb.moveTo(x, 0); cb.lineTo(x, rct.getTop()); } for (float y = 0; y < rct.getTop(); y += spacing) { cb.moveTo(0, y); cb.lineTo(rct.getRight(), y); } cb.stroke(); }