You should be able to get the temp file directory by adding something like 
this to the code which is executed by the Tomcat server:

File outputfile = File.createTempFile("test", null);
String temporaryFileDirectory = outputfile.getAbsolutePath();

That'll return whatever the O/S defines as the temporary directory (e.g. 
/tmp in Linux, C:\Users\YourUserName\AppData\Local\Temp for Windows). 
Check to see what returns when running the code from within Tomcat and 
then check the permissions for that location and it should take care of 
it.  If you are running Tomcat in a development environment, it's probably 
running under your user ID, so just see if you can create a file in that 
directory.  I've used the merge function from Tomcat before, so it's 
probably just a little server setup which you need to do.

--Adam



From:
Andreas Lehmkuehler <[email protected]>
To:
[email protected]
Date:
03/03/2010 11:24
Subject:
Re: PDFs merge using PDFBox in Tomcat server



Hi,

Balakrishna R schrieb:
> Hi,
> 
> I have been trying one example with PDFBox to merge two pdfs using 
PDFMergerUtility class.
> 
> /*---- code snippet  ---*/
> 
> PDFMergerUtility mergePdf = new PDFMergerUtility();
> mergePdf.addSource(file1);
> mergePdf.addSource(file2);
> mergePdf.setDestinationFileName(file3);
> try {
> mergePdf.mergeDocuments();
> } catch (COSVisitorException e) {
> throw new InsolveException(e);
> } catch (IOException e) {
> e.printStackTrace();
> throw new InsolveException(e);
> }
> 
> /*---- code snippet --- */
> 
> When I use the above code in a standalone application it is merging two 
pdf files properly.
> 
> But when I use the above function in a web application as a server side 
program and deployed to Tomcat, the mergeDocuments() statement is causing 
the following exception.
> 
> Exception print stack trace:
> 
> java.io.IOException: The system cannot find the path specified
>                 at java.io.WinNTFileSystem.createFileExclusively(Native 
Method)
>                 at java.io.File.checkAndCreate(Unknown Source)
>                 at java.io.File.createTempFile(Unknown Source)
>                 at 
org.apache.pdfbox.cos.COSDocument.<init>(COSDocument.java:103)
>                 at 
org.apache.pdfbox.cos.COSDocument.<init>(COSDocument.java:90)
>                 at 
org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:153)
>                 at 
org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:841)
>                 at 
org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:808)
>                 at 
org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:779)
>                 at 
org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:127)
>                 at 
com.insolve.common.Utility.mergePDFS(Utility.java:503)
> 
> Note: all the files and folders are available in the file system 
according to the given paths.
> 
> I am guessing there could be some problem with Windows file system which 
is not allowing to create a file from PDFBox code.
> Please let me know what could be the reason and how to solve it.
Yes, PDFBox tries to create a temp file but it can't. You have to define 
some
kind of a temp space and that temp space has to be writable for your
application.

> 
> Thanks in advance,
> Balakrishna.

BR
Andreas Lehmkühler



?  Click here to submit conditions  

This email and any content within or attached hereto from  Sun West Mortgage 
Company, Inc.  is confidential and/or legally privileged. The information is 
intended only for the use of the individual or entity named on this email. If 
you are not the intended recipient, you are hereby notified that any 
disclosure, copying, distribution or the taking of any action in reliance on 
the contents of this email information is strictly prohibited, and that the 
documents should be returned to this office immediately by email. Receipt by 
anyone other than the intended recipient is not a waiver of any privilege. 
Please do not include your social security number, account number, or any other 
personal or financial information in the content of the email. Should you have 
any questions, please call  (800) 453 7884.   

Reply via email to