This is a migrated thread and some comments may be shown as answers.

Pdf Export and file size

5 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bernd
Top achievements
Rank 1
Bernd asked on 17 Nov 2010, 10:59 AM
Hi all,

I have a grid that contains 8 charts and want to export this to pdf.
Following the thread http://www.telerik.com/community/forums/aspnet/grid/exception-on-pdf-export-from-grid.aspx, I've replaced the charts by .png images before.

So I have 8 .png - images, each of it has a file size of around 15KB.

When exporting this grid to pdf, the resulting document has 4 pages and a file size of around 4MB !!!
This is way too big.

I've checked the pdf export settigns and did not see anything like "DPI resolution" or "render quality" etc.
So: is there any possibility to render a grid that contains 120KB image data into a document less than 4MB?

I had another grid export containing only text, this one is only 9KB big...

greetings,
  Bernd

btw.: I'm using RadControls for Asp .Net Ajax Q1/2009

5 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 22 Nov 2010, 03:56 PM
Hello Bernd,

I recommend that you use JPG instead of PNG format if you want to produce a smaller file. Formats that use loseless compression are stored as compressed bitmaps and thus the file size grows quickly.

For example our online demo produces 2.3MB PDF file when using PNG images and 550KB when using JPG files.

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Bernd
Top achievements
Rank 1
answered on 22 Nov 2010, 05:45 PM
Hi Daniel

Thanks - this did the trick: from 4MB to 400Kb

greetings,
  Bernd
0
Bernd
Top achievements
Rank 1
answered on 23 Nov 2010, 01:31 PM
Hi all,

I have another question:
The rendering of the image is ok, quality is good, BUT:

I have a PageWidth of 297mm (Din A4 Landscape) and my grid row contains only one column, this column contains a chart.
I save the charts as 800x300px images.
Now inside the .pdf document, those charts seems to be resized to fit the width of the table inside the page.

Due to this resize, the chart images gets a bad Quality - the Labels and Texts becomes grained/wiggly.

My Solution would be to resize the images by myself (with all quality and anti-alias options that System.Drawing provides...), so that they won't be resized during pdf export anymore. For this I need to know the dpi resolution of the images in the pdf export.

Is there a fixed DPI resolution for images in the grid pdf export - or a formula to calculate it?

greetings,
  Bernd
0
Daniel
Telerik team
answered on 25 Nov 2010, 09:55 PM
Hello Bernd,

You can take for granted that 1 pixel is equal to 0.75 postscript points or 1 point is equal to 1.33333 pixels.

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Bernd
Top achievements
Rank 1
answered on 29 Nov 2010, 04:00 PM
Hi Daniel,

thanks for your reply.
First of all, the pdf result seems to depend on how you watch the document on wich machine.
The same report looked ugly on my machine but nice on the machine of a collegue (same type of monitor, same resolution, same version of Acrobat Reader).
On my machine it made a difference if I've opened the document directly in Acrobat Reader (=ugly) or if I've opened the document in a web browser that used the Acrobat Reader plugin (=nice).

Nevertheless, I've used your informations for scaling the image - the results were slightly better, but the fonts were blurred now, especially when printing. I've ended up to let the customer decide  how to render via configuration file options.

Maybe someone will find the following code snippets usefull - a bunch of extension methods for rendering a chart image (some parts shamelessly stolen from MSDN).

greetings, Bernd

    // usage:
    // myRadChart.SaveAsJpg( @"c:\\temp\dummy.jpg", 80, true );
 
//------------------------------------------------------------------------
public static void SaveAsJpg( this RadChart pChart, string pFileName, long pQuality, bool pUseScaleCorrection )
{
  using ( System.Drawing.Image chartImage = pChart.GetBitmap( ) )
  {
    if ( pUseScaleCorrection )
      using ( System.Drawing.Image chartImageResized = chartImage.ResizeForPdfExport( ) )
      {
        chartImageResized.SaveAsJpg( pFileName, pQuality);
      }
    else
      chartImage.SaveAsJpg( pFileName, pQuality);
  }
}
 
//------------------------------------------------------------------------
public static System.Drawing.Image ResizeForPdfExport( this System.Drawing.Image pImg )
{
  int newWidth = ( int ) ( pImg.Width / 0.75 );
  int newHeight = ( int ) ( pImg.Height / 0.75 );
  System.Drawing.Image imgResized = new System.Drawing.Bitmap( newWidth, newHeight );
 
  using ( System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage( imgResized ) )
  {
    graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
    graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
 
    graphic.DrawImage( pImg, 0, 0, newWidth, newHeight );
  }
  return imgResized;
}
 
//------------------------------------------------------------------------
public static void SaveAsJpg( this System.Drawing.Image pImg, string pFileName, long pQuality )
{
  using ( System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( pImg ) )
  {
    ImageCodecInfo jpgCodec = GetImageEncoder( ImageFormat.Jpeg );
    EncoderParameters jpgCodecParams = new EncoderParameters( 1 );
    jpgCodecParams.Param[ 0 ] = new EncoderParameter(
        System.Drawing.Imaging.Encoder.Quality, pQuality );
 
    bmp.Save( pFileName, jpgCodec, jpgCodecParams );
  }
}
 
 
//------------------------------------------------------------------------
public static ImageCodecInfo GetImageEncoder( ImageFormat pFormat )
{
  ImageCodecInfo[ ] codecs = ImageCodecInfo.GetImageDecoders( );
  foreach ( ImageCodecInfo codec in codecs )
  {
    if ( codec.FormatID == pFormat.Guid )
      return codec;
  }
  return null;
}
Tags
Grid
Asked by
Bernd
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Bernd
Top achievements
Rank 1
Share this question
or