1

I've been working on an app where I have a UIView that needs to be printed via AirPrint. To accomplish this I first fill out all the details in the view and then pass it to the below code to make a pdf out of before printing it. In Xcode 7 everything was working fine. Since I did the update to Xcode 8, the view doesn't render to the correct size any more using renderInContext.

- (NSMutableData *)createPDFDataFromUIView:(UIView *)aView {
NSMutableData *pdfDataObject=[NSMutableData data];

// create a PDF-based graphics context with mutable data object as the target
UIGraphicsBeginPDFContextToData(pdfDataObject, [aView bounds], nil);

// mark the beginning of a new page
UIGraphicsBeginPDFPage();

// get the CGContextRef for our PDF drawing
CGContextRef pdfContext= UIGraphicsGetCurrentContext();

// render the UIView’s layer into the PDF context
[[aView layer] renderInContext:pdfContext];

// end the PDF context
UIGraphicsEndPDFContext();

return pdfDataObject;
}

Any help would be appreciated.

CKU
  • 21
  • 5
  • Check what's the value of [aView bounds] – Anton Malyshev Sep 20 '16 at 07:17
  • Have you import #import ? @CKU – KAR Sep 20 '16 at 07:19
  • When I echo back the width and height I get the expected width and height (aView.bounds.size.width), the values of the view. – CKU Sep 20 '16 at 07:22
  • QuartzCore wasn't imported, didn't help to solve the issue though – CKU Sep 20 '16 at 07:25
  • I get : replacing +/-infinity with -2147483648 when it hits UIGraphicsEndPDFContext(). – CKU Sep 22 '16 at 09:52
  • This post helped me: http://stackoverflow.com/questions/27851647/autolayout-dynamic-xib-view-height . I was also loading the view with a constructor. Adding setTranslatesAutoresizingMaskIntoConstraints:NO and layoutIfNeeded fixed it for me. – CKU Sep 25 '16 at 09:21

0 Answers0