Hi, This little advice solved my problem, thanks ! Pierre,
2015-06-27 14:28 GMT+02:00 Tilman Hausherr <[email protected]>: > Am 26.06.2015 um 15:53 schrieb Pierre Dubillot: > >> private String pdfImgsToXml(byte[] pdfBytes) throws IOException { >> >>> >int pageNumber = 1; >>> >String imgs = "<imgs>\n"; >>> >pdfSplitted = new PDDocument(); >>> >System.out.println(new String(pdfBytes)); >>> >pdfSplitted = PDDocument.load(pdfBytes); >>> >PDFRenderer renderer = new PDFRenderer(pdfSplitted); >>> >/* Test enregistrement >>> >pdfSplitted.save("D:/Stage_DUT/pdfConverter/pdf/test4.pdf"); >>> > */ >>> >int numPages = pdfSplitted.getNumberOfPages(); >>> >for (int i = 0; i < numPages; i++) { >>> >imgs = imgs + "<img" + pageNumber + ">"; >>> >try { >>> >BufferedImage image = renderer.renderImageWithDPI(i, 200); >>> >ByteArrayOutputStream baos = new ByteArrayOutputStream(); >>> >ImageIO.write( image, "jpg", baos ); >>> >//baos.flush(); >>> >byte[] imageInByte = baos.toByteArray(); >>> >baos.close(); >>> >String imgString = Base64.encode(imageInByte); >>> >imgs = imgs + imgString + "</img" + pageNumber + ">\n"; >>> >} catch (Exception e){ >>> >e.printStackTrace(); >>> >} >>> >pageNumber++; >>> >} >>> >return imgs + "</imgs>"; >>> >} >>> >> As you can see,* all documents are closed (theory not practice)*. >> Strange >> thing. (Used try-catch-finally to force this). Any advice ? >> >> > Yes, avoid this: > > pdfSplitted = new PDDocument(); > System.out.println(new String(pdfBytes)); > pdfSplitted = PDDocument.load(pdfBytes); > > > You created an empty document, and then overwrote the variable. And I > don't see where you close > pdfSplitted. > > > Tilman > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >

