Cocoa-Created PDF Not Rendering Correctly
Posted
by Matthew Roberts
on Stack Overflow
See other posts from Stack Overflow
or by Matthew Roberts
Published on 2010-04-25T06:41:25Z
Indexed on
2010/04/25
6:43 UTC
Read the original article
Hit count: 341
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".
© Stack Overflow or respective owner