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 Nicolas Michael <em...@nmichael.de> on 2003/06/17 16:44:47 UTC

FOP locks output file under WinXP

Hi there!

I've embedded FOP 0.20.4 in an application. I use it to create a PDF file and 
launch Acrobat to display the generated file. With Linux and Win98 this works 
fine.
But some of my users use WinXP and have the problem, that Acrobat Reader [6.0] 
cannot open the generated PDF file "because it is still in use by an other 
application". [JRE 1.4.1]

Here is some code to demonstrate the problem.
args[0] is the input xsl-fo file, args[1] is the pdf output file and args[2] 
is the path to the Acrobat Reader exe file.

I'd be glad if someone could help me how to solve this problem. Thanks!!

--------------------------
class Test {

  // args: Test <xsl-fo file> <pdf output file> <path to acrobat reader>
  public static void main(String[] args) {
    try {
      org.apache.fop.apps.Driver driver =
        new org.apache.fop.apps.Driver(new org.xml.sax.InputSource(args[0]),
                                       new java.io.FileOutputStream(args[1]));
      driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
      driver.run();
      String[] cmd = new String[2];
      cmd[0] = args[2];
      cmd[1] = args[1];
      System.out.println("Starting Acrobat: "+cmd[0]+" "+cmd[1]);
      Runtime.getRuntime().exec(cmd);
      Thread.sleep(20000);
      System.out.println("done.");
    } catch(Exception e) {
      e.printStackTrace();
    }
  }

}
--------------------------

-- 
man liest sich...

Nicolas Michael
mailto:email@nmichael.de     http://www.nmichael.de/

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


RE: FOP locks output file under WinXP

Posted by Torsten Erler <To...@net-linx.com>.
;~)

I thought it.
It was just a lark to be not lurking on the thread because it was already
solved.
Sorry if I've violated your programmer proudness ;)

cu

> -----Original Message-----
> To Torsten Erler: "Thread.sleep(20000);" was just to
> demonstrate that Acrobat
> is accessing the file while the application is still running. My real
> application is a GUI application that just starts Acrobat but
> doesn't exit
> itself, so that's what sleep() meant to simulate....


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


Re: FOP locks output file under WinXP

Posted by Nicolas Michael <em...@nmichael.de>.
Am Dienstag, 17. Juni 2003 16:52 schrieb patrick.mannhart@bluewin.ch:

> hmm... you've forgot to flushing and closing the OutputStream!

Yes, sounds good.... Why didn't I see that, it's not really a hard thing to 
figure out?!
Well, now it works! Thanks a lot!!

To Torsten Erler: "Thread.sleep(20000);" was just to demonstrate that Acrobat 
is accessing the file while the application is still running. My real 
application is a GUI application that just starts Acrobat but doesn't exit 
itself, so that's what sleep() meant to simulate....


> >-- Original-Nachricht --
> >Reply-To: fop-user@xml.apache.org
>
> From: Nicolas Michael <em...@nmichael.de>
>
> >To: fop-user@xml.apache.org
> >Subject: FOP locks output file under WinXP
> >Date: Tue, 17 Jun 2003 16:44:47 +0200
> >
> >
> >Hi there!
> >
> >I've embedded FOP 0.20.4 in an application. I use it to create a PDF file
> >and
> >launch Acrobat to display the generated file. With Linux and Win98 this
>
> works
>
> >fine.
> >But some of my users use WinXP and have the problem, that Acrobat Reader
> >[6.0]
> >cannot open the generated PDF file "because it is still in use by an other
> >
> >application". [JRE 1.4.1]
> >
> >Here is some code to demonstrate the problem.
> >args[0] is the input xsl-fo file, args[1] is the pdf output file and
> > args[2]
> >
> >is the path to the Acrobat Reader exe file.
> >
> >I'd be glad if someone could help me how to solve this problem. Thanks!!
> >
> >--------------------------
> >class Test {
> >
> >  // args: Test <xsl-fo file> <pdf output file> <path to acrobat reader>
> >  public static void main(String[] args) {
> >    try {
> >      org.apache.fop.apps.Driver driver =
> >        new org.apache.fop.apps.Driver(new
> > org.xml.sax.InputSource(args[0]), new java.io.FileOutputStream(args[1]));
> > driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
> >      driver.run();
> >      String[] cmd = new String[2];
> >      cmd[0] = args[2];
> >      cmd[1] = args[1];
> >      System.out.println("Starting Acrobat: "+cmd[0]+" "+cmd[1]);
> >      Runtime.getRuntime().exec(cmd);
> >      Thread.sleep(20000);
> >      System.out.println("done.");
> >    } catch(Exception e) {
> >      e.printStackTrace();
> >    }
> >  }
> >
> >}
> >--------------------------

-- 
man liest sich...

Nicolas Michael
mailto:email@nmichael.de     http://www.nmichael.de/

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


Re: FOP locks output file under WinXP

Posted by Bertrand Delacretaz <bd...@codeconsult.ch>.
Le Mardi, 17 juin 2003, à 17:11 Europe/Zurich, Torsten Erler a écrit :
> ...
> Process p = Runtime.getRuntime().exec(cmd);
> p.waitFor();

right on - this is heavy duty distributed code review ;-)

-Bertrand

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


RE: FOP locks output file under WinXP

Posted by Torsten Erler <To...@net-linx.com>.
> > Hi Nicolas
> >
> > hmm... you've forgot to flushing and closing the OutputStream!
> 
> and you have to do it in a "finally" clause if you want it to be 
> reliable.
> 
I've also to bleat ;)

Remove 'Thread.sleep(20000)', 

if your'e waiting for the execution do that:
* 
//close the Stream before calling this!!!
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
*


cu


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


Re: FOP locks output file under WinXP

Posted by Bertrand Delacretaz <bd...@codeconsult.ch>.
Le Mardi, 17 juin 2003, à 16:52 Europe/Zurich, 
patrick.mannhart@bluewin.ch a écrit :

> Hi Nicolas
>
> hmm... you've forgot to flushing and closing the OutputStream!

and you have to do it in a "finally" clause if you want it to be 
reliable.

--
   Bertrand Delacretaz
   independent consultant, Lausanne, Switzerland
   http://cvs.apache.org/~bdelacretaz/


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


RE: FOP locks output file under WinXP

Posted by pa...@bluewin.ch.
Hi Nicolas

hmm... you've forgot to flushing and closing the OutputStream!

regards
patrick



>-- Original-Nachricht --
>Reply-To: fop-user@xml.apache.org
>From: Nicolas Michael <em...@nmichael.de>
>To: fop-user@xml.apache.org
>Subject: FOP locks output file under WinXP
>Date: Tue, 17 Jun 2003 16:44:47 +0200
>
>
>Hi there!
>
>I've embedded FOP 0.20.4 in an application. I use it to create a PDF file
>and 
>launch Acrobat to display the generated file. With Linux and Win98 this
works
>
>fine.
>But some of my users use WinXP and have the problem, that Acrobat Reader
>[6.0] 
>cannot open the generated PDF file "because it is still in use by an other
>
>application". [JRE 1.4.1]
>
>Here is some code to demonstrate the problem.
>args[0] is the input xsl-fo file, args[1] is the pdf output file and args[2]
>
>is the path to the Acrobat Reader exe file.
>
>I'd be glad if someone could help me how to solve this problem. Thanks!!
>
>--------------------------
>class Test {
>
>  // args: Test <xsl-fo file> <pdf output file> <path to acrobat reader>
>  public static void main(String[] args) {
>    try {
>      org.apache.fop.apps.Driver driver =
>        new org.apache.fop.apps.Driver(new org.xml.sax.InputSource(args[0]),
>                                       new java.io.FileOutputStream(args[1]));
>      driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
>      driver.run();
>      String[] cmd = new String[2];
>      cmd[0] = args[2];
>      cmd[1] = args[1];
>      System.out.println("Starting Acrobat: "+cmd[0]+" "+cmd[1]);
>      Runtime.getRuntime().exec(cmd);
>      Thread.sleep(20000);
>      System.out.println("done.");
>    } catch(Exception e) {
>      e.printStackTrace();
>    }
>  }
>
>}
>--------------------------
>
>-- 
>man liest sich...
>
>Nicolas Michael
>mailto:email@nmichael.de     http://www.nmichael.de/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: fop-user-help@xml.apache.org
>


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