Q: I´m working with the pdftron for windows library JAVAversion, and
when i process many pdf files (as much as 100 files) I´ve got the
following error:
bad allocation
The code of the JAVA routine used to convert PDF to image (where the
error raise) is as follows:
private void decodeFile(InformacionPdf informacionPdf) throws
CLException {
PDFNet.initialize(valorProperty);
PDFDraw draw = null;
PDFDoc doc = null;
if(!PDFNet.setResourcesPath(valorProperty))
throw new CLException(BossError.ERR_CONEXION,"No se pudo
setear el path del recurso. NO se encontro el recurso en (" +
valorProperty +")");
try {
doc = new PDFDoc(informacionPdf.getNombreArchivo());
draw = new PDFDraw();
doc.initSecurityHandler();
if(informacionPdf.getDpi() > 0)
draw.setDPI(informacionPdf.getDpi());
else
draw.setImageSize(informacionPdf.getWidth(),
informacionPdf.getHeight());
pdftron.PDF.Page page = doc.getPage(1);
// draw.export(page, jpgFileName);
// Convert the firts page in a stream JPG.
ImageIO.write(draw.getBitmap
(page),"PNG",informacionPdf.getOutputImage());
}
catch (Exception ex){
throw new CLException(BossError.ERR_INDETERMINADO,"Error
generando imagen -->> " + ex.getMessage(),ex); <--- line
260
}
finally {
if (doc != null)
try {
doc.close();
} catch (PDFNetException e) {
throw new CLException
(BossError.ERR_INDETERMINADO,e.getMessage(),e);
}
PDFNet.terminate();
}
}
Could you help me?
-----
A: The most likely problem is that Java garbage collector is not
collecting object in time which could lead to resource exhaustion.
You can explicitly release any memory associated with a large object
(such as PDFDraw, ElementBuilder, ElementWriter, TextExtractor, etc)
by calling destroy() when the object is no longer in use. For
example:
draw = new PDFDraw();
…
draw.export(page, jpgFileName);
…
draw.destroy();