We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Total PDF Megabite size too large from images

Thread ID:





127299 Nov 8,2016 01:27 PM UTC Feb 8,2017 05:42 AM UTC Xamarin.Forms 6
Tags: PDF
Corey Powell
Asked On November 8, 2016 01:27 PM UTC

I had this problem writing in Xcode, there are 7 pages to the PDF with 8 JPG's photos, the problem is the images add too much to the file size, I need to add some compression to the code below

The PDF is 20MB, I need to get it down to under 5MB

var exists = await ApplicationData.Current.LocalFolder.TryGetItemAsync("appFiles\\peopleImage1.jpg") as IStorageFile;
            byte[] fileBytes = null;
            if (exists != null)
                using (IRandomAccessStreamWithContentType stream = await exists.OpenReadAsync())
                    fileBytes = new byte[stream.Size];
                    using (DataReader reader = new DataReader(stream))
                        await reader.LoadAsync((uint)stream.Size);
                Stream imageStreamPeople1 = new MemoryStream(fileBytes);
                PdfBitmap imagePeople1 = new PdfBitmap(imageStreamPeople1);
                graphics.DrawImage(imagePeople1, 20, 575, 230, 160);

This is the Xcode snippet with compression in the " UIImage *imageR = [UIImage imageWithData:UIImageJPEGRepresentation(image, 0.02)];" line

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSData *ImageDataFly1 = [defaults objectForKey:@"photoCP1"];

    self.photoCurrysPeople1.image = [UIImage imageWithData:ImageDataFly1];

    CGRect imageRect = CGRectMake(80, 890, 280, 180);

    UIImage *image = [UIImage imageWithData:ImageDataFly1];

    UIImage *imageR = [UIImage imageWithData:UIImageJPEGRepresentation(image, 0.02)];

    [imageR drawInRect:imageRect];

Corey Powell
Replied On November 8, 2016 02:24 PM UTC

Thought I had found the answer with the snippet below, but I get the error "PdfBitmap does not contain a definition for "Quality"  should there be an additional assemblie reference for this method in "UWP" on top of these two "using Syncfusion.Pdf;   using Syncfusion.Pdf.Graphics;"

PdfBitmap img = new PdfBitmap("Input.jpg");

//Reduces the quality of the image

img.Quality = 50;

Sasi Kumar Sekar [Syncfusion]
Replied On November 9, 2016 03:34 PM UTC

Hi Corey, 

Thank you for your update, 

In UWP platform we don’t have property called “Quality” in PdfBitmap class, so It is not visible in UWP . However we are trying creating a sample to reduce the image size in UWP and we will update you once we completed the sample. Meanwhile can you please confirm whether you are using UWP or Xamarin platform. 

Sasi kumar S. 

Corey Powell
Replied On February 1, 2017 10:03 AM UTC

Hi I am back onto trying to resolve this issue, I am using UWP

Sasi Kumar Sekar [Syncfusion]
Replied On February 2, 2017 02:06 PM UTC

Hi Corey, 
Thank you for your update, 
Currently, we do not have support for reducing the Quality of the image through Quality property. We have created the work around sample to reduce the quality of the image, by decoding and scaling the image. This reduces the output PDF size considerably. Please find the size comparison in the below table. 
The input Image size: 170KB 
PDF size without compression 
PDF size after compressing the images 
Please try the attached sample and let us know if this satisfies your requirement. 
Sasi Kumar S. 

Corey Powell
Replied On February 7, 2017 08:26 AM UTC

Worked great, Thank you

Sasi Kumar Sekar [Syncfusion]
Replied On February 8, 2017 05:42 AM UTC

Hi Corey, 

Thank you for your update. Please let us know if you need further assistance, we are happy to assist you always. 

Sasi Kumar S. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon