As I tried to break it down to send you an actual code sample so you
could see how the ugly code works, which was doing a transform on the
client, and see what I was trying to do with transforming on the server
which wasn't working, I started to examine each object and each step and
figure out it's purpose.  I ultimately realized that while my attempt at
transforming the document on the server to load in the client
PreviewPanel wasn't getting any errors (or output), it was also missing
some things and had some things which weren't even doing anything.  I've
debugged the disconnect and it works!

My print portion of the program is using the Fop class to connect
everything.  I create the Fop with a ByteArrayOutputStream.  Then I
create a SAXResult object using the Fop getDefaultHandler method.  Then
I pass that SAXResult as the output to the javax transform method and
the Fop class links it back to put a finished document in the
ByteArrayOutputStream.  I get the bytes from that output stream to
generate a ByteArrayInputStream which I pass as input to create a
PDDocument object with the pdfbox project, which I can either save as a
PDF file or pass to the printer using java's PrinterJob.  Since that
output is in byte[] form in between the output stream and the input
stream, I can either create that PDF on the server or copy the bytes
down to create it directly on the client.

Now we get to how that all ties together.  I checked the PreviewPanel
and saw there is no way to pass the finished document.  That document
goes through the Renderer.  I looked at AWTRenderer and saw the document
can be passed in using the Renderable class.  I couldn't figure out how
to connect this to the Fop class which is generating the finished
document in the previously described print portion, then I figured out
this is just a convenience class to connect the transforming to the
rendering.  What I needed in order to use the Renderable class was the
intermediate stage.  I replaced the SAXResult output for the transform
on the server with a StreamResult which can be tied to a file.  This
generated the FO file which is the transformed, unrendered document.
The Java File is serializable, so I just copied that to the client for
input to the cli InputHandler.  Then I execute the InputHandler's
renderTo and pass it to the AWTRenderer's setRenderable, and I have a
finished document for the PreviewPanel.  I still have to create the
FopFactory, the FOUserAgent, and the AWTRenderer on the client, but
leaving the XML, XSL, and the Transformer on the server saves a lot.


-----Original Message-----
From: Jeremias Maerki [mailto:d...@jeremias-maerki.ch] 
Sent: Friday, November 19, 2010 3:41 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: Renderable

I think you have two options:

1. Create a bitmap (with PNGDocumentHandler (image/png)) on the server
and send that to the client. But you will likely have to produce your
own viewer and cannot reuse FOP's preview dialog.

2. Generate the IF XML format on the server, send that to the client and
use the org.apache.fop.cli.IFInputHandler to render the IF XML file in
FOP's preview dialog. That at least does the layout part on the server,
but if your document contains SVGs or barcodes, that part will still be
processed on the client-side FOP.

Please note that FOP's Renderable class is not the same as AWT's
Renderable.

And FOP has multiple implementations of it own Renderable interface in
the org.apache.fop.cli package.

If you want to off-load as much as possible to the server, you should
pursue option 1.

On 17.11.2010 17:16:08 Eric Douglas wrote:
> I'm creating an object of type
> org.apache.fop.render.awt.viewer.PreviewPanel.
> The constructor is (FOUserAgent foUserAgent, Renderable renderable, 
> AWTRenderer renderer).
> I'm running a client-server program in webstart.
> Of course the PreviewPanel must be created as a client object.
> This works if I pass a null for Renderable, but also seems to require 
> that I tie my AWTRenderer to a client Fop object to do a client 
> transform.
> The transform runs a lot faster on the server.
> I was wondering if I can do the transform on the server and just pass 
> the result into the client.
> That appears to be the purpose of the Renderable class.
> I don't see any FOP classes which return or implement a Renderable.  
> How do I generate one?




Jeremias Maerki


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


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

Reply via email to