You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by John Lussmyer <Co...@CasaDelGato.com> on 2015/02/19 05:46:46 UTC

Creating a page from a block of CCITTG42D data?

So, I have a block of data (byte[]) that represents a scanned image, compressed using CCITTG4.
I'm new to PDFBox. (of course)

So far, I haven't been able to figure out how I can create a page that consists of just that image.
All the examples want to read the image from a file, and decompress it.
Since I already have it as a compressed block, I'd prefer to just use it as-is.
The last time I did much work with PDF's, I was working directly with the dictionaries.  I don't see a simple way of even getting to the Page dictionary in PDFbox.

Anyone have a suggestion on how to do this?

--
Worlds only All Electric F-250 truck! http://john.casadelgato.com/Electric-Vehicles/1995-Ford-F-250


Re: Creating a page from a block of CCITTG42D data?

Posted by John Lussmyer <Co...@CasaDelGato.com>.
In this case I'm converting some proprietary image files from a program I wrote 18 years ago.

On Thu Feb 19 13:41:30 PST 2015 THausherr@t-online.de said:
>Glad it works. Where did you get the raw G4 files from / is this
>something that you think might be useful to many, or was it just
>something unique for you? I'm just wondering if I should add such code
>to the 2.0 or 2.1 version.
>
>Tilman
>
>Am 19.02.2015 um 19:09 schrieb John Lussmyer:
>> On Wed Feb 18 23:34:09 PST 2015 THausherr@t-online.de said:
>>> Assuming you are using 1.8.8, put the ccitt stream into a PDStream
>>> object, then call the PDCcitt constructor with that PDStream.
>>>
>>> PDStream pd =        new PDStream(doc, new
>>> ByteArrayInputStream(data), true);
>> ....
>>
>> Thanks, that worked! (with a few tweaks and typo corrections of course!)
>>
>> --
>>
>> Try my Sensible Email package!  https://sourceforge.net/projects/sensibleemail/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org


--

Worlds only All Electric F-250 truck! http://john.casadelgato.com/Electric-Vehicles/1995-Ford-F-250



Re: Creating a page from a block of CCITTG42D data?

Posted by Tilman Hausherr <TH...@t-online.de>.
Glad it works. Where did you get the raw G4 files from / is this 
something that you think might be useful to many, or was it just 
something unique for you? I'm just wondering if I should add such code 
to the 2.0 or 2.1 version.

Tilman

Am 19.02.2015 um 19:09 schrieb John Lussmyer:
> On Wed Feb 18 23:34:09 PST 2015 THausherr@t-online.de said:
>> Assuming you are using 1.8.8, put the ccitt stream into a PDStream
>> object, then call the PDCcitt constructor with that PDStream.
>>
>> PDStream pd =        new PDStream(doc, new
>> ByteArrayInputStream(data), true);
> ....
>
> Thanks, that worked! (with a few tweaks and typo corrections of course!)
>
> --
>
> Try my Sensible Email package!  https://sourceforge.net/projects/sensibleemail/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Creating a page from a block of CCITTG42D data?

Posted by John Lussmyer <Co...@CasaDelGato.com>.
On Wed Feb 18 23:34:09 PST 2015 THausherr@t-online.de said:
>Assuming you are using 1.8.8, put the ccitt stream into a PDStream
>object, then call the PDCcitt constructor with that PDStream.
>
>PDStream pd =        new PDStream(doc, new
>ByteArrayInputStream(data), true);
....

Thanks, that worked! (with a few tweaks and typo corrections of course!)

--

Try my Sensible Email package!  https://sourceforge.net/projects/sensibleemail/

Re: Creating a page from a block of CCITTG42D data?

Posted by Tilman Hausherr <TH...@t-online.de>.
Assuming you are using 1.8.8, put the ccitt stream into a PDStream 
object, then call the PDCcitt constructor with that PDStream.


        PDStream pd =        new PDStream(doc, new 
ByteArrayInputStream(data), true);

        COSStream dic = pd.getCOSStream();

        COSDictionary decodeParms = new COSDictionary();
        decodeParms .setInt(COSName.COLUMNS,  nnnnn);
        decodeParms .setInt(COSName.ROWS,  nnnnn);
        decodeParms .setBoolean(COSName.BLACK_IS_1, ?????); // test 
which is right, true or false
        decodeParms .setInt(COSName.K, -1);   // -1 for G4

         dic.setItem(COSName.FILTER, COSName.CCITTFAX_DECODE);
         dic.setItem(COSName.SUBTYPE, COSName.IMAGE);
         dic.setItem(COSName.TYPE, COSName.XOBJECT);
         dic.setItem(COSName.DECODE_PARMS, decodeParms);

         setBitsPerComponent(1);
         setColorSpace(new PDDeviceGray());
         setWidth(decodeParms.getInt(COSName.COLUMNS));
         setHeight(decodeParms.getInt(COSName.ROWS));


Now if that has worked, you can create the PDCCitt object from the 
PDStream object. That one you handle like in the ImageToPDF example. 
(Download the 1.8 source code)

If it doesn't work, email me (tilman at snafu dot de ) a 
non-confidential file with that raw G4 data and the col / row values and 
I'll fix any errors I may have inserted here. (tonight, after work)

Tilman

Am 19.02.2015 um 05:46 schrieb John Lussmyer:
> So, I have a block of data (byte[]) that represents a scanned image, compressed using CCITTG4.
> I'm new to PDFBox. (of course)
>
> So far, I haven't been able to figure out how I can create a page that consists of just that image.
> All the examples want to read the image from a file, and decompress it.
> Since I already have it as a compressed block, I'd prefer to just use it as-is.
> The last time I did much work with PDF's, I was working directly with the dictionaries.  I don't see a simple way of even getting to the Page dictionary in PDFbox.
>
> Anyone have a suggestion on how to do this?
>
> --
> Worlds only All Electric F-250 truck! http://john.casadelgato.com/Electric-Vehicles/1995-Ford-F-250
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org