One more thing. I'm using the FOP 0.20.3 distribution and associated
Jar files that come in the lib directory of the distro.
Thanks
Mike
On Thursday, March 7, 2002, at 08:27 PM, Michael Engelhart wrote:
Hi,
I have a gui java application that does a FO to PDF rendering so that
it can in turn send out an email with the PDF as an attachment. I
use the following FOP code to do this:
public byte[] renderFO() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileInputStream file = new FileInputStream("pdf.fo");
InputSource foFile = new InputSource(file);
Driver driver = new Driver(foFile, out);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();
return out.toByteArray();
}
I then pass the byte array to my custom DataSource class that is then
stuffed into a DataHandler that is passed to the JavaMail Message
object as the content. The code for the DataSource is this:
class ByteArrayDataSource implements DataSource
{
ByteArrayDataSource(String data, String type) {
try {
this.data = data.getBytes("iso-8859-1");
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
this.type = type;
}
ByteArrayDataSource(byte[] data, String type) {
this.data = data;
this.type = type;
}
public InputStream getInputStream() throws IOException {
if (data == null)
throw new IOException("no data");
return new ByteArrayInputStream(data);
}
public OutputStream getOutputStream() throws IOException {
throw new IOException("cannot do this");
}
public String getContentType() {
return type;
}
public String getName() {
return "mydatasource";
}
private byte[] data; // data
private String type; // content-type
}
So, the problem is that the code "works" (i.e., the PDF is rendered,
the email attachment is attached and sent), except that as soon as the
email message is sent and the code is returned back to the main thread
of the application, it just hangs. The GUI becomes unusable and I
have to kill the application. The app actually continues to run though
but as I said it's unusable since the GUI freezes up. If I remove the
3 lines:
Driver driver = new Driver(foFile, out);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();
then the code runs fine (although the PDF file isn't rendered) and the
application runs as expected. I'm stumped as to what is going on here.
I'm running this on Mac OS X, Java 2 (1.3.1), 768MB RAM. The
application is a Java/Cocoa application so it's not 100% pure java but
I still don't know why the 3 lines of coded needed to render a PDF
would cause this.
Any advice would be greatly appreciated.
Thanks
Mike