List of usage examples for com.itextpdf.text.pdf PdfContentByte roundRectangle
public void roundRectangle(double x, double y, double w, double h, double r)
From source file:com.vectorprint.report.itext.style.stylers.Shape.java
License:Open Source License
@Override protected void draw(PdfContentByte canvas, float x, float y, float width, float height, String genericTag) { if (getBorderWidth() > 0) { canvas.setLineWidth(getBorderWidth()); canvas.setColorStroke(itextHelper.fromColor((isDrawShadow()) ? getShadowColor() : getBorderColor())); }//w w w.j a v a 2s .c o m if (width == -1) { width = getWidth(); } if (height == -1) { height = getHeight(); } canvas.setColorFill(itextHelper.fromColor((isDrawShadow()) ? getShadowColor() : getColor())); if (isRounded()) { canvas.setLineJoin(PdfContentByte.LINE_JOIN_ROUND); } float xx = x, yy = y; float[] points = getPoints(); float padding = getPadding(); switch (getShape()) { case free: float xdif = x - points[0]; float ydif = y - points[1]; xx = points[0] + xdif; yy = points[1] + ydif; canvas.moveTo(points[0] + xdif, points[1] + ydif); for (int i = 2; i < points.length; i = i + 2) { canvas.lineTo(points[i], points[i + 1]); } break; case bezier: xdif = x - points[0]; ydif = y - points[1]; xx = points[0] + xdif; yy = points[1] + ydif; canvas.moveTo(points[0] + xdif, points[1] + ydif); for (int i = 2; i < points.length; i = i + 4) { canvas.curveTo(points[i] + xdif, points[i + 1] + ydif, points[i + 2] + xdif, points[i + 3] + ydif); } break; case rectangle: if (isClose()) { xx = x - padding; yy = y - padding - height; canvas.rectangle(xx, yy, width + padding * 2, height + padding * 2); } else { canvas.rectangle(x, y, width, height); } break; case roundrectangle: if (isEnclosing()) { xx = x - padding; yy = y - padding - height; canvas.roundRectangle(xx, yy, width + padding * 2, height + padding * 2, getRadius()); } else { canvas.roundRectangle(x, y, width, height, getRadius()); } break; case ellipse: if (isEnclosing()) { xx = x - padding; yy = y - padding - height; canvas.ellipse(xx, yy, x + width + 2 * padding, y + 2 * padding); } else { canvas.ellipse(x, y, x + width, y + height); } break; } if (isClose()) { if (isFill()) { canvas.closePathFillStroke(); } else { canvas.closePathStroke(); } } else { canvas.stroke(); } if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.DEBUG)) { DebugHelper.styleLink(canvas, getStyleClass(), " (styling)", xx, yy, getSettings(), getLayerManager()); } }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
private void insertPinnedComment(float xCoord, float yCoord, String id, String comment, int pageNum, int masterHeight, int masterWidth) throws DocumentException, IOException { int standardHeight = 38; int standardWidth = 130; int lineHeight = 7; if (fontSize == 8) { standardHeight = 48;/*from w w w .j ava 2s .c o m*/ standardWidth = 180; lineHeight = 10; } else if (fontSize == 10) { standardHeight = 70; standardWidth = 210; lineHeight = 12; } // comment box position defines lower-left corner xCoord += 41; // x-coordinate of comment text box yCoord -= 7; // lower offset moves box up float f = (float) 0.4; PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(f); PdfContentByte fg = pds.getOverContent(pageNum); fg.setGState(gs1); fg.setLineWidth(.5f * getRatio(masterHeight, masterWidth, pageNum)); // Calculate additional needed height for the comment, based on length of comment. List<String> lines = createComment(cleanupComment(comment)); int numLines = lines.size(); int commentHeight = (numLines - 1) * lineHeight; // Draw the comment box String color = "0xF2F3E4"; Color c = Color.decode(color); color = "0xFAFAF4"; Color c2 = Color.decode(color); fg.setLineWidth(1f); fg.setColorStroke(new BaseColor(c.getRGB())); fg.setColorFill(new BaseColor(c2.getRGB())); float newCoords[] = pinnedCoords(xCoord, yCoord, standardWidth, standardHeight + commentHeight); fg.roundRectangle(xCoord, newCoords[1], standardWidth, standardHeight + commentHeight, 2f); fg.fillStroke(); //BaseFont bf = BaseFont.createFont(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, true); BaseFont bfb = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, true); fg.setColorFill(BaseColor.RED); gs1.setFillOpacity(0.8f); fg.setGState(gs1); // Adding comment title text Phrase phrase = new Phrase("Comment", new Font(bfb, fontSize)); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - 7, 0); // Adding comment number phrase = new Phrase(id, new Font(bf, fontSize)); float offset = xCoord + 35; if (fontSize == 8) offset = xCoord + 45; else if (fontSize == 10) offset = xCoord + 55; ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, offset, yCoord - 7, 0); /* Remove 10/27/2015 Jon Changkachith // Adding 'comment' label text phrase = new Phrase("Comment", new Font(bfb, fontSize)); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - 20f, 0); */ // Adding comment text int commentYOffset = 32; for (int i = 0; i < lines.size(); i++) { //phrase = new Phrase(lines.get(i), new Font(bf, fontSize)); phrase = composePhrase(lines.get(i), bf, bfb); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - commentYOffset, 0); commentYOffset += lineHeight; } }
From source file:es.clinica.veterinaria.facturas.FacturaPdf.java
private void generateHeader(Document doc, PdfContentByte cb) { try {// w ww . ja v a2s . c o m createHeadings(cb, 150, 790, "Centro Veterinario \"Mascotas\"", 10); createHeadings(cb, 150, 775, "Nombre del profesional", 8); createHeadings(cb, 150, 760, "NIF: 11.111.111-A", 8); createHeadings(cb, 150, 745, "C/ Nombre de la calles, 1", 8); createHeadings(cb, 150, 730, "Nombre de la Ciudad (Provincia)", 8); createHeadings(cb, 150, 715, "Telfono: 600 00 00 00", 8); cb.setLineWidth(1f); // Invoice Header box layout // cb.rectangle(70,600,150,60); cb.roundRectangle(460, 770, 100, 50, 5); //x, y, ancho, alto, round cb.roundRectangle(460, 705, 100, 50, 5); //x, y, ancho, alto, round cb.moveTo(460, 797); // (x,y) cb.lineTo(560, 797); cb.moveTo(460, 732); cb.lineTo(560, 732); cb.stroke(); createHeadings(cb, 480, 804, "FACTURA", 12); createHeadings(cb, 502, 780, "" + factura.getNumero(), 14); createHeadings(cb, 488, 739, "FECHA", 12); createHeadings(cb, 470, 715, new SimpleDateFormat("dd / MM / yyyy").format(factura.getFecha()), 14); cb.setLineWidth(1f); cb.roundRectangle(25, 565, 540, 120, 5); //x, y, ancho, alto, round cb.stroke(); // cb.setGrayStroke(1f); // cb.rectangle(25, 665, 299, 20); //x,y, ancho, alto // cb.setGrayStroke(20f); cb.moveTo(25, 660); // (x,y) cb.lineTo(565, 660); cb.stroke(); createHeadings(cb, 265, 667, "CLIENTE", 12); createCliente(cb, 35, 643, "Nombre: " + factura.getCliente().getFullname(), 11); createCliente(cb, 35, 626, "NIF/CIF: " + factura.getCliente().getNif(), 11); createCliente(cb, 35, 608, "Direccin: " + factura.getCliente().getDireccion(), 11); createCliente(cb, 35, 590, "Ciudad: " + factura.getCliente().getCiudad().getPoblacion() + ", " + factura.getCliente().getCodigopostal() + ", (" + factura.getCliente().getProvincia().getProvincia() + ")", 11); createCliente(cb, 35, 572, "Telfono: " + factura.getCliente().getTelefono(), 11); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:se.billes.pdf.renderer.model.Image.java
License:Open Source License
@Override public void onRender(PdfContentByte cb) throws PdfRenderException { ImageInstance instance = null;//from w ww.j a v a2 s . c o m try { instance = new ImageFactory().getImageByFile(cb, file); } catch (Exception e) { throw new PdfRenderException(e); } float pageHeight = getPage().getPdfDocument().getSize()[1]; float pageWidth = getPage().getPdfDocument().getSize()[0]; float x = 0; float y = 0; float fitHeight = 0f; float imageHeight = 0; float imageWidth = 0; boolean alignImage = false; float[] positions = new BlockFactory().getBoundsInPs(this); float width = positions[2]; float height = positions[3]; com.itextpdf.text.Image image = instance.getImage(); int dpiX = image.getDpiX(); if (dpiX == 0) { dpiX = 300; } if (!new ImageFactory().isPdf(file)) { dpiX = getDotsPerInch(); alignImage = true; // always align jpg } float realPercent = 72f / dpiX * 100; // only jpg if (isScaleToFit()) { image.scaleToFit(width, height); imageHeight = image.getScaledHeight(); imageWidth = image.getScaledWidth(); } else if (isFitContentProportionally()) { image.scaleToFit(width, height); imageHeight = image.getScaledHeight(); imageWidth = image.getScaledWidth(); fitHeight = height - imageHeight; alignImage = true; } else { if (isFillFrameProportionally()) { float percentWidth = width / image.getWidth(); float percentHeight = height / image.getHeight(); realPercent = Math.max(percentHeight, percentWidth) * 100; alignImage = true; if (new ImageFactory().isPdf(file)) { image.scalePercent(realPercent); imageHeight = image.getScaledHeight(); imageWidth = image.getScaledWidth(); fitHeight = height - imageHeight; } } if (isCenterImageToPageWidth() && new ImageFactory().isPdf(file)) { imageWidth = image.getScaledWidth(); float middle = (pageWidth / 2) - (imageWidth / 2); positions[0] = SizeFactory.PostscriptPointsToMillimeters(middle); } if (!new ImageFactory().isPdf(file)) { image.scalePercent(realPercent); imageHeight = image.getScaledHeight(); imageWidth = image.getScaledWidth(); fitHeight = height - imageHeight; } } if (alignImage) { float[] result = handleAlignment(width, imageWidth, height, imageHeight, fitHeight); x = result[0]; y = result[1]; } try { PdfTemplate tp = cb.createTemplate(width, height); image.setAbsolutePosition(x, y); tp.roundRectangle(0, 0, width, height, SizeFactory.millimetersToPostscriptPoints(getRadius())); tp.clip(); tp.newPath(); tp.addImage(image); float left = getPosition()[0]; float top = getPosition()[1]; if (getPage().getPdfDocument().getCutmarks() != null) { left += SizeFactory.CUT_MARK; top -= SizeFactory.CUT_MARK; } cb.addTemplate(tp, SizeFactory.millimetersToPostscriptPoints(left), SizeFactory.millimetersToPostscriptPoints(pageHeight - (top + getPosition()[3]))); if (getBorder() != null) { cb.setLineWidth(SizeFactory.millimetersToPostscriptPoints(getBorder().getThickness())); cb.setColorStroke(getBorder().getBaseColor()); cb.roundRectangle(SizeFactory.millimetersToPostscriptPoints(left), SizeFactory.millimetersToPostscriptPoints(pageHeight - (top + getPosition()[3])), width, height, SizeFactory.millimetersToPostscriptPoints(getRadius())); cb.stroke(); } } catch (Exception e) { throw new PdfRenderException(e); } }