pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Fwd: PDFRenderer : RandomAccessBuffer already closed (PDFBox 2.0)
Date Sat, 27 Jun 2015 12:28:40 GMT
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: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message