[ 
https://issues.apache.org/jira/browse/PDFBOX-1983?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13936348#comment-13936348
 ] 

John Hewson commented on PDFBOX-1983:
-------------------------------------

Yes, ximage.getImage() should be returning an image. I took a look at this and 
it was a caused by a combination of the way that JPEGFactory and CCITTFactory 
use PDStream, the fact that PDStream performs caching when it probably 
shouldn't, and the fact that COSStream#getLength() returns the dictionay value 
and not the current stream length.

There's a fundamental problem here which is that COSStream allows its stream to 
be written to but does not return the length in getLength. I think that the 
fact that the underlying stream can be manipulated by classes outside of 
COSStream is the issue. COSStream has no way to know when its stream has been 
modified! I think we need to rethink the design of this at some point, it looks 
like COSStream should subclass InputStream and/or OutputStream so that it knows 
when the stream is being manipulated, rather than just returning e.g. an 
InputStream which anyone can mess with via e.g. getFilteredStream().

Anyway, I've basically just added a workaround in 1577959 to sidestep the 
problem for now and enabled the portions of the tests which were commented out.

> Unable to add TIF images, CCITTFactory not working
> --------------------------------------------------
>
>                 Key: PDFBOX-1983
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1983
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.0
>            Reporter: Joel Kääpä
>            Assignee: Tilman Hausherr
>             Fix For: 2.0.0
>
>         Attachments: G4.tif, huhu.pdf
>
>
> As used in the AddImageToPDF example, the following line generates an error 
> with tif image:
> PDImageXObject ximage =  CCITTFactory.createFromRandomAccess(document, new 
> RandomAccessFile(new File(imagePath), "r"));
> java.io.IOException: Stream was not read
>         at org.apache.pdfbox.cos.COSStream.getDecodeResult(COSStream.java:235)
>         at 
> org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.<init>(PDImageXObject.java:80)
>         at 
> org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.<init>(PDImageXObject.java:70)
>         at 
> org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.createFromRandomAccess(CCITTFactory.java:50)



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to