Source Code Cross Referenced for ExampleFO2OldStylePrint.java in  » Graphic-Library » fop » embedding » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Graphic Library » fop » embedding 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        /* $Id: ExampleFO2OldStylePrint.java 441942 2006-09-10 11:38:03Z jeremias $ */
019:
020:        package embedding;
021:
022:        // Java
023:        import java.awt.print.PrinterJob;
024:        import java.io.File;
025:        import java.io.IOException;
026:
027:        //JAXP
028:        import javax.xml.transform.Transformer;
029:        import javax.xml.transform.TransformerFactory;
030:        import javax.xml.transform.Source;
031:        import javax.xml.transform.Result;
032:        import javax.xml.transform.stream.StreamSource;
033:        import javax.xml.transform.sax.SAXResult;
034:
035:        // FOP
036:        import org.apache.fop.apps.FOUserAgent;
037:        import org.apache.fop.apps.Fop;
038:        import org.apache.fop.apps.FOPException;
039:        import org.apache.fop.apps.FopFactory;
040:        import org.apache.fop.render.print.PrintRenderer;
041:
042:        /**
043:         * This class demonstrates printing an FO file to a PrinterJob instance.
044:         */
045:        public class ExampleFO2OldStylePrint {
046:
047:            // configure fopFactory as desired
048:            private FopFactory fopFactory = FopFactory.newInstance();
049:
050:            /**
051:             * Prints an FO file using an old-style PrinterJob.
052:             * @param fo the FO file
053:             * @throws IOException In case of an I/O problem
054:             * @throws FOPException In case of a FOP problem
055:             */
056:            public void printFO(File fo) throws IOException, FOPException {
057:
058:                //Set up PrinterJob instance
059:                PrinterJob printerJob = PrinterJob.getPrinterJob();
060:                printerJob.setJobName("FOP Printing Example");
061:
062:                try {
063:                    //Set up a custom user agent so we can supply our own renderer instance
064:                    FOUserAgent userAgent = fopFactory.newFOUserAgent();
065:
066:                    //Set up our own PrintRenderer instance so we can supply a special PrinterJob instance.
067:                    PrintRenderer renderer = new PrintRenderer(printerJob);
068:                    renderer.setUserAgent(userAgent);
069:
070:                    userAgent.setRendererOverride(renderer);
071:
072:                    // Construct fop with desired output format (here, it is set through the user agent)
073:                    Fop fop = fopFactory.newFop(userAgent);
074:
075:                    // Setup JAXP using identity transformer
076:                    TransformerFactory factory = TransformerFactory
077:                            .newInstance();
078:                    Transformer transformer = factory.newTransformer(); // identity transformer
079:
080:                    // Setup input stream
081:                    Source src = new StreamSource(fo);
082:
083:                    // Resulting SAX events (the generated FO) must be piped through to FOP
084:                    Result res = new SAXResult(fop.getDefaultHandler());
085:
086:                    // Start XSLT transformation and FOP processing
087:                    transformer.transform(src, res);
088:
089:                } catch (Exception e) {
090:                    e.printStackTrace(System.err);
091:                    System.exit(-1);
092:                }
093:            }
094:
095:            /**
096:             * Main method.
097:             * @param args command-line arguments
098:             */
099:            public static void main(String[] args) {
100:                try {
101:                    System.out.println("FOP ExampleFO2OldStylePrint\n");
102:                    System.out.println("Preparing...");
103:
104:                    //Setup directories
105:                    File baseDir = new File(".");
106:                    File outDir = new File(baseDir, "out");
107:                    outDir.mkdirs();
108:
109:                    //Setup input and output files            
110:                    File fofile = new File(baseDir, "xml/fo/helloworld.fo");
111:
112:                    System.out.println("Input: XSL-FO (" + fofile + ")");
113:                    System.out
114:                            .println("Output: old-style printing using PrinterJob");
115:                    System.out.println();
116:                    System.out.println("Transforming...");
117:
118:                    ExampleFO2OldStylePrint app = new ExampleFO2OldStylePrint();
119:                    app.printFO(fofile);
120:
121:                    System.out.println("Success!");
122:                } catch (Exception e) {
123:                    e.printStackTrace(System.err);
124:                    System.exit(-1);
125:                }
126:            }
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.