You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Ng <jn...@yahoo.com> on 2002/02/17 05:16:47 UTC

FOP and strus

Hi, I am looking into FOP in generating PDF in
struts...  the examples so far that I have seen are
only taking static XML files and XLS files.  Can
someone tell me how to use FOP to generate pdf with
dynamic XML string (generated by some java objects) on
the fly?

I would apprecaite if you could even provide me with
some sample code.

Thanks
John


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FOP and strus

Posted by Nick Pellow <ni...@cortexebusiness.com.au>.
John,
We wrote a servlet that took the name of a URI as a parameter.
That URI, essentially mapped to a JSP, whose output was FOP.
The servlet:
requested the URI, got the FOP, formatted the FOP, then sent that back to
the browser. This may not be ideal for all situations, but it worked nicely
for us.

You could look at using something like webmacro/velocity as it would be
neater than a JSP for
this. It depends on what you are doing.

Regards,
Nick

----- Original Message -----
From: "John Ng" <jn...@yahoo.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Sunday, February 17, 2002 3:16 PM
Subject: FOP and strus


> Hi, I am looking into FOP in generating PDF in
> struts...  the examples so far that I have seen are
> only taking static XML files and XLS files.  Can
> someone tell me how to use FOP to generate pdf with
> dynamic XML string (generated by some java objects) on
> the fly?
>
> I would apprecaite if you could even provide me with
> some sample code.
>
> Thanks
> John
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Sports - Coverage of the 2002 Olympic Games
> http://sports.yahoo.com
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FOP and strus (IE problem)

Posted by Tadashi Ishikawa <is...@wink.tis.co.jp>.
I had the same problem.(Not IE problem)

FOPServlet works fine under Tomcat3.2.3 and OC4J(Orion).
IE has a URL problem. but this is not the case.

FO -> FOP -> PDF works fine under WebLogic6.1sp1 as well.
XML + XSL ->Xalan ->FO -> FOP ->PDF won't work.

PDF file size was 0 in NN also.
I thought Xalan failed. I noticed FO wasn't created. but I got no exception.
I changed server's CLASSPATH. but nothing was changed.
I think this problem is specific to weblogic. and I couldn't solve it.

John Ng wrote:

>I still couldn't get it working in IE.  I use weblogic
>as the webserver... Do I have to do anything specific
>to weblogic?
>
>Thanks
>John
>
>--- Arron Bates <ar...@pacific.net.au> wrote:
>
>>Oh, what a world of pain.
>>IE in this regard is a pile of *@!# and NS is the
>>absolute honey  :)
>>
>>This is off-struts, but I know the pain you go
>>through to get IE going 
>>properly.
>>
>>Here's what I had to do to get it running
>>reliably...
>>
>>
>>// START CODE --==>>
>>
>>// set the response type
>>response.setContentType("application/pdf");
>>// set the content details
>>response.setHeader("Content-Disposition", "inline; 
>>filename=ConfirmationLetter.pdf; ");
>>
>>// creating a temporary output stream
>>ByteArrayOutputStream bout = new
>>ByteArrayOutputStream();
>>
>>// this class takes teh xml document and runs it
>>through the FOP process
>>// and pumps it into the output stream created.
>>OnlineSalesPDFGenerator pdf = new
>>OnlineSalesPDFGenerator(xmlDoc);
>>pdf.run(form,request,bout);
>>
>>byte[] content = bout.toByteArray();
>>
>>// set the exact content length from our temp output
>>stream
>>response.setContentLength(content.length);
>>
>>// write the content
>>response.getOutputStream().write(content);
>>
>>// flush the stream
>>response.getOutputStream().flush();
>>
>>// <<==-- END CODE
>>
>>
>>I went through a lot of pain to get all the
>>alternatives people were 
>>doing to get this. Important parts are...
>>a) The response type.
>>b) The Content-Disposition details. This sets
>>filenames and stuff for 
>>the file saving dialog boxes etc.
>>c) Setting the exact content length. Made possible
>>by writing to the 
>>ByteArrayOutputStream and getting its resulting
>>size.
>>
>>And if you're pessimistic (most likely you are by
>>now :), make sure you 
>>flush and close the output stream, and you can also
>>throw in what Gregor 
>>says below with your URL. After the above though,
>>you shouldn't have any 
>>problems.
>>
>>Hopefully this will get you where you need to be.
>>
>>
>>Arron.
>>
>>
>>Gregor Rayman wrote:
>>
>>>"John Ng" <jn...@yahoo.com> wrote:
>>>
>>>>Hi, The following is a piece of the code that I
>>>>
>>write
>>
>>>>in the perform method of an ActionForm to generate
>>>>
>>the
>>
>>>>PDF.  However, it works fine in netscape, but NOT
>>>>
>>IE. 
>>
>>>>Can someone help me with this?
>>>>
>>>>Thanks!
>>>>John 
>>>>
>>>Try adding "?.pdf" to the url.
>>>
>>>--
>>>gR
>>>
>>>
>>>--
>>>To unsubscribe, e-mail:  
>>>
>><ma...@jakarta.apache.org>
>>
>>>For additional commands, e-mail:
>>>
>><ma...@jakarta.apache.org>
>>
>>>
>>
>>
>>
>
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Sports - Coverage of the 2002 Olympic Games
>http://sports.yahoo.com
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: FOP and strus (IE problem)

Posted by Robert <rm...@bull-enterprises.com>.
I realize I'm jumping in this one late, so forgive me if I restate what
some others have, but:

a) no, you shouldn't have to do anything with your web/app server at
all.

b) This is a bug with IE, in that it tends to ignore content types if it
thinks it 'knows' what the content is (by what the URL ends with), so as
others have said, you should be able to set the content type and either
set the URL to end with a '.pdf' or NOT end with it (then IE checks the
content type) The Cocoon site mentions this as well, as they have a FOP
example in their distro that out of the box doesn't work in IE because
the URL actually end in .xml so IE thinks it's an XML document even
though cocoon sets the content type.

c) What _exactly_ is happening? Are you getting a browser full of funky
text, nothing at all, crashing, etc.?

- Robert McIntosh

-----Original Message-----
From: John Ng [mailto:jng369@yahoo.com] 
Sent: Tuesday, February 19, 2002 1:08 PM
To: Struts Users Mailing List
Subject: Re: FOP and strus (IE problem)

I still couldn't get it working in IE.  I use weblogic
as the webserver... Do I have to do anything specific
to weblogic?

Thanks
John

--- Arron Bates <ar...@pacific.net.au> wrote:
> Oh, what a world of pain.
> IE in this regard is a pile of *@!# and NS is the
> absolute honey  :)
> 
> This is off-struts, but I know the pain you go
> through to get IE going 
> properly.
> 
> Here's what I had to do to get it running
> reliably...
> 
> 
> // START CODE --==>>
> 
> // set the response type
> response.setContentType("application/pdf");
> // set the content details
> response.setHeader("Content-Disposition", "inline; 
> filename=ConfirmationLetter.pdf; ");
> 
> // creating a temporary output stream
> ByteArrayOutputStream bout = new
> ByteArrayOutputStream();
> 
> // this class takes teh xml document and runs it
> through the FOP process
> // and pumps it into the output stream created.
> OnlineSalesPDFGenerator pdf = new
> OnlineSalesPDFGenerator(xmlDoc);
> pdf.run(form,request,bout);
> 
> byte[] content = bout.toByteArray();
> 
> // set the exact content length from our temp output
> stream
> response.setContentLength(content.length);
> 
> // write the content
> response.getOutputStream().write(content);
> 
> // flush the stream
> response.getOutputStream().flush();
> 
> // <<==-- END CODE
> 
> 
> I went through a lot of pain to get all the
> alternatives people were 
> doing to get this. Important parts are...
> a) The response type.
> b) The Content-Disposition details. This sets
> filenames and stuff for 
> the file saving dialog boxes etc.
> c) Setting the exact content length. Made possible
> by writing to the 
> ByteArrayOutputStream and getting its resulting
> size.
> 
> And if you're pessimistic (most likely you are by
> now :), make sure you 
> flush and close the output stream, and you can also
> throw in what Gregor 
> says below with your URL. After the above though,
> you shouldn't have any 
> problems.
> 
> Hopefully this will get you where you need to be.
> 
> 
> Arron.
> 
> 
> Gregor Rayman wrote:
> 
> >"John Ng" <jn...@yahoo.com> wrote:
> >
> >>Hi, The following is a piece of the code that I
> write
> >>in the perform method of an ActionForm to generate
> the
> >>PDF.  However, it works fine in netscape, but NOT
> IE. 
> >>Can someone help me with this?
> >>
> >>Thanks!
> >>John 
> >>
> >
> >Try adding "?.pdf" to the url.
> >
> >--
> >gR
> >
> >
> >--
> >To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> >For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
> 
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FOP and strus (IE problem)

Posted by John Ng <jn...@yahoo.com>.
I still couldn't get it working in IE.  I use weblogic
as the webserver... Do I have to do anything specific
to weblogic?

Thanks
John

--- Arron Bates <ar...@pacific.net.au> wrote:
> Oh, what a world of pain.
> IE in this regard is a pile of *@!# and NS is the
> absolute honey  :)
> 
> This is off-struts, but I know the pain you go
> through to get IE going 
> properly.
> 
> Here's what I had to do to get it running
> reliably...
> 
> 
> // START CODE --==>>
> 
> // set the response type
> response.setContentType("application/pdf");
> // set the content details
> response.setHeader("Content-Disposition", "inline; 
> filename=ConfirmationLetter.pdf; ");
> 
> // creating a temporary output stream
> ByteArrayOutputStream bout = new
> ByteArrayOutputStream();
> 
> // this class takes teh xml document and runs it
> through the FOP process
> // and pumps it into the output stream created.
> OnlineSalesPDFGenerator pdf = new
> OnlineSalesPDFGenerator(xmlDoc);
> pdf.run(form,request,bout);
> 
> byte[] content = bout.toByteArray();
> 
> // set the exact content length from our temp output
> stream
> response.setContentLength(content.length);
> 
> // write the content
> response.getOutputStream().write(content);
> 
> // flush the stream
> response.getOutputStream().flush();
> 
> // <<==-- END CODE
> 
> 
> I went through a lot of pain to get all the
> alternatives people were 
> doing to get this. Important parts are...
> a) The response type.
> b) The Content-Disposition details. This sets
> filenames and stuff for 
> the file saving dialog boxes etc.
> c) Setting the exact content length. Made possible
> by writing to the 
> ByteArrayOutputStream and getting its resulting
> size.
> 
> And if you're pessimistic (most likely you are by
> now :), make sure you 
> flush and close the output stream, and you can also
> throw in what Gregor 
> says below with your URL. After the above though,
> you shouldn't have any 
> problems.
> 
> Hopefully this will get you where you need to be.
> 
> 
> Arron.
> 
> 
> Gregor Rayman wrote:
> 
> >"John Ng" <jn...@yahoo.com> wrote:
> >
> >>Hi, The following is a piece of the code that I
> write
> >>in the perform method of an ActionForm to generate
> the
> >>PDF.  However, it works fine in netscape, but NOT
> IE. 
> >>Can someone help me with this?
> >>
> >>Thanks!
> >>John 
> >>
> >
> >Try adding "?.pdf" to the url.
> >
> >--
> >gR
> >
> >
> >--
> >To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> >For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
> 
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FOP and strus (IE problem)

Posted by Arron Bates <ar...@pacific.net.au>.
Oh, what a world of pain.
IE in this regard is a pile of *@!# and NS is the absolute honey  :)

This is off-struts, but I know the pain you go through to get IE going 
properly.

Here's what I had to do to get it running reliably...


// START CODE --==>>

// set the response type
response.setContentType("application/pdf");
// set the content details
response.setHeader("Content-Disposition", "inline; 
filename=ConfirmationLetter.pdf; ");

// creating a temporary output stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();

// this class takes teh xml document and runs it through the FOP process
// and pumps it into the output stream created.
OnlineSalesPDFGenerator pdf = new OnlineSalesPDFGenerator(xmlDoc);
pdf.run(form,request,bout);

byte[] content = bout.toByteArray();

// set the exact content length from our temp output stream
response.setContentLength(content.length);

// write the content
response.getOutputStream().write(content);

// flush the stream
response.getOutputStream().flush();

// <<==-- END CODE


I went through a lot of pain to get all the alternatives people were 
doing to get this. Important parts are...
a) The response type.
b) The Content-Disposition details. This sets filenames and stuff for 
the file saving dialog boxes etc.
c) Setting the exact content length. Made possible by writing to the 
ByteArrayOutputStream and getting its resulting size.

And if you're pessimistic (most likely you are by now :), make sure you 
flush and close the output stream, and you can also throw in what Gregor 
says below with your URL. After the above though, you shouldn't have any 
problems.

Hopefully this will get you where you need to be.


Arron.


Gregor Rayman wrote:

>"John Ng" <jn...@yahoo.com> wrote:
>
>>Hi, The following is a piece of the code that I write
>>in the perform method of an ActionForm to generate the
>>PDF.  However, it works fine in netscape, but NOT IE. 
>>Can someone help me with this?
>>
>>Thanks!
>>John 
>>
>
>Try adding "?.pdf" to the url.
>
>--
>gR
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>




Re: FOP and strus (IE problem)

Posted by Gregor Rayman <gr...@gmx.net>.
"John Ng" <jn...@yahoo.com> wrote:

> Hi, The following is a piece of the code that I write
> in the perform method of an ActionForm to generate the
> PDF.  However, it works fine in netscape, but NOT IE. 
> Can someone help me with this?
> 
> Thanks!
> John 

Try adding "?.pdf" to the url.

--
gR


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FOP and strus (IE problem)

Posted by John Ng <jn...@yahoo.com>.
Hi, The following is a piece of the code that I write
in the perform method of an ActionForm to generate the
PDF.  However, it works fine in netscape, but NOT IE. 
Can someone help me with this?

Thanks!
John 

  
      File xsltfile=new File("c:/uwreportdet.xsl");
      File xmlfile=new File("c:/uwreport.xml");
      
      StringWriter writer = new StringWriter();
      //XSLTransform.transform(s,
xsltfile.getCanonicalPath(), 
      //writer);
     
XSLTransform.transform(xmlfile.getCanonicalPath(),
xsltfile.getCanonicalPath(), 
			     writer);
      writer.flush();
      writer.close();
      
      System.out.println("fo file: [" +
writer.toString() + "]");

      response.setContentType("application/pdf");
      StringReader reader = new
StringReader(writer.toString());
      

      Driver driver = new Driver(new
InputSource(reader), out);
      driver.run();

      byte[] content = out.toByteArray();
      response.setContentLength(content.length);
      response.getOutputStream().write(content);
      response.getOutputStream().flush();

--- Ted Husted <hu...@apache.org> wrote:
> Or the Commons-Digester :o)
> 
> Ajay Chitre wrote:
> > 
> > One approach would be to convert java objects to
> xml using Castor and then
> > pass the XML to FOP.
> > 
> > HTH.
> > 
> > -- Original Message --
> > 
> > >Hi, I am looking into FOP in generating PDF in
> > >struts...  the examples so far that I have seen
> are
> > >only taking static XML files and XLS files.  Can
> > >someone tell me how to use FOP to generate pdf
> with
> > >dynamic XML string (generated by some java
> objects) on
> > >the fly?
> > >
> > >I would apprecaite if you could even provide me
> with
> > >some sample code.
> > >
> > >Thanks
> > >John
> > >
> > >
> >
> >__________________________________________________
> > >Do You Yahoo!?
> > >Yahoo! Sports - Coverage of the 2002 Olympic
> Games
> > >http://sports.yahoo.com
> > >
> > >--
> > >To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> > >For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> > >
> > >
> > 
> > Ajay Chitre
> > 
> > Diligent Team, Inc.
> > (Where Diligent People Work as a Team)
> > 
> > http://www.DiligentTeam.com
> > 
> > --
> > To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> -- Ted Husted, Husted dot Com
> -- For priority Struts support, 
> -> visit http://husted.com/about/services
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FOP and strus

Posted by Ted Husted <hu...@apache.org>.
Or the Commons-Digester :o)

Ajay Chitre wrote:
> 
> One approach would be to convert java objects to xml using Castor and then
> pass the XML to FOP.
> 
> HTH.
> 
> -- Original Message --
> 
> >Hi, I am looking into FOP in generating PDF in
> >struts...  the examples so far that I have seen are
> >only taking static XML files and XLS files.  Can
> >someone tell me how to use FOP to generate pdf with
> >dynamic XML string (generated by some java objects) on
> >the fly?
> >
> >I would apprecaite if you could even provide me with
> >some sample code.
> >
> >Thanks
> >John
> >
> >
> >__________________________________________________
> >Do You Yahoo!?
> >Yahoo! Sports - Coverage of the 2002 Olympic Games
> >http://sports.yahoo.com
> >
> >--
> >To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> >For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
> 
> Ajay Chitre
> 
> Diligent Team, Inc.
> (Where Diligent People Work as a Team)
> 
> http://www.DiligentTeam.com
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- Ted Husted, Husted dot Com
-- For priority Struts support, 
-> visit http://husted.com/about/services

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: FOP and strus

Posted by Ajay Chitre <aj...@diligentteam.com>.
One approach would be to convert java objects to xml using Castor and then
pass the XML to FOP.

HTH.

-- Original Message --

>Hi, I am looking into FOP in generating PDF in
>struts...  the examples so far that I have seen are
>only taking static XML files and XLS files.  Can
>someone tell me how to use FOP to generate pdf with
>dynamic XML string (generated by some java objects) on
>the fly?
>
>I would apprecaite if you could even provide me with
>some sample code.
>
>Thanks
>John
>
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Sports - Coverage of the 2002 Olympic Games
>http://sports.yahoo.com
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>

Ajay Chitre

Diligent Team, Inc.
(Where Diligent People Work as a Team)

http://www.DiligentTeam.com



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>