It was a bug in the postscript processing, a dispose() was missing. The fix
is in the CVS.
The explanation is interesting. The ByteBuffer.toByteArray() creates a new
array with count bytes. As the array in this case is big, about 2M, it
usually forces a GC. This GC causes the dispose() to be called that causes
some bytes to be written to this ByteBuffer. The end result is that the
array has count bytes but count was incremented by the CG thread and when it
reaches arraycopy() count is bigger that it was and there's the exception.

----- Original Message ----- 
From: "Carsten Hammer" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, October 17, 2005 10:54 PM
Subject: [iText-questions] PdfTemplate going wild


> Hi,
> does anybody know why I get this exception:
>
> java.lang.ArrayIndexOutOfBoundsException
>
> at java.lang.System.arraycopy(Native Method)
>
> at com.lowagie.text.pdf.ByteBuffer.toByteArray(ByteBuffer.java:538)
>
> at com.lowagie.text.pdf.PdfContentByte.toPdf(PdfContentByte.java:219)
>
> at com.lowagie.text.pdf.PdfFormXObject.<init>(PdfFormXObject.java:98)
>
> at com.lowagie.text.pdf.PdfTemplate.getFormXObject(PdfTemplate.java:218)
>
> at
> com.lowagie.text.pdf.PdfWriter.addSharedObjectsToBody(PdfWriter.java:1170)
>
> at com.lowagie.text.pdf.PdfWriter.close(PdfWriter.java:1234)
>
> at com.lowagie.text.pdf.PdfDocument.close(PdfDocument.java:951)
>
> at com.lowagie.text.Document.close(Document.java:520)
>
> at inlinepostscript.<init>(inlinepostscript.java:85)
>
> at inlinepostscript.main(inlinepostscript.java:96)
>
>
> using the attached code?
>
> For inlinepostscript.java to run I needed the following constructor to
> add to ImgPostscript.java:
>
> public ImgPostscript(byte[] content,float width,float height) throws
> BadElementException, IOException {
>         super( (URL)null);
>         rawData = content;
>         originalData = content;
>         processParameters();
>         this.urx=width;
>         this.ury=height;
>     }
>
> Any idea?
>
> Best regards,
> Carsten
>


----------------------------------------------------------------------------
----


> import com.lowagie.text.ImgPostscript;
>
> import java.io.FileOutputStream;
>
> import com.lowagie.text.pdf.*;
> import com.lowagie.text.*;
>
> public class inlinepostscript {
>   public inlinepostscript() {
>     try {
>
>       Document document = new Document();
>       PdfWriter pdfwriter = PdfWriter.getInstance(document,
>                                                   new FileOutputStream(
>           "inlinetest.pdf"));
>       document.compress = false;
>       document.open();
>
>       PdfContentByte cb = pdfwriter.getDirectContentUnder();
>       cb.addImage(new ImgPostscript( ("/Helvetica-Bold findfont " +
>                                       "50 scalefont setfont " +
>                                       "/oshow" +
>                                       "{ true charpath stroke } def\n" +
>                                       "/circleofItext" +
>                                       "{ 30 15 345\n" +
>                                       "{ gsave\n" +
>                                       "rotate 0 0 moveto\n" +
>                                       "(      itext) oshow\n" +
>                                       "grestore\n" +
>                                       "} for\n" +
>                                       "} def\n" +
>                                       "250 400 translate\n" +
>                                       ".5 setlinewidth\n" +
>                                       "circleofItext\n" +
>                                       "showpage\n").
>                                     getBytes(), 500, 800), 500, 0, 0, 800,
0, 0);
>
>       for (int i = 0; i < 30; i++) {
>         document.add(new Paragraph("Hello World Hello World Hello
World"));
>       }
>       document.newPage();
>
>       cb = pdfwriter.getDirectContentUnder();
>
>       cb.addImage(new ImgPostscript( ("%!PS-Adobe-1.0 \n" +
>                                       "%%DocumentFonts: Courier \n" +
>                                       "%%Title: Random Fern \n" +
>                                       "%%Creator: Eric Wicklund from
algoritm of John Wicklund \n" +
>                                       "%%EndComments \n" +
>                                       "/m1 [  0.00  0.00  0.00  0.16  0.00
0.00 ] def \n" +
>                                       "/m2 [  0.85 -0.04  0.04  0.85  0.00
1.60 ] def \n" +
>                                       "/m3 [  0.20  0.23 -0.26  0.22  0.00
1.60 ] def \n" +
>                                       "/m4 [ -0.15  0.26  0.28  0.24  0.00
0.44 ] def \n" +
>                                       "/inch {72 mul} bind def \n" +
>                                       "%%EndProlog \n" +
>                                       "%%Page: 1 1 \n" +
>                                       "save \n" +
>                                       "% will draw inside a 8 inch square
centered on \n" +
>                                       "% a 8.5 by 11 inch page \n" +
>                                       "4.25 inch 1.5 inch translate \n" +
>                                       "0.8 inch dup scale \n" +
>                                       "% x coordinate ranges from -5 to 5
\n" +
>                                       "% y coordinate ranges from 0 to 10
\n" +
>                                       "1 setlinecap \n" +
>                                       "0.005 setlinewidth \n" +
>                                       "0.36 0.63 0.07 setrgbcolor \n" +
>                                       "% first point at the origin \n" +
>                                       " 0 0 \n" +
>                                       " 100000 { \n" +
>                                       "       % Pick a transformation
matrix probabilitistically \n" +
>                                       "       rand 100 mod \n" +
>                                       "         dup  1 lt { pop m1 } \n" +
>                                       "       { dup 86 lt { pop m2 } \n" +
>                                       "       { dup 93 lt { pop m3 } \n" +
>                                       "                   { pop m4 }
ifelse } ifelse } ifelse \n" +
>                                       "        transform 2 copy moveto 0 0
rlineto stroke \n" +
>                                       "} repeat \n" +
>                                       "showpage").
>                                     getBytes(), 500, 800), 500, 0, 0, 800,
0, 0);
>
>       for (int i = 0; i < 30; i++) {
>         document.add(new Paragraph("Hello World Hello World Hello
World"));
>       }
>
>       document.close();
>
>       System.out.println("Finished.");
>     }
>     catch (Exception de) {
>       de.printStackTrace();
>     }
>
>   }
>
>   public static void main(String[] args) {
>     inlinepostscript inlinepostscript = new inlinepostscript();
>   }
> }
>



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to