It's a bug. It will be fixed in the next release.
Best Regards,
Paulo Soares
-----Original Message-----
From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED] On Behalf Of Noah Mattern
Sent: Thursday, January 22, 2004 19:40
To: [EMAIL PROTECTED]
Subject: [iText-questions] Problem with Barcodes, PdfStamper.close() and Acrobat v4
I was able to create and place a barcode on a PDF created with Acrobat 6.
However, when I run the same code with a PDF created by Acrobat 4.0, I
receive the following error when attempting to close the PdfStamper:
'java.lang.ArrayIndexOutOfBoundsException: 6'
Any ideas would be greatly appreciated.
Thanks
Noah
A simplified version of the code I am attempting to run:
/*
* Barcode.java
*
* Created on January 21, 2004, 11:37 AM
*/
import java.util.*;
import java.sql.*;
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class Barcode {
public static void main(String args[]) {
try {
byte[] pdfBytesOut = null;
PdfReader reader = null;
ByteArrayOutputStream pdfOutput = null;
PdfStamper stamper = null;
System.out.println("Start");
String filename = "c:\\temp\\Blank_v4.pdf"; // a PDF made via
Acrobat 4.0
// String filename = "c:\\temp\\Blank_v6.pdf"; // a PDF made via
Acrobat 6
FileInputStream inStream = new FileInputStream( filename );
int byteCount = inStream.available();
byte[] pdfBytes = new byte[byteCount];
inStream.read(pdfBytes, 0, byteCount);
// read the PDF into an object
reader = new PdfReader( pdfBytes );
// make the output object
pdfOutput = new ByteArrayOutputStream();
stamper = new PdfStamper(reader, pdfOutput);
// add any barcodes to the PDF
try {
PdfContentByte cb = stamper.getOverContent(1);
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(codeEAN.EAN13);
codeEAN.setCode("9780201615883");
PdfTemplate barCodeTemplate =
codeEAN.createTemplateWithBarcode(cb, null, null);
cb.addTemplate(barCodeTemplate, barCodeTemplate.getWidth() *
0.02f, 0, 0, barCodeTemplate.getHeight() * 0.03f, 20f, 200f );
}
catch( Exception e ){
System.out.println( "Unable to add barcodes to PDF: " +
e.toString() );
}
// close the stamper object
try{
/******* THIS LINE FAILS *******/
stamper.close();
}
catch( Exception e ){
System.out.println( "Unable to close the PdfStamper: " +
e.toString() );
}
System.out.println("End");
}
catch( Exception e ) {
System.out.println( "Error: " + e.toString() );
}
}
}
<< File: Blank_v4.pdf >> << File: Blank_v6.pdf >>