See attached SVG file for an example (the code to render to a PDF is at http://itextpdf.com/examples/iia.php?id=263). The blue text is opaque in the SVG, but in the PDF it has the alpha of the circle sector.
I also reproduced the problem with some simple code that directly draws on PdfGraphics2D, see attached Java class. What seems to happen is that with some combinations of create() and setClip(), PdfGraphics2D gets into a state in which currentFillGState and the actual GState in the document are desynchronized.
We are currently using iText 2.1.7, but 5.3.3 has the same problem.Can anyone confirm that this is a bug in PdfGraphics2D? Any ideas to workaround it?
Thanks, Lucian
import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; import com.itextpdf.awt.PdfGraphics2D; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfStream; import com.itextpdf.text.pdf.PdfWriter; public class PdfGraphics2DSample { public static void main(String[] args) throws DocumentException, IOException { awt(new File("result.png")); pdf(new File("result.pdf")); } private static void pdf(File out) throws DocumentException, FileNotFoundException { Document document = new Document(new Rectangle(500, 500)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(out)); writer.setCompressionLevel(PdfStream.NO_COMPRESSION); document.open(); PdfContentByte canvas = writer.getDirectContent(); Graphics2D g2 = new PdfGraphics2D(canvas, 400, 400); paint(g2); g2.dispose(); document.close(); } private static void awt(File out) throws IOException { BufferedImage image = new BufferedImage(400, 400, BufferedImage.TYPE_INT_ARGB); paint(image.createGraphics()); ImageIO.write(image, "png", out); } private static void paint(Graphics2D graphics) { Graphics2D g2 = (Graphics2D) graphics.create(); g2.setClip(0, 0, 100, 100); g2.setPaint(Color.BLUE); g2.fillOval(0, 0, 200, 200); graphics.setPaint(new Color(0xff, 0, 0, 0x20)); graphics.fillRect(120, 120, 100, 100); g2 = (Graphics2D) graphics.create(); g2.setClip(240, 240, 100, 100); g2.setPaint(Color.BLUE); g2.fillOval(240, 240, 200, 200); } }
<<attachment: alpha.svg>>
------------------------------------------------------------------------------ Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too! http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php