Interesting coincidence that I've done a few things in PrintRenderer
today. With some fresh memory about this whole thing it was easy to come
up with support for JPS, at least in FOP Trunk...

(some of the stuff below may be a bit fop-dev-ish. Forgive me.)

The current PrintRenderer uses java.awt.print, i.e. the "old" Java
printing API. Because the printing is started within the stopRenderer()
method it is not possible in 0.94 to use PrintRenderer with JPS even
though PrintRenderer readily implements Pageable and Printable.

If you want to create a temporary solution with minimal effort, you
could copy PrintRenderer.java and adjust it to JPS. That will work, is
easy to do but is not a beautiful solution.

I thought it should be possible to turn the PrintRenderer into a pure
Pageable without active parts (i.e. it does not call PrintJob.print() or
DocPrintJob.print()). That would make it usable for both java.awt.print
and JPS.

The best approach was to create a new renderer: PageableRenderer. This
should only implement Pageable and provide the from/to and odd/even
functionality that the PrintRenderer offers. PrintRenderer can then
be derived from the PageableRenderer while preserving its original
behaviour.

This can now be found in FOP Trunk. I've added a minimal example, too:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2JPSPrint.java?view=markup

If you want to port this back to 0.94, you can try. Should be possible,
too, without too many problems. The relevant changes are:
http://svn.apache.org/viewvc?rev=649279&view=rev
http://svn.apache.org/viewvc?rev=649285&view=rev

I'll be grateful for feedback on this as I don't have a real-life
use-case for this, unfortunately, in which I could test this. It was
simply fun to implement. ;-) HTH

On 17.04.2008 19:20:30 David J wrote:
> 
> We are upgrading to FOP 0.94 from 0.20.5 (on Java 1.5).  I am new to java
> printing in general, so any help in pointing me to the solution is greatly
> appreciated.
> 
> My goal is to print directly to a printer from my java program (I have
> already generated an FO document) with printer parameters that have already
> been set up (so no user interaction for this process).
> 
> We had the following code working in FOP 0.20.5:
>     
> /**
> * Renders and prints a source XSL-FO document to specified print job
> */
> public static void print(InputSource source, DocPrintJob job,
> PrintRequestAttributeSet pras)
>       throws AjentException {
>   if (job != null) {
>       AWTRenderer renderer = new AWTRenderer(null);
>       render(source, renderer);
>       try {
>           Doc doc = new SimpleDoc(renderer,
> DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
>           job.print(doc, pras);
>       } catch (PrintException e) {
>           ...
>       }
>   }
> }
>   /**
>   * Render a source XSL-FO document using specified renderer
>   */
> public static void render(InputSource source, Renderer renderer) throws
> AjentException {
>      Driver driver = new Driver();
>      driver.setInputSource(source);
>      driver.setRenderer(renderer);
>      try {
>          driver.run();
>      } catch (IOException e) {
>          …
>      } catch (FOPException e) {
>          ...
>      }
>  }
> 
> 
> I want to do something similar in 0.94 (directly print with my settings).  I
> have looked at the ExampleFO2OldStylePrint example on the FOP site, however,
> I cannot figure out how to set the printer properties that I was setting
> before. (Printer and printer tray are the main properties).
> 
> I realize that I will be complete changing this for 0.94, however, an
> example of setting printer options to print directly in the new API would be
> greatly appreciated.
> 
> Thanks for any help or direction on this.
> 
> David J
> Columbia Ultimate
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Direct-Printing-and-setting-print-parameters-in-FOP-0.94-tp16747594p16747594.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to