10
I've been searching a lot lately for a good PDF tutorial, documentation, etc.
I ended up using this code, but there are few problems.
Scenario
I have a view which contains a label, a textView and an imageView.
Now, we'll call the label name, the textView description and the imageView image.
The name works as header.
The description is very very mutable, it can be from 2 lines to some pages.
Image should go at the end of the description text.
I'm using this code:
- (void)generatePDF{
NSString *fileName = [NSString stringWithFormat:@"%@.pdf",nameString];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL,
(CFStringRef)descriptionString, NULL);
if (currentText) {
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
if (framesetter) {
// Create the PDF context using the default page: currently constants at the size
// of 612 x 792.
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
CFRange currentRange = CFRangeMake(0, 0);
NSInteger currentPage = 0;
BOOL done = NO;
do {
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth,
kDefaultPageHeight), nil);
[self drawHeader]