Hi,
I've a problem with the below code.
public class CreateBigDocument {
static public String[] sortFileList(File[] fileList) {
String[] list = new String[fileList.length];
for(int c = 0; c < fileList.length; c++) {
list[c] = new String(fileList[c].getAbsolutePath());
}
Arrays.sort(list);
return list;
}
/**
* This class can be used to concatenate existing PDF files.
* (This was an example known as PdfCopy.java)
* @param args the command line arguments
*/
public static void main(String args[]) {
if (args.length < 2) {
System.err.println("arguments: srcdir destfile");
}
else {
File dir = new File(args[0]);
FileFilter fileFilter = new FileFilter() {
public boolean accept(File file) {
return !file.isDirectory();
}
};
String[] fileList = sortFileList(dir.listFiles(fileFilter));
try {
String outFile = args[args.length-1];
Document document = null;
PdfCopy writer = null;
int totPages = 0;
for(int f = 0; f < fileList.length; f++) {
// we create a reader for a certain document
PdfReader reader = new PdfReader(fileList[f]);
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
System.out.println("There are " + n + " pages in " +
fileList[f]);
String title =
(String)reader.getInfo().get("Title");
if (f == 0) {
// step 1: creation of a document-object
document = new Document(reader.getPageSizeWithRotation(1));
// step 2: we create a writer that listens to the
document
writer = new PdfCopy(document, new FileOutputStream(outFile));
// step 3: we open the document
document.open();
}
// step 4: we add content
PdfImportedPage page;
for (int i = 0; i < n; ) {
++i;
page = writer.getImportedPage(reader, i);
writer.addPage(page);
System.out.println("Processed page " + i);
PdfContentByte cb = writer.getDirectContent();
cb.addOutline(new PdfOutline(cb.getRootOutline(),
new PdfAction(fileList[f], 1), fileList[f]), fileList[f]);
}
PRAcroForm form = reader.getAcroForm();
if (form != null)
writer.copyAcroForm(reader);
}
// step 5: we close the document
document.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
}
This return the below error but I don't know if the error is in my code
or if it's in the library (iText 1.00).
There are 1 pages in D:\Temp\Chap1107.pdf
Processed page 1
java.lang.NullPointerException
at com.lowagie.text.pdf.PdfDocument.localDestination(PdfDocument.java:2663)
at com.lowagie.text.pdf.PdfDocument.addOutline(PdfDocument.java:2312)
at com.lowagie.text.pdf.PdfContentByte.addOutline(PdfContentByte.java:1234)
at
it.cedimension.cedocument.samples.CreateBigDocument.main(CreateBigDocument.java:85)
Thank you for all,
Paolo Aldovini
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions