2

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

splash
  • 13,037
  • 1
  • 44
  • 67
Srinivasan
  • 433
  • 3
  • 8
  • 20

2 Answers2

2

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

amielcar
  • 81
  • 6
0

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);
}
splash
  • 13,037
  • 1
  • 44
  • 67
  • Thanks for the code. While using the above code i get the timeout exception (maximum execution time is 15 seconds). I think the exception will be due to the high resolution image which we are using. To give u an clear idea of the image dimension we have used, i have mentioned the details below: Dimension: 1920 * 827 and the file size is 827 KB. Please let me know, whether you have faced this issue before and is there any workaround for it. – Srinivasan Aug 24 '11 at 07:38
  • Creating high resolution PDFs with AlivePDF takes noticeable longer. I never profiled the entire process, because my bitmaps never were so large. You could trace through the several function calls to see where the bottleneck is. – splash Aug 24 '11 at 15:21
  • @srinivasan Using the PNG encoder (instead of JPG) yields much faster execution. – Chris Aug 24 '13 at 09:15