pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre Dubillot <alexcou...@gmail.com>
Subject Fwd: PDFRenderer : RandomAccessBuffer already closed (PDFBox 2.0)
Date Thu, 25 Jun 2015 16:56:52 GMT
I'm having an issue while trying to create an image output :

java.io.IOException: RandomAccessBuffer already closed
> at
> org.apache.pdfbox.io.RandomAccessBuffer.checkClosed(RandomAccessBuffer.java:433)
> at
> org.apache.pdfbox.io.RandomAccessBuffer.length(RandomAccessBuffer.java:292)
> at org.apache.pdfbox.cos.COSStream.copyBuffer(COSStream.java:361)
> at org.apache.pdfbox.cos.COSStream.doDecode(COSStream.java:334)
> at
> org.apache.pdfbox.cos.COSStream.checkUnfilteredBuffer(COSStream.java:265)
> at org.apache.pdfbox.cos.COSStream.getUnfilteredStream(COSStream.java:214)
> at
> org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:232)
> at
> org.apache.pdfbox.pdmodel.graphics.color.PDICCBased.loadICCProfile(PDICCBased.java:115)
> at
> org.apache.pdfbox.pdmodel.graphics.color.PDICCBased.<init>(PDICCBased.java:89)
> at
> org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.create(PDColorSpace.java:160)
> at
> org.apache.pdfbox.pdmodel.PDResources.getColorSpace(PDResources.java:111)
> at
> org.apache.pdfbox.contentstream.operator.color.SetNonStrokingColorSpace.process(SetNonStrokingColorSpace.java:41)
> at
> org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:795)
> at
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:462)
> at
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:438)
> at
> org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149)
> at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:180)
> at org.apache.pdfbox.rendering.PDFRenderer.renderPage(PDFRenderer.java:205)
> at
> org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:136)
> at
> org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:81)
> at metier.parseur.ParserPDF.pdfImgsToXml(ParserPDF.java:62)
> at metier.parseur.ParserPDF.preLoad(ParserPDF.java:45)
> at metier.MetierLoader.getPage(MetierLoader.java:34)
> at action.ActionLoader.chargerPage(ActionLoader.java:15)
> at action.ActionSora.doPost(ActionSora.java:35)
>

With the following code :

private static String pdfImgsToXml() throws IOException {
>
> int pageNumber = 1;
>
> String imgs = "<imgs>\n";
>
> PDFRenderer renderer = new PDFRenderer(pdf);
>
> int numPages = pdf.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) {
>
> // TODO Auto-generated catch block
>
> e.printStackTrace();
>
> }
>
>  pageNumber++;
>
> }
>
>  return imgs + "</imgs>";
>
> }
>
>
My app is running on a Java EE Server, trying to write rendered images to
byte array to put them in XML.
But first I need to render them, and that's not working.

Thanks,
Pierre

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message