List of usage examples for com.lowagie.text Rectangle Rectangle
public Rectangle(float llx, float lly, float urx, float ury)
Rectangle
-object. From source file:org.geomajas.plugin.print.component.PdfContext.java
License:Open Source License
/** * Return the text box for the specified text and font. * * @param text text// w w w.j a v a2 s . co m * @param font font * @return text box */ public Rectangle getTextSize(String text, Font font) { template.saveState(); // get the font DefaultFontMapper mapper = new DefaultFontMapper(); BaseFont bf = mapper.awtToPdf(font); template.setFontAndSize(bf, font.getSize()); // calculate text width and height float textWidth = template.getEffectiveStringWidth(text, false); float ascent = bf.getAscentPoint(text, font.getSize()); float descent = bf.getDescentPoint(text, font.getSize()); float textHeight = ascent - descent; template.restoreState(); return new Rectangle(0, 0, textWidth, textHeight); }
From source file:org.geomajas.plugin.print.component.PdfContext.java
License:Open Source License
/** * Converts an absolute rectangle to a relative one wrt to the current coordinate system. * * @param rect absolute rectangle//from w w w. ja v a2s.co m * @return relative rectangle */ public Rectangle toRelative(Rectangle rect) { return new Rectangle(rect.getLeft() - origX, rect.getBottom() - origY, rect.getRight() - origX, rect.getTop() - origY); }
From source file:org.geomajas.plugin.print.parser.RectangleConverter.java
License:Open Source License
@Override public Object fromString(String str) { StringTokenizer st = new StringTokenizer(str, ","); if (st.countTokens() < 4) { throw new IllegalArgumentException("Not enough tokens (<4) in rectangle " + str); }//w w w . ja v a2s . c o m float left = Float.parseFloat(st.nextToken()); float bottom = Float.parseFloat(st.nextToken()); float right = Float.parseFloat(st.nextToken()); float top = Float.parseFloat(st.nextToken()); return new Rectangle(left, bottom, right, top); }
From source file:org.geomajas.plugin.printing.command.print.PrintGetTemplateCommand.java
License:Open Source License
private float getPageSizeRelativeToA3(PrintGetTemplateRequest request) { Rectangle r;//from w w w. j ava 2 s. c om if (request.getPageSize() != null) { r = PageSize.getRectangle(request.getPageSize()); } else { float width = request.getTemplate().getPage().getLayoutConstraint().getWidth(); float height = request.getTemplate().getPage().getLayoutConstraint().getHeight(); r = new Rectangle(0, 0, width, height); } return (r.getWidth() / PageSize.A3.getWidth() + r.getHeight() / PageSize.A3.getHeight()) / 2; }
From source file:org.mapfish.print.ChunkDrawer.java
License:Open Source License
public void tableLayout(PdfPTable table, float widths[][], float heights[], int headerRows, int rowStart, PdfContentByte[] canvases) {/*ww w. j a v a 2s .c om*/ PdfContentByte dc = canvases[PdfPTable.LINECANVAS]; Rectangle rect = new Rectangle(widths[0][0], heights[1], widths[0][1], heights[0]); render(rect, dc); }
From source file:org.mapfish.print.config.layout.MapBlock.java
License:Open Source License
public void render(PJsonObject params, PdfElement target, RenderingContext context) throws DocumentException { final Transformer transformer = createTransformer(context, params); final MapChunkDrawer drawer = new MapChunkDrawer(context.getCustomBlocks(), transformer, overviewMap, params, context, getBackgroundColorVal(context, params), name); if (isAbsolute()) { final int absX = getAbsoluteX(context, params); final int absY = getAbsoluteY(context, params); context.getCustomBlocks().addAbsoluteDrawer(new PDFCustomBlocks.AbsoluteDrawer() { public void render(PdfContentByte dc) { final Rectangle rectangle = new Rectangle(absX, absY - transformer.getPaperH(), absX + transformer.getPaperW(), absY); drawer.render(rectangle, dc); }/*from w w w. ja v a 2s .c om*/ }); } else { target.add(PDFUtils.createPlaceholderTable(transformer.getPaperW(), transformer.getPaperH(), spacingAfter, drawer, align, context.getCustomBlocks())); } }
From source file:org.mapfish.print.PDFCustomBlocks.java
License:Open Source License
private void addHeader(Document document, PdfContentByte dc) { if (header != null) { Rectangle rectangle = new Rectangle(document.left(), document.top(), document.right(), document.top() + header.getHeight()); header.render(rectangle, dc, headerParams, context); }/*from www . j a v a 2 s . com*/ }
From source file:org.mapfish.print.PDFCustomBlocks.java
License:Open Source License
private void addFooter(Document document, PdfContentByte dc) { if (footer != null) { Rectangle rectangle = new Rectangle(document.left(), document.bottom() - footer.getHeight(), document.right(), document.bottom()); footer.render(rectangle, dc, footerParams, context); }/*from w w w . j a v a 2s .com*/ }
From source file:org.mapfish.print.PDFCustomBlocks.java
License:Open Source License
private void addErrors(PdfWriter writer) { if (errors.size() > 0) { StringBuilder errorTxt = new StringBuilder(); for (int i = 0; i < errors.size(); i++) { Exception exception = errors.get(i); errorTxt.append(exception).append("\n"); }//from ww w . ja v a 2s . c o m errors.clear(); final Rectangle rect = new Rectangle(20f, 40f, 40f, 60f); final PdfAnnotation annotation = PdfAnnotation.createText(writer, rect, "Error", errorTxt.toString(), false, "Note"); writer.addAnnotation(annotation); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Added an annotation for errors"); } } }
From source file:org.nuxeo.ecm.platform.signature.core.sign.SignatureServiceImpl.java
License:Open Source License
/** * @since 5.8 Provides the position rectangle for the next certificate. An assumption is made that all previous * certificates in a given PDF were placed using the same technique and settings. New certificates are added * depending of signature layout contributed. *///from w ww . j av a2 s . co m protected Rectangle getNextCertificatePosition(PdfReader pdfReader, List<X509Certificate> pdfCertificates) throws SignException { int numberOfSignatures = pdfCertificates.size(); Rectangle pageSize = pdfReader.getPageSize(PAGE_TO_SIGN); // PDF size float width = pageSize.getWidth(); float height = pageSize.getHeight(); // Signature size float rectangleWidth = width / getSignatureLayout().getColumns(); float rectangeHeight = height / getSignatureLayout().getLines(); // Signature location int column = numberOfSignatures % getSignatureLayout().getColumns() + getSignatureLayout().getStartColumn(); int line = numberOfSignatures / getSignatureLayout().getColumns() + getSignatureLayout().getStartLine(); if (column > getSignatureLayout().getColumns()) { column = column % getSignatureLayout().getColumns(); line++; } // Skip rectangle display If number of signatures exceed free locations // on pdf layout if (line > getSignatureLayout().getLines()) { return new Rectangle(0, 0, 0, 0); } // make smaller by page margin float topRightX = rectangleWidth * column; float bottomLeftY = height - rectangeHeight * line; float bottomLeftX = topRightX - SIGNATURE_FIELD_WIDTH; float topRightY = bottomLeftY + SIGNATURE_FIELD_HEIGHT; // verify current position coordinates in case they were // misconfigured validatePageBounds(pdfReader, 1, bottomLeftX, true); validatePageBounds(pdfReader, 1, bottomLeftY, false); validatePageBounds(pdfReader, 1, topRightX, true); validatePageBounds(pdfReader, 1, topRightY, false); Rectangle positionRectangle = new Rectangle(bottomLeftX, bottomLeftY, topRightX, topRightY); return positionRectangle; }