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

Reply via email to