For those who haven�t read my last post i summarize what was it about.
I have a script based from the threaded Servlet introduced in the tutorial,
and it generates a pdf file that contains like a photo album, containing
about 100 images of about 100k each.
The program worked all right with about 30 images, but when i ask for more
than 39 images, the servlet didn�t made any output (no error, no pdf,
nothing).
Paulo suggested me that it was a memory problem, but i couldn�t trace it,
because you can�t trace a thread (i can�t, i don�t know if anyone can,
mostly servlet threads!!).
So, i moved my code to a simple servlet, no threads, nothing.
The error it throws is this
----------------------------------------------------------------------------
----
exception
javax.servlet.ServletException: Invoker service() exception
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java
:524)
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
Root cause
java.lang.OutOfMemoryError
----------------------------------------------------------------------------
----
So, the question goes in this direction.
How can i add so many images to the pdf, without filling my server�s
memory???
This is the peace of code that generates de pdf.
ResultSet AImprimir = StatementAImprimir.executeQuery();
while(AImprimir.next()) {
if (i % (2 * numCols) == 0) {
if ((cantImagenes - i) > numCols) {
sc.log("agregando tabla al documento");
doc.add(table);
table = null;
Runtime r = Runtime.getRuntime();
r.gc();
table = new PdfPTable(numCols);
table.setWidthPercentage(tableWidthPercentage);
table.setExtendLastRow(false);
};
};
sc.log("agregando a tabla imagen " + (new Integer(i +
1)).toString() + " de " + (new Integer(cantImagenes)).toString());
p = 100 * i / cantImagenes;
imageTable = new PdfPTable(1);
nombreImagen = AImprimir.getString("nombre");
//Creo una tabla para cada imagen, con la imagen y su nombre
debajo
try {
image = Image.getInstance(filePath + nombreImagen);
if (orientar != 0) { //no orientar
float ratio = image.plainWidth() /
image.plainHeight();
if (orientar == 1) { //horizontal
if (ratio < 1) image.setRotationDegrees(90);
} else if (orientar == 2) { //vertical
if (ratio > 1) image.setRotationDegrees(90);
};
};
imageTable.addCell(image);
imageTable.addCell(nombreImagen);// + " " + new
Integer(i).toString());
sc.log("imagen agregada a tabla");
} catch (BadElementException e) {
sc.log("BadElementException" + e.getStackTrace());
imageTable = new PdfPTable(1);
imageTable.addCell(nombreImagen + " no esta
disponible.");
} catch (MalformedURLException e) {
sc.log("MalformedURLException" + e.getStackTrace());
imageTable = new PdfPTable(1);
imageTable.addCell(nombreImagen + " no esta
disponible.");
} catch (IOException e) {
sc.log("IOException:" + e.getStackTrace());
imageTable = new PdfPTable(1);
imageTable.addCell(nombreImagen + " no esta
disponible.");
};
table.addCell(imageTable);
i++;
};
while (cantImagenes % numCols != 0) { sc.log("completando
tabla");table.addCell(new Paragraph("")); cantImagenes++;};
doc.add(table);
sc.log("agregando tabla final al documento");
//doc.add(new Paragraph(new Integer(cantImagenes).toString()));
p = 100;
Thanks All!!
Nicolas Andres Pace
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions