xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Yves Tinevez <tine...@pasteur.fr>
Subject Trouble going from Graphics2D to PDF, with PDFDocumentGraphics2D
Date Thu, 21 Jul 2011 12:25:43 GMT
Dear list,

I am struggling a lot with exporting a swing figure based on  
Graphics2D drawing to PDF using FOP. After a lot of fiddling and  
googling, I turn to you with hope.

Basically, I have a panel that is painted with a draw(Graphics2D g2d,  
Rectangle bounds) methods (in my specific case it is a JFreeChart  
plot) that I try to export as pdf. I have tried to do that in two  
ways, leading to 2 problems. The first way I investigated was based on  

I came with the following snippet in charge of the exporting:

	 * Exports a JFreeChart to a PDF file.
	 * <p>
	 * We use a dirty hack for that: we first export to a physical SVG  
file, reload it, and
	 * use Apache FOP PDF transcoder to convert it to pdfs. It only works  
partially, for
	 * the text ends up in not being selectable in the pdf.
	 * @param chart JFreeChart to export
	 * @param bounds the dimensions of the viewport
	 * @param pdfFile the output file.
	 * @throws IOException if writing the pdfFile fails.
	public static void exportChartAsPDF(JFreeChart chart, Rectangle  
bounds, File pdfFile) throws IOException, TranscoderException {
		PDFDocumentGraphics2D doc = new PDFDocumentGraphics2D(false);
		doc.setGraphicContext(new GraphicContext());
		OutputStream stream = new FileOutputStream(pdfFile);
		doc.setupDocument(stream, bounds.width, bounds.height);
		chart.draw(doc, bounds );

It turned out the execution of this method works fine, as long as I  
use standard fonts (Helvetica not Arial): I get a pdf file, which can  
be opened in the Mac OSX's Preview for instance, but not in Acrobat  
In the later, I receive a message stating that the pdf has "some"  
error and that I should get contacted, and some parts of the pdf are  
not drawn. I attach an example of this pdf to this mail.

Could you tip me on what I did wrong there?

The versions of the libs I used:

- FOP: SVN tags/fop-0_94
- Java:
   os.arch => x86_64
   os.name => Mac OS X
   os.version => 10.5.8
   java.version => 1.6.0_26
   java.vendor => Apple Inc.
   java.runtime.name => Java(TM) SE Runtime Environment
   java.runtime.version => 1.6.0_26-b03-384-9M3425
   java.vm.name => Java HotSpot(TM) 64-Bit Server VM
   java.vm.version => 20.1-b02-384
   java.vm.vendor => Apple Inc.


View raw message