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);
reader.ReadBytes(fileBytes);
}
}
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];