bruno schrieb:
Eberhard Schulte wrote:
Hi,
use src.getParentFile().getAbsolutePath() to get the full path!
This was already fixed in the CVS repository a while ago.
br,
Bruno
Hi Bruno,
next time i will look first in the CVS.
But now i have two enhancements.
1. parentFile may be null, if you use relative files
java -cp iText-CVS/bin/ com.lowagie.tools.plugins.ExtractAttachments 0-0524.pdf
2. throws Exception if occurs
java -cp iText-CVS/bin/ com.lowagie.tools.plugins.ExtractAttachments 0-0524.pdf
Unpacking file '0-0524_RGB.tif' to
java.io.FileNotFoundException: /0-0524_RGB.tif (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at
com.lowagie.tools.plugins.ExtractAttachments.unpackFile(ExtractAttachments.java:214)
at
com.lowagie.tools.plugins.ExtractAttachments.execute(ExtractAttachments.java:128)
at
com.lowagie.tools.plugins.ExtractAttachments.main(ExtractAttachments.java:178)
Index: ExtractAttachments.java
===================================================================
RCS file: /cvsroot/itext/src/com/lowagie/tools/plugins/ExtractAttachments.java,v
retrieving revision 1.3
diff -u -r1.3 ExtractAttachments.java
--- ExtractAttachments.java 23 Jan 2006 13:42:43 -0000 1.3
+++ ExtractAttachments.java 1 Mar 2006 11:14:22 -0000
@@ -51,6 +51,7 @@
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
@@ -104,7 +105,15 @@
// we create a reader for a certain document
PdfReader reader = new PdfReader(src.getAbsolutePath());
- String outPath = src.getParentFile().getAbsolutePath();
+ final File parentFile = src.getParentFile();
+ final String outPath;
+ if(parentFile != null) {
+ outPath = parentFile.getAbsolutePath();
+ } else {
+ outPath = ""; // may set to default outPath?
+ // or throw Exception
+ // throw new IOException("use absolute file names");
+ }
PdfDictionary catalog = reader.getCatalog();
PdfDictionary names = (PdfDictionary) PdfReader
.getPdfObject(catalog.get(PdfName.NAMES));
@@ -176,11 +185,11 @@
throw new InstantiationException("There is more than one
destfile.");
}
- public static void unpackFile(PdfReader reader, PdfDictionary filespec,
- String outPath) {
+ public static void unpackFile(PdfReader reader, PdfDictionary filespec,
+ String outPath) throws IOException {
if (filespec == null)
return;
- try {
+
PdfName type = (PdfName) PdfReader.getPdfObject(filespec
.get(PdfName.TYPE));
if (!PdfName.F.equals(type) &&
!PdfName.FILESPEC.equals(type))
@@ -205,8 +214,7 @@
FileOutputStream fout = new FileOutputStream(fullPath);
fout.write(b);
fout.close();
- } catch (Exception e) {
- }
+
}
}
--
Schönen Gruß
Eberhard Schulte
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions