Hi,
I have the following code but am erroring out with an ArrayIndexOutOfBounds
exception. what am I doing wrong.
@param: pdfPath: path to a file
pageNumbers: Vector of page numbers.
public static void removePages (String pdfPath, Vector pageNumbers) throws
Exception{
PdfReader reader = new PdfReader(inpFile);
int n = reader.getNumberOfPages();
Document document = null;
PdfCopy writer = null;
boolean first = true;
String fileName = pdfPath;
for(int j = 1; j <= n;){
PdfDictionary page1;
page1 = reader.getPageN(j);
PdfDictionary annot = null;
for ( int i = 0; i < pageNumbers.size(); i++){
Integer pageNum
=(Integer)pageNumbers.elementAt(i);
int checkPg = pageNum.intValue();
if (j == checkPg){
j++;
continue;
}
}
if(first){
document = new
Document(reader.getPageSizeWithRotation(1));
writer = new PdfCopy(document, new
FileOutputStream(fileName));
document.open();
first = false;
}
PdfImportedPage page;
int z = j;
page = writer.getImportedPage(reader, z);
writer.addPage(page);
PRAcroForm form = reader.getAcroForm();
if (form != null) {
writer.copyAcroForm(reader);
}
j++;
}
document.close();
}
purpose of the method is that, the Vector object contains some page numbers. I
need to remove those pages from the input file . The output file is stored in
the same location as the input file and with the same name. Can you give me
some suggestions as to how I an do that?
IF I CREATE A NEW FILE WITH A NEW FILE NAME, THEN IT WORKS PERFECTLY, BUT IF I
WANT TO OVERWRITE THE INPUT FILE IT IS ERRORING OUT. I WAS THINKING, ONCE THE
PDFREADER HAS READ THE FILE, IT WILL NOT HAVE ANY ASSOCIATION WITH THE FILE
ITSELF AND HENCE I SHOULD BE ABLE TO OVERWRITE THE FILE. AM I THINKING WRONG???
Thank You
Kalkunda Venkat
515 362 0241
x-20241
-----Message Disclaimer-----
This e-mail message is intended only for the use of the individual or
entity to which it is addressed, and may contain information that is
privileged, confidential and exempt from disclosure under applicable law.
If you are not the intended recipient, any dissemination, distribution or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify us immediately by
reply email to [EMAIL PROTECTED] and delete or destroy all copies of
the original message and attachments thereto. Email sent to or from the
Principal Financial Group or any of its member companies may be retained
as required by law or regulation.
Nothing in this message is intended to constitute an Electronic signature
for purposes of the Uniform Electronic Transactions Act (UETA) or the
Electronic Signatures in Global and National Commerce Act ("E-Sign")
unless a specific statement to the contrary is included in this message.
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions