You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Debasish Jana <de...@anshinsoft.com> on 2006/04/10 14:11:08 UTC

FOP 0.91 Beta - Previewer problem

Hi:

 

We are using FOP 0.91 Beta for rendering XSL-FO documents to PDF or RTF or
other supported formats. To use the previewer, we are using the following
code snippet:

------

// file is the output file created earlier, and fo is the input stream
having XSL-FO source

FOP fop = new Fop(MimeConstants.MIME_FOP_AWT_PREVIEW);

BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(file));

fop.setOutputStream(out);

fop.getUserAgent().setOutputFile(file);

                                    

// Setup JAXP using identity transformer

TransformerFactory factory = TransformerFactory.newInstance();

Transformer transformer = factory.newTransformer(); // identity transformer

                                    

// Setup input stream

Source src = new StreamSource(fo);

                                    

try {

// Resulting SAX events (the generated FO) must be piped through to FOP

Result res = new SAXResult(fop.getDefaultHandler());

            

// Start XSLT transformation and FOP processing

            

transformer.transform(src, res);

}

catch(Exception ex)

{

} 

------

 

While hooking up the previewer, we face the following problems.

 

(1)     The previewer is shown in a separate JFrame window, which shows the
preview, but on closing the entire application of ours (running in a
separate JFrame) closes and the application comes out. Is it an acceptable
behavior? Or is there any workaround?

(2)     In case we would like to fit the previewer window inside a JPanel,
how can we do that, so that we can control stopping or terminating the
preview window whenever required.

(3)     Is there any other way of using the AWT previewer or are we doing
any mistake to use the previewer elegantly?

 

An early reply would be sincerely appreciated.

 

Warm regards,

 

Debasish Jana

 

 

 


RE: FOP 0.91 Beta - Previewer problem

Posted by Debasish Jana <de...@anshinsoft.com>.
Can you please pass on how to use the AWTRenderer with some sample code to
hook in? I would like to use it in as-is form, i.e. to call proper API to
preview using AWTRenderer and show it in a suitable JFrame or JPanel. 

Regards,

Debasish

-----Original Message-----
From: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
Sent: Tuesday, April 11, 2006 7:58 PM
To: fop-users@xmlgraphics.apache.org
Subject: Re: FOP 0.91 Beta - Previewer problem

There is something to consider:
Previewing the FO document in FOP's AWT Preview is not the same as
previewing the PDF. The AWTRenderer (based on the Java2DRenderer) uses
different font metrics than the PDFRenderer which can cause the document
to look different depending on which renderer the document was generated
with.

There are Java-based packages around with implement a PDF viewer that
you should be able to integrate into your Java application. Just enter
"Java PDF Viewer" in Google and you find plenty of hits. All commercial,
I think. PDFBox is an open source package which can preview PDFs but
it's not mature enough for the job, yet.

On 11.04.2006 13:06:52 Debasish Jana wrote:
> Hi:
> 
> Thanks for your prompt answer. Can you please pass me a sample code to
> invoke the renderer in an AWT window (JPanel or JFrame). Suppose I have a
> XSL-FO document which I would like to render to say PDF using FOP renderer
> and like to preview it? How can I do it?
<snip/>

Jeremias Maerki
----


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


Re: FOP 0.91 Beta - Previewer problem

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
There is something to consider:
Previewing the FO document in FOP's AWT Preview is not the same as
previewing the PDF. The AWTRenderer (based on the Java2DRenderer) uses
different font metrics than the PDFRenderer which can cause the document
to look different depending on which renderer the document was generated
with.

There are Java-based packages around with implement a PDF viewer that
you should be able to integrate into your Java application. Just enter
"Java PDF Viewer" in Google and you find plenty of hits. All commercial,
I think. PDFBox is an open source package which can preview PDFs but
it's not mature enough for the job, yet.

On 11.04.2006 13:06:52 Debasish Jana wrote:
> Hi:
> 
> Thanks for your prompt answer. Can you please pass me a sample code to
> invoke the renderer in an AWT window (JPanel or JFrame). Suppose I have a
> XSL-FO document which I would like to render to say PDF using FOP renderer
> and like to preview it? How can I do it?
<snip/>

Jeremias Maerki


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


RE: FOP 0.91 Beta - Previewer problem

Posted by Debasish Jana <de...@anshinsoft.com>.
Hi:

Thanks for your prompt answer. Can you please pass me a sample code to
invoke the renderer in an AWT window (JPanel or JFrame). Suppose I have a
XSL-FO document which I would like to render to say PDF using FOP renderer
and like to preview it? How can I do it?

Pls help.

Regards,

Debasish

-----Original Message-----
From: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
Sent: Monday, April 10, 2006 10:46 PM
To: fop-users@xmlgraphics.apache.org
Subject: Re: FOP 0.91 Beta - Previewer problem

(comments inline...)

On 10.04.2006 14:11:08 Debasish Jana wrote:
> Hi:
>  
> We are using FOP 0.91 Beta for rendering XSL-FO documents toPDF or RTF
> or other supported formats. To use the previewer, we are using
> the following code snippet:
> ------
> // file is the output file created earlier, and fo is theinput stream
having XSL-FO source
> FOP fop = new Fop(MimeConstants.MIME_FOP_AWT_PREVIEW);
> BufferedOutputStream out = new
BufferedOutputStream(newFileOutputStream(file));
> fop.setOutputStream(out);
> fop.getUserAgent().setOutputFile(file);

Why do you set an OutputStream if the file is displayed on screen?

> // Setup JAXP using identity transformer
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer(); //identity transformer
>                                     
> // Setup input stream
> Source src = new StreamSource(fo);
>                                     
> try {
> // Resulting SAX events (the generated FO) must be pipedthrough to FOP
> Result res = new SAXResult(fop.getDefaultHandler());
>             
> // Start XSLT transformation and FOP processing
>             
> transformer.transform(src, res);
> }
> catch(Exception ex)
> {
> } 
> ------
>  
> While hooking up the previewer, we face the following problems.
>  
> (1)     Thepreviewer is shown in a separate JFrame window, which shows
> the preview, but onclosing the entire application of ours (running in a
> separate JFrame) closesand the application comes out. Is it an
> acceptable behavior? Or is there anyworkaround?

Sorry, but I don't understand what you're trying to say.

> (2)     In case wewould like to fit the previewer window inside a
> JPanel, how can we do that, sothat we can control stopping or terminating
the
> preview window wheneverrequired.

I'd look at the source code of PreviewDialog. It should contains
everything you need to use the preview panel in your own windows,
because that's just what this class does.

http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/src/java/org/apache/fo
p/render/awt/viewer/PreviewDialog.java

Since this is not the first time this question pops up, it would be good
if someone would write a short Wiki page on how to do that. Or maybe
even an example class we could include in our embedding examples.

> (3)     Is there anyother way of using the AWT previewer or are we
> doing any mistake to use thepreviewer elegantly?

One thing would probably be to instantiate the AWTRenderer yourself and
to pass it to FOP using FOUserAgent.setRendererOverride(). I'm sorry I
can't help more. I'm not so much into GUI programming lately so that I'm
not a big help without wasting many hours first.

> An early reply would be sincerely appreciated.


Jeremias Maerki


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


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


Re: FOP 0.91 Beta - Previewer problem

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
(comments inline...)

On 10.04.2006 14:11:08 Debasish Jana wrote:
> Hi:
>  
> We are using FOP 0.91 Beta for rendering XSL-FO documents toPDF or RTF
> or other supported formats. To use the previewer, we are using
> the following code snippet:
> ------
> // file is the output file created earlier, and fo is theinput stream having XSL-FO source
> FOP fop = new Fop(MimeConstants.MIME_FOP_AWT_PREVIEW);
> BufferedOutputStream out = new BufferedOutputStream(newFileOutputStream(file));
> fop.setOutputStream(out);
> fop.getUserAgent().setOutputFile(file);

Why do you set an OutputStream if the file is displayed on screen?

> // Setup JAXP using identity transformer
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer(); //identity transformer
>                                     
> // Setup input stream
> Source src = new StreamSource(fo);
>                                     
> try {
> // Resulting SAX events (the generated FO) must be pipedthrough to FOP
> Result res = new SAXResult(fop.getDefaultHandler());
>             
> // Start XSLT transformation and FOP processing
>             
> transformer.transform(src, res);
> }
> catch(Exception ex)
> {
> } 
> ------
>  
> While hooking up the previewer, we face the following problems.
>  
> (1)     Thepreviewer is shown in a separate JFrame window, which shows
> the preview, but onclosing the entire application of ours (running in a
> separate JFrame) closesand the application comes out. Is it an
> acceptable behavior? Or is there anyworkaround?

Sorry, but I don't understand what you're trying to say.

> (2)     In case wewould like to fit the previewer window inside a
> JPanel, how can we do that, sothat we can control stopping or terminating the
> preview window wheneverrequired.

I'd look at the source code of PreviewDialog. It should contains
everything you need to use the preview panel in your own windows,
because that's just what this class does.

http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java

Since this is not the first time this question pops up, it would be good
if someone would write a short Wiki page on how to do that. Or maybe
even an example class we could include in our embedding examples.

> (3)     Is there anyother way of using the AWT previewer or are we
> doing any mistake to use thepreviewer elegantly?

One thing would probably be to instantiate the AWTRenderer yourself and
to pass it to FOP using FOUserAgent.setRendererOverride(). I'm sorry I
can't help more. I'm not so much into GUI programming lately so that I'm
not a big help without wasting many hours first.

> An early reply would be sincerely appreciated.


Jeremias Maerki


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