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 Jignesh Shah <js...@mdnotes.com> on 2003/08/06 18:47:37 UTC

Need help with PDF File creation

Hi,
 
I use the following code to generate my pdf in a servlet. There are two
problems here:
1. I see the file in the directory but when I access it, it gives me
Sharing Violation error. If I logout of my Form Based Authentication
implemented (Servlet is in that system) system I am able to access the
pdf correctly. Does anybody know how I can release the file once the
file has been generated
2. After getting the FileOutputStream it starts writing to the file. At
the same time it generates a "socket connection reset by peer
exception". I don't know why this exception is generated. It might be
with the popup window which closes down after passing the information to
a servlet which in turn dispatches the below servlet to generate the pdf
 
Any help is appreciated
 
Thank you
 
Jignesh
 
  public void renderXML(Document xmlsource, InputStream xslobj, String
file_is)
               throws ServletException {
 
  FileOutputStream fout = null;
  System.getProperty("file.separator");
  String sep = System.getProperty("file.separator");
 
  File dir = new File("c:" + sep + "Email PDF");
  if(!dir.exists())
  {
    dir.mkdirs();
  }
  System.out.println("New File Dir is : " + dir);
 
  File file = new File(dir,file_is);
 
  try
  {
    fout = new FileOutputStream(file);
  }
  catch(IOException ioe)
  {
    ioe.printStackTrace();
  }
 
  try
  {
    Driver driver = new Driver();
    driver.setLogger(log);
    driver.setOutputStream(fout);
    driver.setRenderer(Driver.RENDER_PDF);
    Transformer
transformer=TransformerFactory.newInstance().newTransformer(new
StreamSource(xslobj));
    transformer.transform(new JDOMSource(xmlsource), new
SAXResult(driver.getContentHandler()));
 
    fout.flush();
      if (fout !=null)
        fout.close();
  }
  catch (Exception ex)
  {
            ex.printStackTrace();
  }
}
 

Re: Need help with PDF File creation

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Jignesh Shah wrote:
> 1. I see the file in the directory but when I access it, it gives me
> Sharing Violation error. If I logout of my Form Based Authentication
> implemented (Servlet is in that system) system I am able to access the
> pdf correctly. Does anybody know how I can release the file once the
> file has been generated

Closing the file output stream should be enough. If you still
have the problem even after the file has been written and the
stream has been closed, experiment a bit:
- Use the FileOutputStream(dir+sep+file_is) constructor
- Close the file explicitely
- Set both fos and file to null to give the GC a chance to
   reclaim the objects.
If neither helps, ask on a general Java list.

> 2. After getting the FileOutputStream it starts writing to the file. At
> the same time it generates a "socket connection reset by peer
> exception". I don't know why this exception is generated.

This typically happens when the browser times out and hangs
up. You should pass something to the servlet response output
stream if you want avoid this.

J.Pietschmann



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