You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Antoni Mylka (JIRA)" <ji...@apache.org> on 2011/07/25 15:23:10 UTC

[jira] [Created] (PDFBOX-1075) Can't get images from a PDF

Can't get images from a PDF
---------------------------

                 Key: PDFBOX-1075
                 URL: https://issues.apache.org/jira/browse/PDFBOX-1075
             Project: PDFBox
          Issue Type: Bug
          Components: Parsing
    Affects Versions: 1.6.0, 1.7.0
            Reporter: Antoni Mylka
             Fix For: 1.4.0


This is a regression. In 1.4.0 I was able to extract images from a PDF file. In 1.6 and the current trunk I get exceptions:

SEVERE: java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
	at java.awt.image.BufferedImage.<init>(BufferedImage.java:611)
	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:252)
	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.write2OutputStream(PDPixelMap.java:289)
	at org.apache.pdfbox.TestGovdocs148902.test148902(TestGovdocs148902.java:58)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at junit.framework.TestCase.runTest(TestCase.java:168)
	at junit.framework.TestCase.runBare(TestCase.java:134)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:124)
	at junit.framework.TestSuite.runTest(TestSuite.java:232)
	at junit.framework.TestSuite.run(TestSuite.java:227)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

http://domex.nps.edu/corp/files/govdocs1/148/148902.pdf

I pasted it into the src/test/resources/pdfparser folder and run a test case like this:

public class TestGovdocs148902 extends TestCase
{

    public void test148902() throws IOException {
        PDDocument doc = PDDocument.load( "src/test/resources/pdfparser/148902.pdf");
        int imageCounter = 0;
        COSDocument cosDoc = doc.getDocument();
        List<COSObject> list = cosDoc.getObjectsByType(COSName.XOBJECT);
        
        for (COSObject cosOb : list) {
            COSBase baseObject = cosOb.getObject();
            if (baseObject != null && baseObject instanceof COSStream) {
                COSStream st = (COSStream)baseObject;
                String subtype = st.getNameAsString(COSName.SUBTYPE);
                if (subtype != null && subtype.equalsIgnoreCase("image")) {
                    PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( st );
                    if (ximage != null && ximage.getWidth() >= 5 && ximage.getHeight() >= 5) {
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        ximage.write2OutputStream(baos);
                        byte [] bytes = baos.toByteArray();
                        if (bytes.length > 0) {
                            imageCounter++;
                        }
                    }
                }
            }
        }
        
        assertEquals(32, imageCounter);
    }
}

The test cases passes in 1.4.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (PDFBOX-1075) Can't get images from a PDF

Posted by "Antoni Mylka (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13084046#comment-13084046 ] 

Antoni Mylka commented on PDFBOX-1075:
--------------------------------------

Narrowed the problem further.

AFAIU:

In PDPixelMap.getImage the basic algorithm is:
1. get the color model
2. create a compatible WritableRaster
3. copy the bytes from the PDF to the buffer of the raster
4. initialize a buffered image with the color model and the raster

Only part 1. changed in r1133281. Parts 2,3,4 are the same.

In the old version, the color model returned would be: (taken from toString())
IndexColorModel: #pixelBits = 1 numComponents = 4 color space = java.awt.color.ICC_ColorSpace@7736bd transparency = 2 transIndex   = 1 has alpha = true isAlphaPre = false

In the new version:
IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1bac748 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false

The new version has only 3 components(no alpha channel, no transparency). The old version included the alpha channel and the transparency.

Now the real problem seems to have surfaced when I did something like this:

WritableRaster raster = cm.createCompatibleWritableRaster( width, height );            
if (!cm.isCompatibleRaster(raster)) {
        System.out.println("Color model created an incompatible raster");
}

So it seems that in the new version, for this pdf, the createCompatibleWritableRaster method returns rasters which are NOT compatible. 

> Can't get images from a PDF
> ---------------------------
>
>                 Key: PDFBOX-1075
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1075
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.6.0, 1.7.0
>            Reporter: Antoni Mylka
>
> This is a regression. In 1.4.0 I was able to extract images from a PDF file. In 1.6 and the current trunk I get exceptions:
> SEVERE: java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> 	at java.awt.image.BufferedImage.<init>(BufferedImage.java:611)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:252)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.write2OutputStream(PDPixelMap.java:289)
> 	at org.apache.pdfbox.TestGovdocs148902.test148902(TestGovdocs148902.java:58)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:168)
> 	at junit.framework.TestCase.runBare(TestCase.java:134)
> 	at junit.framework.TestResult$1.protect(TestResult.java:110)
> 	at junit.framework.TestResult.runProtected(TestResult.java:128)
> 	at junit.framework.TestResult.run(TestResult.java:113)
> 	at junit.framework.TestCase.run(TestCase.java:124)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:232)
> 	at junit.framework.TestSuite.run(TestSuite.java:227)
> 	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> http://domex.nps.edu/corp/files/govdocs1/148/148902.pdf
> I pasted it into the src/test/resources/pdfparser folder and run a test case like this:
> public class TestGovdocs148902 extends TestCase
> {
>     public void test148902() throws IOException {
>         PDDocument doc = PDDocument.load( "src/test/resources/pdfparser/148902.pdf");
>         int imageCounter = 0;
>         COSDocument cosDoc = doc.getDocument();
>         List<COSObject> list = cosDoc.getObjectsByType(COSName.XOBJECT);
>         
>         for (COSObject cosOb : list) {
>             COSBase baseObject = cosOb.getObject();
>             if (baseObject != null && baseObject instanceof COSStream) {
>                 COSStream st = (COSStream)baseObject;
>                 String subtype = st.getNameAsString(COSName.SUBTYPE);
>                 if (subtype != null && subtype.equalsIgnoreCase("image")) {
>                     PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( st );
>                     if (ximage != null && ximage.getWidth() >= 5 && ximage.getHeight() >= 5) {
>                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
>                         ximage.write2OutputStream(baos);
>                         byte [] bytes = baos.toByteArray();
>                         if (bytes.length > 0) {
>                             imageCounter++;
>                         }
>                     }
>                 }
>             }
>         }
>         
>         assertEquals(32, imageCounter);
>     }
> }
> The test cases passes in 1.4.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (PDFBOX-1075) Can't get images from a PDF

Posted by "Antoni Mylka (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13084171#comment-13084171 ] 

Antoni Mylka commented on PDFBOX-1075:
--------------------------------------

The way I understand it, in an indexed color model, the palette cannot contain more colors than 2^bitsPerPixel. In my case in this PDF there was a picture with 1 bpp, but the arrays csIndexed.getHighValue() would return 255. This is clearly wrong. The high value is taken from the COSArray - i.e. the file itself contains a wrong value. 

As a workaround I replaced the line 

int size = csIndexed.getHighValue()

with

int size = Math.min(csIndexed.getHighValue(), 1 << (bpc-1));

As I said, an indexed color model can have at most 2^bpc colors in the palette. More make no sense, and in this case break the processing of the image.

Does it all make sense?

> Can't get images from a PDF
> ---------------------------
>
>                 Key: PDFBOX-1075
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1075
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.6.0, 1.7.0
>            Reporter: Antoni Mylka
>
> This is a regression. In 1.4.0 I was able to extract images from a PDF file. In 1.6 and the current trunk I get exceptions:
> SEVERE: java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> 	at java.awt.image.BufferedImage.<init>(BufferedImage.java:611)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:252)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.write2OutputStream(PDPixelMap.java:289)
> 	at org.apache.pdfbox.TestGovdocs148902.test148902(TestGovdocs148902.java:58)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:168)
> 	at junit.framework.TestCase.runBare(TestCase.java:134)
> 	at junit.framework.TestResult$1.protect(TestResult.java:110)
> 	at junit.framework.TestResult.runProtected(TestResult.java:128)
> 	at junit.framework.TestResult.run(TestResult.java:113)
> 	at junit.framework.TestCase.run(TestCase.java:124)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:232)
> 	at junit.framework.TestSuite.run(TestSuite.java:227)
> 	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> http://domex.nps.edu/corp/files/govdocs1/148/148902.pdf
> I pasted it into the src/test/resources/pdfparser folder and run a test case like this:
> public class TestGovdocs148902 extends TestCase
> {
>     public void test148902() throws IOException {
>         PDDocument doc = PDDocument.load( "src/test/resources/pdfparser/148902.pdf");
>         int imageCounter = 0;
>         COSDocument cosDoc = doc.getDocument();
>         List<COSObject> list = cosDoc.getObjectsByType(COSName.XOBJECT);
>         
>         for (COSObject cosOb : list) {
>             COSBase baseObject = cosOb.getObject();
>             if (baseObject != null && baseObject instanceof COSStream) {
>                 COSStream st = (COSStream)baseObject;
>                 String subtype = st.getNameAsString(COSName.SUBTYPE);
>                 if (subtype != null && subtype.equalsIgnoreCase("image")) {
>                     PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( st );
>                     if (ximage != null && ximage.getWidth() >= 5 && ximage.getHeight() >= 5) {
>                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
>                         ximage.write2OutputStream(baos);
>                         byte [] bytes = baos.toByteArray();
>                         if (bytes.length > 0) {
>                             imageCounter++;
>                         }
>                     }
>                 }
>             }
>         }
>         
>         assertEquals(32, imageCounter);
>     }
> }
> The test cases passes in 1.4.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (PDFBOX-1075) Can't get images from a PDF

Posted by "Daniel Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13084305#comment-13084305 ] 

Daniel Wilson commented on PDFBOX-1075:
---------------------------------------

Antoni,

Your correction makes sense to me (though I'm not the strongest on the Java graphics model) and it does no harm to the test document provided for PDFBOX-1010.

I believe your change should be included.

> Can't get images from a PDF
> ---------------------------
>
>                 Key: PDFBOX-1075
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1075
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.6.0, 1.7.0
>            Reporter: Antoni Mylka
>
> This is a regression. In 1.4.0 I was able to extract images from a PDF file. In 1.6 and the current trunk I get exceptions:
> SEVERE: java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> 	at java.awt.image.BufferedImage.<init>(BufferedImage.java:611)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:252)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.write2OutputStream(PDPixelMap.java:289)
> 	at org.apache.pdfbox.TestGovdocs148902.test148902(TestGovdocs148902.java:58)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:168)
> 	at junit.framework.TestCase.runBare(TestCase.java:134)
> 	at junit.framework.TestResult$1.protect(TestResult.java:110)
> 	at junit.framework.TestResult.runProtected(TestResult.java:128)
> 	at junit.framework.TestResult.run(TestResult.java:113)
> 	at junit.framework.TestCase.run(TestCase.java:124)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:232)
> 	at junit.framework.TestSuite.run(TestSuite.java:227)
> 	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> http://domex.nps.edu/corp/files/govdocs1/148/148902.pdf
> I pasted it into the src/test/resources/pdfparser folder and run a test case like this:
> public class TestGovdocs148902 extends TestCase
> {
>     public void test148902() throws IOException {
>         PDDocument doc = PDDocument.load( "src/test/resources/pdfparser/148902.pdf");
>         int imageCounter = 0;
>         COSDocument cosDoc = doc.getDocument();
>         List<COSObject> list = cosDoc.getObjectsByType(COSName.XOBJECT);
>         
>         for (COSObject cosOb : list) {
>             COSBase baseObject = cosOb.getObject();
>             if (baseObject != null && baseObject instanceof COSStream) {
>                 COSStream st = (COSStream)baseObject;
>                 String subtype = st.getNameAsString(COSName.SUBTYPE);
>                 if (subtype != null && subtype.equalsIgnoreCase("image")) {
>                     PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( st );
>                     if (ximage != null && ximage.getWidth() >= 5 && ximage.getHeight() >= 5) {
>                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
>                         ximage.write2OutputStream(baos);
>                         byte [] bytes = baos.toByteArray();
>                         if (bytes.length > 0) {
>                             imageCounter++;
>                         }
>                     }
>                 }
>             }
>         }
>         
>         assertEquals(32, imageCounter);
>     }
> }
> The test cases passes in 1.4.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (PDFBOX-1075) Can't get images from a PDF

Posted by "Antoni Mylka (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13083160#comment-13083160 ] 

Antoni Mylka commented on PDFBOX-1075:
--------------------------------------

FWIW. 

I narrowed the problem down to revision 1133281. The test used to pass before that revision, and stopped passing afterwards. That revision has been committed by Andreas Lehmkühler within the scope of PDFBOX-1010. 

I have no idea what this commit was about and why it caused a regression. 

> Can't get images from a PDF
> ---------------------------
>
>                 Key: PDFBOX-1075
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1075
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.6.0, 1.7.0
>            Reporter: Antoni Mylka
>
> This is a regression. In 1.4.0 I was able to extract images from a PDF file. In 1.6 and the current trunk I get exceptions:
> SEVERE: java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> 	at java.awt.image.BufferedImage.<init>(BufferedImage.java:611)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:252)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.write2OutputStream(PDPixelMap.java:289)
> 	at org.apache.pdfbox.TestGovdocs148902.test148902(TestGovdocs148902.java:58)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:168)
> 	at junit.framework.TestCase.runBare(TestCase.java:134)
> 	at junit.framework.TestResult$1.protect(TestResult.java:110)
> 	at junit.framework.TestResult.runProtected(TestResult.java:128)
> 	at junit.framework.TestResult.run(TestResult.java:113)
> 	at junit.framework.TestCase.run(TestCase.java:124)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:232)
> 	at junit.framework.TestSuite.run(TestSuite.java:227)
> 	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> http://domex.nps.edu/corp/files/govdocs1/148/148902.pdf
> I pasted it into the src/test/resources/pdfparser folder and run a test case like this:
> public class TestGovdocs148902 extends TestCase
> {
>     public void test148902() throws IOException {
>         PDDocument doc = PDDocument.load( "src/test/resources/pdfparser/148902.pdf");
>         int imageCounter = 0;
>         COSDocument cosDoc = doc.getDocument();
>         List<COSObject> list = cosDoc.getObjectsByType(COSName.XOBJECT);
>         
>         for (COSObject cosOb : list) {
>             COSBase baseObject = cosOb.getObject();
>             if (baseObject != null && baseObject instanceof COSStream) {
>                 COSStream st = (COSStream)baseObject;
>                 String subtype = st.getNameAsString(COSName.SUBTYPE);
>                 if (subtype != null && subtype.equalsIgnoreCase("image")) {
>                     PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( st );
>                     if (ximage != null && ximage.getWidth() >= 5 && ximage.getHeight() >= 5) {
>                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
>                         ximage.write2OutputStream(baos);
>                         byte [] bytes = baos.toByteArray();
>                         if (bytes.length > 0) {
>                             imageCounter++;
>                         }
>                     }
>                 }
>             }
>         }
>         
>         assertEquals(32, imageCounter);
>     }
> }
> The test cases passes in 1.4.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Resolved] (PDFBOX-1075) Can't get images from a PDF

Posted by "Andreas Lehmkühler (Resolved JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Lehmkühler resolved PDFBOX-1075.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.7.0
         Assignee: Andreas Lehmkühler

Set to resolved.

Thanks for the contribution!
                
> Can't get images from a PDF
> ---------------------------
>
>                 Key: PDFBOX-1075
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1075
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.6.0, 1.7.0
>            Reporter: Antoni Mylka
>            Assignee: Andreas Lehmkühler
>             Fix For: 1.7.0
>
>
> This is a regression. In 1.4.0 I was able to extract images from a PDF file. In 1.6 and the current trunk I get exceptions:
> SEVERE: java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> 	at java.awt.image.BufferedImage.<init>(BufferedImage.java:611)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:252)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.write2OutputStream(PDPixelMap.java:289)
> 	at org.apache.pdfbox.TestGovdocs148902.test148902(TestGovdocs148902.java:58)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:168)
> 	at junit.framework.TestCase.runBare(TestCase.java:134)
> 	at junit.framework.TestResult$1.protect(TestResult.java:110)
> 	at junit.framework.TestResult.runProtected(TestResult.java:128)
> 	at junit.framework.TestResult.run(TestResult.java:113)
> 	at junit.framework.TestCase.run(TestCase.java:124)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:232)
> 	at junit.framework.TestSuite.run(TestSuite.java:227)
> 	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> http://domex.nps.edu/corp/files/govdocs1/148/148902.pdf
> I pasted it into the src/test/resources/pdfparser folder and run a test case like this:
> public class TestGovdocs148902 extends TestCase
> {
>     public void test148902() throws IOException {
>         PDDocument doc = PDDocument.load( "src/test/resources/pdfparser/148902.pdf");
>         int imageCounter = 0;
>         COSDocument cosDoc = doc.getDocument();
>         List<COSObject> list = cosDoc.getObjectsByType(COSName.XOBJECT);
>         
>         for (COSObject cosOb : list) {
>             COSBase baseObject = cosOb.getObject();
>             if (baseObject != null && baseObject instanceof COSStream) {
>                 COSStream st = (COSStream)baseObject;
>                 String subtype = st.getNameAsString(COSName.SUBTYPE);
>                 if (subtype != null && subtype.equalsIgnoreCase("image")) {
>                     PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( st );
>                     if (ximage != null && ximage.getWidth() >= 5 && ximage.getHeight() >= 5) {
>                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
>                         ximage.write2OutputStream(baos);
>                         byte [] bytes = baos.toByteArray();
>                         if (bytes.length > 0) {
>                             imageCounter++;
>                         }
>                     }
>                 }
>             }
>         }
>         
>         assertEquals(32, imageCounter);
>     }
> }
> The test cases passes in 1.4.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (PDFBOX-1075) Can't get images from a PDF

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Lehmkühler updated PDFBOX-1075:
---------------------------------------

    Fix Version/s:     (was: 1.4.0)

> Can't get images from a PDF
> ---------------------------
>
>                 Key: PDFBOX-1075
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1075
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.6.0, 1.7.0
>            Reporter: Antoni Mylka
>
> This is a regression. In 1.4.0 I was able to extract images from a PDF file. In 1.6 and the current trunk I get exceptions:
> SEVERE: java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> 	at java.awt.image.BufferedImage.<init>(BufferedImage.java:611)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:252)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.write2OutputStream(PDPixelMap.java:289)
> 	at org.apache.pdfbox.TestGovdocs148902.test148902(TestGovdocs148902.java:58)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:168)
> 	at junit.framework.TestCase.runBare(TestCase.java:134)
> 	at junit.framework.TestResult$1.protect(TestResult.java:110)
> 	at junit.framework.TestResult.runProtected(TestResult.java:128)
> 	at junit.framework.TestResult.run(TestResult.java:113)
> 	at junit.framework.TestCase.run(TestCase.java:124)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:232)
> 	at junit.framework.TestSuite.run(TestSuite.java:227)
> 	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> http://domex.nps.edu/corp/files/govdocs1/148/148902.pdf
> I pasted it into the src/test/resources/pdfparser folder and run a test case like this:
> public class TestGovdocs148902 extends TestCase
> {
>     public void test148902() throws IOException {
>         PDDocument doc = PDDocument.load( "src/test/resources/pdfparser/148902.pdf");
>         int imageCounter = 0;
>         COSDocument cosDoc = doc.getDocument();
>         List<COSObject> list = cosDoc.getObjectsByType(COSName.XOBJECT);
>         
>         for (COSObject cosOb : list) {
>             COSBase baseObject = cosOb.getObject();
>             if (baseObject != null && baseObject instanceof COSStream) {
>                 COSStream st = (COSStream)baseObject;
>                 String subtype = st.getNameAsString(COSName.SUBTYPE);
>                 if (subtype != null && subtype.equalsIgnoreCase("image")) {
>                     PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( st );
>                     if (ximage != null && ximage.getWidth() >= 5 && ximage.getHeight() >= 5) {
>                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
>                         ximage.write2OutputStream(baos);
>                         byte [] bytes = baos.toByteArray();
>                         if (bytes.length > 0) {
>                             imageCounter++;
>                         }
>                     }
>                 }
>             }
>         }
>         
>         assertEquals(32, imageCounter);
>     }
> }
> The test cases passes in 1.4.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (PDFBOX-1075) Can't get images from a PDF

Posted by "Andreas Lehmkühler (Commented JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13133659#comment-13133659 ] 

Andreas Lehmkühler commented on PDFBOX-1075:
--------------------------------------------

The size should be calculated as follows:

int size = Math.min(csIndexed.getHighValue(), (1 << bpc) - 1); 

Antonis fix accidentically worked for PDFBOX-1010 and this one but introduced a regression with PDFBOX-706.

I fixed that in revision 1187899
                
> Can't get images from a PDF
> ---------------------------
>
>                 Key: PDFBOX-1075
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1075
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.6.0, 1.7.0
>            Reporter: Antoni Mylka
>             Fix For: 1.7.0
>
>
> This is a regression. In 1.4.0 I was able to extract images from a PDF file. In 1.6 and the current trunk I get exceptions:
> SEVERE: java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> java.lang.IllegalArgumentException: Raster BytePackedRaster: width = 1000 height = 32 #channels 1 xOff = 0 yOff = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1050169 transparency = 1 transIndex   = -1 has alpha = false isAlphaPre = false
> 	at java.awt.image.BufferedImage.<init>(BufferedImage.java:611)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:252)
> 	at org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.write2OutputStream(PDPixelMap.java:289)
> 	at org.apache.pdfbox.TestGovdocs148902.test148902(TestGovdocs148902.java:58)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:168)
> 	at junit.framework.TestCase.runBare(TestCase.java:134)
> 	at junit.framework.TestResult$1.protect(TestResult.java:110)
> 	at junit.framework.TestResult.runProtected(TestResult.java:128)
> 	at junit.framework.TestResult.run(TestResult.java:113)
> 	at junit.framework.TestCase.run(TestCase.java:124)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:232)
> 	at junit.framework.TestSuite.run(TestSuite.java:227)
> 	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> http://domex.nps.edu/corp/files/govdocs1/148/148902.pdf
> I pasted it into the src/test/resources/pdfparser folder and run a test case like this:
> public class TestGovdocs148902 extends TestCase
> {
>     public void test148902() throws IOException {
>         PDDocument doc = PDDocument.load( "src/test/resources/pdfparser/148902.pdf");
>         int imageCounter = 0;
>         COSDocument cosDoc = doc.getDocument();
>         List<COSObject> list = cosDoc.getObjectsByType(COSName.XOBJECT);
>         
>         for (COSObject cosOb : list) {
>             COSBase baseObject = cosOb.getObject();
>             if (baseObject != null && baseObject instanceof COSStream) {
>                 COSStream st = (COSStream)baseObject;
>                 String subtype = st.getNameAsString(COSName.SUBTYPE);
>                 if (subtype != null && subtype.equalsIgnoreCase("image")) {
>                     PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( st );
>                     if (ximage != null && ximage.getWidth() >= 5 && ximage.getHeight() >= 5) {
>                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
>                         ximage.write2OutputStream(baos);
>                         byte [] bytes = baos.toByteArray();
>                         if (bytes.length > 0) {
>                             imageCounter++;
>                         }
>                     }
>                 }
>             }
>         }
>         
>         assertEquals(32, imageCounter);
>     }
> }
> The test cases passes in 1.4.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira