2
votes

Iam using AlivePDF for printing the components in flex. Components have text and images, are dynamically created. In this we have high resolution image and the text with embedded font style. AlivePDF's output text and image quality is not good. Text looks blur and the image quality is not that much clear as we see in the original image.

I tried with adding the page as imagestream, but still the output quality is the same.

I have pasted the code below for reference:

var image:ImageSnapshot = ImageSnapshot.captureImage(
    templGroup.getChildAt(i),300,new mx.graphics.codec.JPEGEncoder());
printPDF.addImageStream(image.data,"",null,0,0);

Let me know, whether is there any way to improve the pdf output image quality from alive pdf.

Thanks in Advance,

Regards

Srini

2

2 Answers

2
votes

JPEGEncoder has an argument of quality: JPEGEncoder(quality = 50), change it to 90 and results will be much better, i.e. new JPEGEncoder(90);

0
votes

Try this code for capturing in higher resolution:

function capture(source: DisplayObject, dpi:uint = 72, bgColor:Number = 0xFFFFFF): BitmapData
{
    var scale:Number = dpi/72.0;
    var bmd:BitmapData = new BitmapData(source.width * scale, source.height * scale, false, bgColor);
    var m: Matrix = new Matrix();
    m.scale(scale, scale);
    bmd.draw(source, m);
    return bmd;
}

You could use it like this:

function addHighResSnapshot(pdf: PDF, snapshotObject: DisplayObject, imageRect: Rectangle, dpi: uint = 300): void
{
    var bitmapData: BitmapData = capture(snapshotObject, dpi);
    var encodedImage: ByteArray = new JPEGEncoder().encode(bitmapData);
    pdf.addImageStream(encodedImage, ColorSpace.DEVICE_RGB, null, 
        imageRect.x, imageRect.y, imageRect.width, imageRect.height);
}