Bom dia, estou com um problema e gostaria da ajuda de vcs. O problema é o seguinte estou usando o itext na minha aplicação para manipular pdf, tudo funcionava bem porem tem um caso onde uns pdfs são manipulados e unificados gerando um unico pdf de 920 páginas causando o estouro de memória, meu metodo esta assim :
public static byte[] juntarPDFs(List<byte[]> listaPDF) throws DocumentException, IOException {
ByteArrayOutputStream bArray = new ByteArrayOutputStream();
Document document = new Document();
PdfCopy copy = new PdfCopy(document, bArray);
document.open();
for(byte[] pdfBytes : listaPDF){
PdfReader reader = new PdfReader(new RandomAccessFileOrArray(pdfBytes), null);
int paginas = reader.getNumberOfPages();
for(int i = 1; i < (paginas + 1) ;i++){
PdfImportedPage page = copy.getImportedPage(reader, i);
copy.addPage(page);
}
}
document.close();
return bArray.toByteArray();
}
no momento em que dou ‘bArray.toByteArray();’ é causado o estouro, pois é onde tudo é carregado em memoria para retornar para o browser. Obrigado desde já.
Vc esta fechando todos os recursos utilizados no método, depois que foram usados?
Qual estouro que está dando ?? StackOverflow ou PermGen space ??
Abs []
O erro é de stack, segue ela :
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.io.ByteArrayOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.write(Unknown Source)
at java.io.FilterOutputStream.write(Unknown Source)
at com.lowagie.text.pdf.OutputStreamCounter.write(Unknown Source)
at com.lowagie.text.pdf.PRStream.toPdf(Unknown Source)
at com.lowagie.text.pdf.PdfIndirectObject.writeTo(Unknown Source)
at com.lowagie.text.pdf.PdfWriter$PdfBody.add(Unknown Source)
at com.lowagie.text.pdf.PdfWriter$PdfBody.add(Unknown Source)
at com.lowagie.text.pdf.PdfWriter$PdfBody.add(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.addToBody(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyIndirect(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyObject(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.copyDictionary(Unknown Source)
at com.lowagie.text.pdf.PdfCopy.addPage(Unknown Source)
at br.com.dataeasy.core.office.pdf.PDFUtil.juntarPDFs(PDFUtil.java:1103)
at br.com.dataeasy.docflow3.bus.ctr.negocio.impl.ImprimirBO.imprimirDocumentos(ImprimirBO.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at br.com.dataeasy.core.security.SecurityProxy.invoke(SecurityProxy.java:54)
at $Proxy257.imprimirDocumentos(Unknown Source)
at br.com.dataeasy.docflow3.web.ctr.bean.ImprimirDocumentoBean.visualizarImpressao(ImprimirDocumentoBean.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
Minha configuração de memória está:
-XX:MaxPermSize=512m
-Xmx1g
-Xms256m