Hi,
I'm using the following code to merge two pdf Documents to form a single pdf document. My pgm runs well and the output also generated.
But when i try to open the output pdf i get the following error msg
"There is an error opening the document. There is a problem reading the document(109)."
I'm using Adobe Reader 7.0.5 version,
i also tried opening the same document with other versions 4.0 and 5.0 but still i get the same error.
String fStrFileName = "Merged.pdf";
String[] files = new String[2];
files[0] = "C:/Dataglance/Product/Source/Sample1.pdf";
files[1] = "C:/Dataglance/Product/Source/Sample2.pdf";
PdfCopy writer = null;
Document doc = null;
for(int i=0;i<2;i++)
{
PdfReader reader = new PdfReader(files[i]);
if (i == 0) {
// step 1: creation of a document-object
doc = new Document(reader.getPageSizeWithRotation(1));
// step 2: we create a writer that listens to the document
writer = new PdfCopy(doc, new FileOutputStream(fStrFileName));
// step 3: we open the document
doc.open();
}
int n = reader.getNumberOfPages();
System.out.println("There are " + n + " pages in " + files[i]);
PdfImportedPage page;
for (int p = 0; p < n; ) {
++p;
page = writer.getImportedPage(reader, p);
writer.addPage(page);
System.out.println("Processed page " + p);
}
}
doc.close();
Any help is highly Appreciated.
Thanks,
satya.
