List of usage examples for com.itextpdf.text.pdf PdfContentByte transform
public void transform(final java.awt.geom.AffineTransform af)
From source file:com.vectorprint.report.itext.style.stylers.AdvancedImpl.java
License:Open Source License
/** * get a canvas for drawing, prepared according to settings * * @see #draw(com.itextpdf.text.Rectangle, java.lang.String) * @return/*ww w . j a v a 2 s . c o m*/ */ protected final PdfContentByte getPreparedCanvas(float opacity) { needRestore = false; PdfContentByte canvas = (tableForeground != null) ? tableForeground : (isBg()) ? getWriter().getDirectContentUnder() : getWriter().getDirectContent(); String layerName = getLayerName(); BLENDMODE blend = getBlend(); if (getWriter().getPDFXConformance() == PdfWriter.PDFX1A2001) { // check blend, opacity, layers if (!PdfGState.BM_NORMAL.equals(blend.getBlend()) && !PdfGState.BM_COMPATIBLE.equals(blend.getBlend())) { throw new VectorPrintRuntimeException("blend not supported in PDF/X-1a: " + blend); } if (layerName != null) { throw new VectorPrintRuntimeException("layers not supported in PDF/X-1a: " + layerName); } if (opacity < 1) { throw new VectorPrintRuntimeException("opacity not supported in PDF/X-1a: " + opacity); } } if (layerName != null) { layerManager.startLayerInGroup(layerName, canvas); } // pgs.setAlphaIsShape(true); if (opacity <= 1) { // PdfShading shading = PdfShading.simpleAxial(getWriter(), 0, 0, getDocument().right() - getDocument().getPageSize().getWidth() * 0.6f, getDocument().top() - getDocument().getPageSize().getHeight() * 0.6f, Color.green, Color.orange,true,true); // canvas.paintShading(shading); canvas.saveState(); needRestore = true; PdfGState pgs = new PdfGState(); pgs.setFillOpacity(opacity); pgs.setStrokeOpacity(opacity); canvas.setGState(pgs); } if (!BLENDMODE.NORMAL.equals(blend)) { if (!needRestore) { canvas.saveState(); needRestore = true; } PdfGState pgs = new PdfGState(); pgs.setBlendMode(blend.getBlend()); canvas.setGState(pgs); } if (getTransform() != null && !(this instanceof Image)) { canvas.transform(new AffineTransform(getTransform())); } return canvas; }
From source file:com.vectorprint.report.itext.style.stylers.Underline.java
License:Open Source License
@Override public void draw(Rectangle rect, String genericTag) throws VectorPrintException { if (genericTag == null) { if (log.isLoggable(Level.FINE)) { log.fine("not drawing underline because genericTag is null (no data for underline)"); }//from www . jav a2s .c o m return; } DelayedData delayed = getDelayed(genericTag); PdfContentByte canvas = getPreparedCanvas(); try { com.itextpdf.text.Font f = delayed.getChunk().getFont(); canvas.setColorStroke((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor())); canvas.setLineWidth(getLineWidth()); if (delayed.getChunk().getTextRise() != 0) { canvas.transform(AffineTransform.getTranslateInstance(0, delayed.getChunk().getTextRise())); } HashMap<String, Object> attributes = delayed.getChunk().getAttributes(); if (attributes != null && attributes.containsKey(Chunk.SKEW)) { log.warning("lines under skewed text may not be at the correct position"); } canvas.moveTo(rect.getLeft(), rect.getBottom()); canvas.lineTo(rect.getLeft() + rect.getWidth(), rect.getBottom()); canvas.stroke(); } catch (Exception ex) { resetCanvas(canvas); throw new VectorPrintException(ex); } resetCanvas(canvas); }