xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Maerki <...@jeremias-maerki.ch>
Subject Re: NullPointerException while printing
Date Sun, 10 Sep 2006 11:34:07 GMT
That seems to be a bug in ExampleFO2OldStylePrint.java. If you
instantiate the Renderer yourself, you also have to set the user agent.
See additional line below. Sorry for the trouble.

On 06.09.2006 10:52:43 flyingscot wrote:
> 
> Hello!
> 
> I have some problems embedding FOP 0.92b with an overridden Print-Renderer,
> similar to the  ExampleFO2OldStylePrint.java example.
> 
> Her is my simplified sourcecode:
> 
> class printFO
> {
>     public static void main(String[] args)
>     {
> 	try {
> 	    PrinterJob printerJob = PrinterJob.getPrinterJob();
> 	    PrintRenderer p_renderer = new PrintRenderer(printerJob);
> 	    
> 	    FopFactory fopFactory = FopFactory.newInstance();
> 	    FOUserAgent foUserAgent= fopFactory.newFOUserAgent();
> 
> 	    foUserAgent.setRendererOverride(p_renderer);

            p_renderer.setUserAgent(foUserAgent);


> 	     
> 	    Fop fop= fopFactory.newFop(MimeConstants.MIME_FOP_PRINT, foUserAgent,
> null);
> 	    File sourcefile=new File(args[0]);
> 	    String baseURL = null;
> 	    
> 	    baseURL = new File(sourcefile.getAbsolutePath()).
> 		getParentFile().toURL().toExternalForm();
> 	    
> 	    foUserAgent.setBaseURL(baseURL);
> 
> 	    Result res = new SAXResult(fop.getDefaultHandler());
> 
>             TransformerFactory factory = TransformerFactory.newInstance();
>             Transformer transformer;
>             
> 	    transformer = factory.newTransformer();
> 
>             // Create a SAXSource from the input Source file
>             Source src = new StreamSource(sourcefile);
> 
>             // Start XSLT transformation and FOP processing
>             transformer.transform(src, res);
> 	} catch (Exception e) {
> 	e.printStackTrace();
> 	}	
>     }
> }

<snip/>

> PS.: My main point is to direct the printer output to a special printer and
> a special tray, so I need this PrinterJob instance. If you have an
> alternative way to do so: please drop me a note!

Well, a better way would be support for the Java Printing System (JPS,
available since J2SE 1.4). If you can make it work with the hint above,
good. Otherwise, someone has to implement support for JPS first. It's
on my personal list but I don't have much "fun time" left lately.


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Mime
View raw message