Hello,
I tried to use iText.
I made a simple program able to copy a PDF document.
Just read a document and create another one copying one page at a time.
The source code below.
I used some code from the Concatenate.java example.
The program works with several files but I have a 11MByte PDF file that get the program crazy.
I tried to use iText.
I made a simple program able to copy a PDF document.
Just read a document and create another one copying one page at a time.
The source code below.
I used some code from the Concatenate.java example.
The program works with several files but I have a 11MByte PDF file that get the program crazy.
When I run copyPDF on this file I have the following output:
Import pages as images
Permission = -64
File Length= 11838051
PDF Version= 3
PDF Pag Num= 658
1
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyArray(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
Permission = -64
File Length= 11838051
PDF Version= 3
PDF Pag Num= 658
1
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyArray(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
<... it continue for several lines ...>
The created file is 6MByte long but it can not be opened with Acrobat reader and it seems that it is not a PDF file.
I tested the program with different files 5 and 6 MByte long with no issues.
I tested the program with different files 5 and 6 MByte long with no issues.
Have anyone an idea about what can couse the issue?
It is caused by the contents of the file?
I can provide the "tricky" PDF file but it is 11MByte long ...
Thank you to everyone will help me.
Lorenzo
It is caused by the contents of the file?
I can provide the "tricky" PDF file but it is 11MByte long ...
Thank you to everyone will help me.
Lorenzo
P.S. copy the itext jar and copyPDF.java in the same directory.
build the program with:
javac -classpath ./;./itext-1.3.3.jar copyPDF.java
run the program with
java -classpath ./;./itext-1.3.3.jar copyPDF my.pdf
build the program with:
javac -classpath ./;./itext-1.3.3.jar copyPDF.java
run the program with
java -classpath ./;./itext-1.3.3.jar copyPDF my.pdf
------------------------------------------------------------------------
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
import com.lowagie.text.Document;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PRAcroForm;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.SimpleBookmark;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PRAcroForm;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.SimpleBookmark;
public class copyPDF {
public static void main(String[] args) {
try {
try {
ArrayList master = new ArrayList();
String outFile = "new-"+args[0];
Document document = null;
PdfCopy writer = null;
// we create a reader for a certain document
PdfReader reader = new PdfReader(args[0]);
System.out.println("Permission = "+reader.getPermissions());
System.out.printl n("File Length= "+reader.getFileLength());
System.out.println("PDF Version= "+reader.getPdfVersion());
String outFile = "new-"+args[0];
Document document = null;
PdfCopy writer = null;
// we create a reader for a certain document
PdfReader reader = new PdfReader(args[0]);
System.out.println("Permission = "+reader.getPermissions());
System.out.printl n("File Length= "+reader.getFileLength());
System.out.println("PDF Version= "+reader.getPdfVersion());
reader.consolidateNamedDestinations();
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
System.out.println("PDF Pag Num= "+n);
// 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();
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
System.out.println("PDF Pag Num= "+n);
// 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;
System.out.println(i);
page = writer.getImportedPage(reader, i);
writer.addPage(page);
}
PdfImportedPage page;
for (int i = 0; i < n; ) {
++i;
System.out.println(i);
page = writer.getImportedPage(reader, i);
writer.addPage(page);
}
document.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
}
}
catch (Exception de) {
de.printStackTrace();
}
}
}
Yahoo! Mail: gratis 1GB per i messaggi, antispam, antivirus, POP3
