I am trying to crop and then transform a UIView to a pdf file. The UIView is cropping correctly for x component, width and height. But it is taking the same y component,ie 0 for rendering.I want to crop the image 110 points from top. This is my code
UIView *tempV;
tempV=self.view;
CGRect fram= tempV.bounds;
fram.origin.x=537;
fram.origin.y=110;
fram.size.width=404;
fram.size.height=772;
tempV.bounds=fram;
NSLog(@"Mail");
NSLog(@"%f,%f,%f,%f",tempV.bounds.origin.x,tempV.bounds.origin.y,tempV.bounds.size.width,tempV.bounds.size.height);
NSMutableData *pdfData=[NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, tempV.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext= UIGraphicsGetCurrentContext();
[tempV.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
MFMailComposeViewController *mailComposer=[[[MFMailComposeViewController alloc]init] autorelease];
mailComposer.mailComposeDelegate=self;
[mailComposer addAttachmentData: pdfData mimeType: @"application/pdf" fileName: @"Dudel creation.pdf"];
[pdfData writeToFile:@"Dudel creation.pdf" atomically:YES];
[self presentModalViewController: mailComposer animated: YES];
You are doing something very wrong in your initial part of your code… I don’t even want to go there, but let me break down a few things:
1)
UIGraphicsBeginPDFContextToDatasecond parameter is aCGRect.2) From what I’ve understood, you want a very specific rectangle of what’s showing on your screen and although its center is completely different from your view controller’s view (you’re trying to change both origin and size). So, why create a dependency on your view controller’s view’s bounds? (remember bounds and center always go hand in hand).
3) So why not just get rid of the initial part of your code and do this: