I am trying to create a PDF from a UIView
which may contain images, labels, etc.
I have checked the reference ( GeneratingPDF) and I am also aware of the rend
You do indeed have to draw the texts/images individually into a CGContextRef
(look at CGPDFContextCreateWithURL
) using functions like CGContextShowTextAtPoint
. While you could theoretically scan your UIView for images/labels, it would be better if you just draw the layout from scratch. You must have some way to know what elements should be in the UIView. Although the code will be very different, logically you should approach it the same way you would if you were going to draw the UIView programmatically instead of loading it from a nib.
If you really want to scan your UIView, you could do something like this:
for(UIView *subview in parentView.subviews) {
if([subview isKindOfClass:[UIImageView class]]) {
...
} else if([subview isKindOfClass:[UITextView class]]) {
...
} else if([subview isKindOfClass:[UILabel class]]) {
...
}
}