pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre Dubillot <alexcou...@gmail.com>
Subject Re: Fwd: PDFRenderer : RandomAccessBuffer already closed (PDFBox 2.0)
Date Mon, 29 Jun 2015 08:19:24 GMT
Hi,
This little advice solved my problem, thanks !

Pierre,

2015-06-27 14:28 GMT+02:00 Tilman Hausherr <THausherr@t-online.de>:

> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message