PurePDF ImageElement throwing errors

375 views Asked by At

Hey so I am trying to create an air app that generates a PDF for the user to save but am running into issues with PurePDF. Whenever I run the ImageElement.getInstance() method I am returned a runtime error:

Error: Error #2030: End of file was encountered. at flash.utils::ByteArray/readUnsignedByte()

I am still just in the testing stage and am not evening doing anything crazy. This is what my code looks like:

var bd:BitmapData = new BitmapData( 1024,768 );
bd.draw(pdfClip); //A simple movieclip on the stage containing an image
var bytes:ByteArray = bd.getPixels(new Rectangle(1024,768));
var image:ImageElement = ImageElement.getInstance( bytes );

I would be grateful if anyone that has used purePDF can offer any advice, the documentation is extremely limiting.

1

There are 1 answers

0
Alessandro Crugnola On BEST ANSWER

You should use the "getBitmapDataInstance" instead, because the "getInstance" method is expecting a png encoded bytearray.

ImageElement.getBitmapDataInstance( bitmap );

see also this example: https://code.google.com/p/purepdf/source/browse/examples/src/ImageBitmapData.as