List of usage examples for com.itextpdf.text Rectangle Rectangle
public Rectangle(final float llx, final float lly, final float urx, final float ury)
Rectangle
-object. From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
/** * prints debug info when property debug is true, calls renderHeader and renderFooter and * {@link Advanced#draw(com.itextpdf.text.Rectangle, java.lang.String) } with {@link Document#getPageSize() } * and null for {@link DefaultStylerFactory#PAGESTYLERS}. * * @param writer// w w w . j a va2s .c om * @param document */ @Override public final void onEndPage(PdfWriter writer, Document document) { super.onEndPage(writer, document); sanitize(writer); try { if (failuresHereAfter || debugHereAfter) { PdfContentByte bg = writer.getDirectContentUnder(); Rectangle rect = writer.getPageSize(); rect.setBackgroundColor(itextHelper .fromColor(getSettings().getColorProperty(new Color(240, 240, 240), "legendbackground"))); bg.rectangle(rect); bg.closePathFillStroke(); } else { for (Advanced a : doForAllPages) { try { if (a.shouldDraw(null)) { a.draw(document.getPageSize(), null); } } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } } } if (!debugHereAfter && getSettings().getBooleanProperty(false, DEBUG)) { PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(document.leftMargin(), document.bottomMargin(), document.right() - document.rightMargin(), document.top() - document.topMargin()); DebugHelper.debugRect(canvas, rect, new float[] { 10, 2 }, 0.3f, getSettings(), stylerFactory.getLayerManager()); } renderHeader(writer, document); maxTagForGenericTagOnPage = ((DefaultElementProducer) elementProducer).getAdvancedTag(); if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.PRINTFOOTER)) { renderFooter(writer, document); } else { log.warning("not printing footer, if you want page footers set " + ReportConstants.PRINTFOOTER + " to true"); } maxTagForGenericTagOnPage = Integer.MAX_VALUE; } catch (VectorPrintException | DocumentException | InstantiationException | IllegalAccessException e) { throw new VectorPrintRuntimeException("failed to create the report header or footer: ", e); } }
From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
private Rectangle imageRectFromChunk(String genericTag, Rectangle rect) { Image r = rectangles.get(genericTag); return new Rectangle(rect.getLeft(), rect.getTop() - r.getScaledHeight() + Y_POSITION_FIX, rect.getLeft() + r.getScaledWidth(), rect.getTop() + Y_POSITION_FIX); }
From source file:com.vectorprint.report.itext.style.stylers.AbstractFieldStyler.java
License:Open Source License
@Override protected void draw(PdfContentByte canvas, float x, float y, float width, float height, String genericTag) throws VectorPrintException { Rectangle box = new Rectangle(x, y, x + width, y - height); PdfFormField pff = null;/*from www .j a v a 2 s . c o m*/ if (getValue(DocumentSettings.WIDTH, Float.class) > 0) { box.setRight(box.getLeft() + getValue(DocumentSettings.WIDTH, Float.class)); } if (getValue(DocumentSettings.HEIGHT, Float.class) > 0) { float diff = box.getHeight() - getValue(DocumentSettings.HEIGHT, Float.class); box.setBottom(box.getBottom() + diff / 2); box.setTop(box.getTop() - diff / 2); } bf.setBox(box); try { List<BaseStyler> stylers = stylerFactory.getStylers(getStyleClass()); List<FormFieldStyler> ffStylers = StyleHelper.getStylers(stylers, FormFieldStyler.class); pff = makeField(); if (FormFieldStyler.FIELDTYPE.BUTTON.equals(getFieldtype())) { for (FormFieldStyler f : ffStylers) { if (f.isParameterSet(Image.URLPARAM)) { pff.setAction(PdfAction.createSubmitForm(f.getValue(Image.URLPARAM, URL.class).toString(), null, PdfAction.SUBMIT_HTML_FORMAT)); break; } } } } catch (IOException | DocumentException | VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } getWriter().addAnnotation(pff); if (stylerFactory.getSettings().getBooleanProperty(false, DEBUG)) { DebugHelper.debugRect(canvas, box, new float[] { 2, 2 }, 0.7f, stylerFactory.getSettings(), elementProducer); DebugHelper.styleLink(canvas, getStyleClass(), "", box.getLeft(), box.getTop(), stylerFactory.getSettings(), elementProducer); } }
From source file:com.vectorprint.report.itext.style.stylers.AdvancedImpl.java
License:Open Source License
/** * An advanced styler may be added as event to a table by {@link StyleHelper#style(java.lang.Object, java.lang.Object, java.util.Collection) } * when the element styled is a table and the {@link EVENTMODE} is ALL or TABLE. This enables drawing near a table. * Calls {@link #draw(com.itextpdf.text.Rectangle, java.lang.String) } with the rectangle of the table and null as genericTag. * * @see EVENTMODE#TABLE// www . j a va 2 s . c om * @param table * @param widths * @param heights * @param headerRows * @param rowStart * @param canvases */ @Override public final void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { final int footer = widths.length - table.getFooterRows(); final int header = table.getHeaderRows(); int columns = widths[header].length - 1; float w = widths[header][columns]; try { tableForeground = isBg() ? canvases[PdfPTable.BASECANVAS] : canvases[PdfPTable.TEXTCANVAS]; draw(new Rectangle(widths[header][0], heights[footer - 1], w, heights[header]), null); tableForeground = null; } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } }
From source file:com.vectorprint.report.itext.style.stylers.AdvancedImpl.java
License:Open Source License
/** * An advanced styler may be added as event to a cell by {@link StyleHelper#style(java.lang.Object, java.lang.Object, java.util.Collection) } * when the element styled is a table and the {@link EVENTMODE} is ALL or CELL. This enables drawing near a cell. * Calls {@link #draw(com.itextpdf.text.Rectangle, java.lang.String) } with the rectangle of the cell and null as genericTag. When * {@link #USEPADDING} is true the rectangle is calculated taking cell padding into account. * * @see EVENTMODE#CELL//from w w w .j av a 2 s. c om * @param cell * @param position * @param canvases */ @Override public final void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { try { tableForeground = isBg() ? canvases[PdfPTable.BASECANVAS] : canvases[PdfPTable.TEXTCANVAS]; Rectangle box = getValue(USEPADDING, Boolean.class) ? new Rectangle(position.getLeft() + cell.getPaddingLeft(), position.getBottom() + cell.getPaddingBottom(), position.getRight() - cell.getPaddingRight(), position.getTop() - cell.getPaddingTop()) : position; draw(box, null); tableForeground = null; } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } }
From source file:com.vectorprint.report.itext.style.stylers.DocumentSettings.java
License:Open Source License
/** * adds a visible signature of 200 / 100 at top left of the first page of the pdf with "verify origin" as reason, the * localhost name as location. Uses MakeSignature.signDetached(psa, as, pks, certificateChain, null, null, null, 0, * MakeSignature.CryptoStandard.CMS)//from ww w . jav a2s .com * * @see #loadKeyStore(char[]) * @see #getKey(java.security.KeyStore, java.lang.String, char[]) } * @param psa * @throws KeyStoreException * @throws NoSuchAlgorithmException * @throws UnrecoverableKeyException * @throws VectorPrintException */ @Override public void configureVisualSignature(PdfSignatureAppearance psa) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, VectorPrintException { psa.setReason("verify origin"); try { psa.setLocation(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException ex) { log.log(Level.WARNING, "unable to set location for pdf signature", ex); } char[] pw = getValue(KEYSTORE_PASSWORD, char[].class); char[] clone = pw.clone(); KeyStore ks = loadKeyStore(pw); PrivateKey key = getKey(ks, (String) ks.aliases().nextElement(), clone); Certificate[] certificateChain = ks.getCertificateChain((String) ks.aliases().nextElement()); PrivateKeySignature pks = new PrivateKeySignature(key, getValue(DIGESTPARAM, DIGESTALGORITHM.class).name(), "BC"); ExternalDigest as = new BouncyCastleDigest(); psa.setVisibleSignature(new Rectangle(0, getHeight() - 100, 200, getHeight()), 1, "signature"); try { MakeSignature.signDetached(psa, as, pks, certificateChain, null, null, null, 0, MakeSignature.CryptoStandard.CMS); } catch (IOException | DocumentException | GeneralSecurityException ex) { throw new VectorPrintException(ex); } }
From source file:com.vectorprint.report.itext.style.stylers.Image.java
License:Open Source License
/** * Adds an image to a canvas applying the transform if it is not null. Calls {@link DebugHelper#debugAnnotation(com.itextpdf.text.Rectangle, java.lang.String, com.itextpdf.text.pdf.PdfWriter) * }.//from w w w . j a v a 2s.c om * * @param tf may be null, the transform matrix to apply to the image * @param img * @param canvas * @throws DocumentException */ public void addToCanvas(float[] tf, com.itextpdf.text.Image img, PdfContentByte canvas) throws DocumentException { if (tf == null) { canvas.addImage(img); } else { canvas.addImage(img, img.getWidth() * tf[TRANSFORMMATRIX.SCALEX.getIndex()], tf[TRANSFORMMATRIX.SHEARX.getIndex()], tf[TRANSFORMMATRIX.SHEARY.getIndex()], img.getHeight() * tf[TRANSFORMMATRIX.SCALEY.getIndex()], img.getAbsoluteX() + tf[TRANSFORMMATRIX.TRANSLATEX.getIndex()], img.getAbsoluteY() + tf[TRANSFORMMATRIX.TRANSLATEY.getIndex()]); } if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.DEBUG) && !isDrawShadow()) { if (tf == null) { DebugHelper .debugAnnotation( new Rectangle(img.getAbsoluteX(), img.getAbsoluteY(), img.getAbsoluteX() + img.getWidth(), img.getAbsoluteY() + img.getHeight()), getStyleClass(), getWriter()); } else { DebugHelper.debugAnnotation( new Rectangle(img.getAbsoluteX() + tf[TRANSFORMMATRIX.TRANSLATEX.getIndex()], img.getAbsoluteY() + tf[TRANSFORMMATRIX.TRANSLATEY.getIndex()], img.getAbsoluteX() + tf[TRANSFORMMATRIX.TRANSLATEX.getIndex()] + img.getWidth() * tf[TRANSFORMMATRIX.SCALEX.getIndex()], img.getAbsoluteY() + tf[TRANSFORMMATRIX.TRANSLATEY.getIndex()] + img.getHeight() * tf[TRANSFORMMATRIX.SCALEY.getIndex()]), getStyleClass(), getWriter()); } } }
From source file:com.vectorprint.report.itext.style.stylers.ImportTiff.java
License:Open Source License
protected void drawOnPage(com.itextpdf.text.Image img) throws VectorPrintException { /*/*from w ww .j a v a 2 s . c o m*/ * we call draw here to use the positioning and shadow intelligence of the AbstractPositining styler. * this styler uses the top left corner of the argument rectangle as its positioning base. * therefore we call this method with the image rectangle moved down by its height, the effect is * that the image will be positioned as expected. */ draw(new Rectangle(img.getLeft(), img.getBottom() - img.getHeight(), img.getRight(), img.getBottom()), null); }
From source file:com.vectorprint.report.itext.style.stylers.SimpleColumns.java
License:Open Source License
/** * calls {@link #getPreparedCanvas() } to create a new {@link ColumnText#ColumnText(com.itextpdf.text.pdf.PdfContentByte) * } and calculates column Rectangles based on parameters. * * @return/* w w w. java2s . co m*/ * @throws VectorPrintException */ protected ColumnText prepareColumns() throws VectorPrintException { ct = new ColumnText(getPreparedCanvas()); float width = getRight() - getLeft(); float colWidth = (width - (getNumColumns() - 1) * getSpacing()) / getNumColumns(); for (int i = 0; i < getNumColumns(); i++) { float left = (i == 0) ? getLeft() : getLeft() + colWidth * i + getSpacing() * i; float right = (i == 0) ? getLeft() + colWidth : getLeft() + colWidth * i + getSpacing() * i + colWidth; int shift = i * 4; columns.add(new Rectangle(left, getValue(BOTTOM, Float.class), right, getValue(TOP, Float.class))); } return ct; }
From source file:com.vectorprint.report.itext.style.ZebraStripes.java
License:Open Source License
@Override public void tableLayout(final PdfPTable table, final float[][] widths, final float[] heights, final int headerRows, final int rowStart, final PdfContentByte[] canvases) { rowsDealtWith += widths.length;/* ww w. j av a 2 s . c o m*/ final int footer = widths.length - table.getFooterRows(); final int header = table.getHeaderRows(); int columns = widths[header].length - 1; float w = widths[header][columns]; int i = 0; boolean up = true; setCurrentBackGround(oddColor); for (int row = header; row < footer; row++) { if (row >= footer - getEndRowsToSkip()) { continue; } paintRow(row, new Rectangle(widths[row][0], heights[row + 1], w, heights[row]), canvases, row == footer - 1, header == row); if (row < footer - 1 - getEndRowsToSkip()) { if (up) { i++; if (i == alternate) { setCurrentBackGround(evenColor); up = false; } } else { i--; if (i == 0) { setCurrentBackGround(oddColor); up = true; } } } } }