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. Image for the cookie policy date

Total PDF Megabite size too large from images

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];

6 Replies

CP Corey Powell 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;

SK Sasi Kumar Sekar Syncfusion Team 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. 

CP Corey Powell February 1, 2017 10:03 AM UTC

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

SK Sasi Kumar Sekar Syncfusion Team 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. 

CP Corey Powell February 7, 2017 08:26 AM UTC

Worked great, Thank you

SK Sasi Kumar Sekar Syncfusion Team 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. 

Live Chat Icon For mobile
Up arrow icon