KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > api > pdf > PDFChartGenerator


1 /***********************************************************************
2  * Copyright (c) 2006 IBM Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ***********************************************************************/

11 package org.eclipse.birt.chart.examples.api.pdf;
12
13 import org.eclipse.birt.chart.device.IDeviceRenderer;
14 import org.eclipse.birt.chart.device.pdf.PDFRendererImpl;
15 import org.eclipse.birt.chart.exception.ChartException;
16 import org.eclipse.birt.chart.factory.GeneratedChartState;
17 import org.eclipse.birt.chart.factory.Generator;
18 import org.eclipse.birt.chart.factory.RunTimeContext;
19 import org.eclipse.birt.chart.model.Chart;
20 import org.eclipse.birt.chart.model.attribute.Bounds;
21 import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
22
23 import com.ibm.icu.util.ULocale;
24
25 /**
26  * Example class that generates a PDF file based on a BIRT Chart Model.
27  *
28  */

29 public class PDFChartGenerator {
30
31     /**
32      * Generates a pdf chart to a file
33      */

34     public static void generateChart(){
35         //Tell chart engine that we are running in stand alone mode. Note running in an eclipse environment.
36
System.setProperty("STANDALONE", "true"); //$NON-NLS-1$ //$NON-NLS-2$
37

38         //Create the chart we want to render
39
Chart cm = ChartModels.createHSChart( );
40         
41         //Create the pdf renderer
42
IDeviceRenderer idr = new PDFRendererImpl();
43
44         try
45         {
46             RunTimeContext rtc = new RunTimeContext( );
47             rtc.setULocale( ULocale.getDefault( ) );
48
49             final Generator gr = Generator.instance( );
50             GeneratedChartState gcs = null;
51             //Set the chart size
52
Bounds bo = BoundsImpl.create( 0, 0, 450, 300 );
53             gcs = gr.build( idr.getDisplayServer( ), cm, bo, null, rtc, null );
54
55             //Specify the file to write to.
56
idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, "test.pdf" ); //$NON-NLS-1$
57

58             //generate the chart
59
gr.render( idr, gcs );
60         }
61         catch ( ChartException ce )
62         {
63             ce.printStackTrace( );
64         }
65     }
66     
67     public static final void main(String JavaDoc argv[]){
68         generateChart();
69     }
70 }
71
Popular Tags