Create a pdf with subviews of Scrollview one by one

Tuesday, July 8, 2014

I have an application where the user will be presented with a pdf of subviews added to a scrollview one by one that is like one view is one page in pdf. I have searched for an answer to create pdf from a set of subviews added to a scrollview efficiently, but I get the pdf created only for the visible area. The other portion that is visible on scrolling is clipped off and the corresponding part is white. Guys please help me. I have been banging on this for a some time. I have found similar codes for achieving the same, but it doesn't help.



UIView *aView = (UIView *)[[aScrollView subviews]objectAtIndex:0];
CGRect origSize = aScrollView.frame;
CGRect newSize = origSize;
newSize.size =CGSizeMake(aScrollView.contentSize.width, 780);
[aScrollView setFrame:newSize];

UIGraphicsBeginPDFContextToData(pdfData,(CGRect){0,0, aView.frame.size.width, 780}, nil); //aviewframe
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[aView.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
[aScrollView setFrame:origSize];
}


NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
// Retrieves the document directories from the iOS device*/






http://ift.tt/1k1IsLF