Cocoa-Created PDF Not Rendering Correctly
- by Matthew Roberts
I've created a PDF on the iPad, but the problem is when you have a line of text greater than 1 line, the content just goes off the page. This is my code:
void CreatePDFFile (CGRect pageRect, const char *filename) {
CGContextRef pdfContext;
CFStringRef path;
CFURLRef url;
CFMutableDictionaryRef myDictionary = NULL;
path = CFStringCreateWithCString (NULL, filename,
kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path,
kCFURLPOSIXPathStyle, 0);
CFRelease (path);
myDictionary = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
NSString *foos = @"Title";
const char *text = [foos UTF8String];
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR(text));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("Author"));
pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary);
CFRelease(myDictionary);
CFRelease(url);
CGContextBeginPage (pdfContext, &pageRect);
CGContextSelectFont (pdfContext, "Helvetica", 12, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
NSString *body = @"text goes here";
const char *text = [body UTF8String];
CGContextShowTextAtPoint (pdfContext, 30, 750, text, strlen(text));
CGContextEndPage (pdfContext);
CGContextRelease (pdfContext);}
Now the issue lies within me writing the text to the page, but the problem is that I can't seem to specify a multi-line "text view".