Let me state this problem another way.  I think I figured out how to
get the raw bytes of the barcode image, but decoding it is a problem.

I create this barcode from iText like so:

// create datamatrix bar code
BarcodeDatamatrix codeDm = getDatamatrix(code);
doc.add(codeDm.createImage());

private BarcodeDatamatrix getDatamatrix(String text) throws
UnsupportedEncodingException {
                BarcodeDatamatrix dm = new BarcodeDatamatrix();
                dm.setOptions(BarcodeDatamatrix.DM_AUTO);
                dm.setHeight(40);
                dm.setWidth(40);
                dm.generate(text);
                return dm;
        }

Now, I would like to turn around and read it.  So I have the following:

final PdfReader reader = new PdfReader(pdfBytes);
int xo = reader.getXrefSize();
for(int i=0; i<xo; i++) {
        PdfObject obj = reader.getPdfObject(i);
        if(obj!=null && obj.isStream()) {
                PdfDictionary pd = (PdfDictionary)obj;
                if(pd.contains(PdfName.SUBTYPE) &&
pd.get(PdfName.SUBTYPE).toString().equals("/Image")) {
                        String filter = pd.get(PdfName.FILTER).toString();
                                
                        if("/CCITTFaxDecode".equals(filter)) {
                                byte[] rawBytes = 
PdfReader.getStreamBytesRaw((PRStream)obj);
                                final ByteArraySeekableStream stream = new
ByteArraySeekableStream(rawBytes);
                                List<RenderedImage> list = getImages(stream);
                        } else {
                                throw new RuntimeException("filter was 
"+filter);
                        }
                }
        }
}

It turns out that the filter is "/CCITTFaxDecode" when you create the
BarcodeDatamatrix.

I already have code that can decode TIFF -- the method above where it does this:

List<RenderedImage> list = getImages(stream);

This method has been working fine for FAXes and is in production for a
year now.  When I pass the stream with the raw bytes here, it tells me
that it is not a valid TIFF -- the TIFF bytes in the header are not
correct to be exact.

This is where I'm stuck.  Has anyone here had success with creating a
BarcodeDatamatrix and then later extracting it from the PDF?  If so,
any idea what I'm doing wrong here?

Thanks in advance,
Davis

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to