I am rendering a pdf by creating a pdf context and giving it a path as defined below:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *file = [docsDirectory stringByAppendingPathComponent:@"mypdf.pdf"];
And then using that path like the following:
char * fileutf8 = [file UTF8String];
CGContextRef pdfContext;
CFStringRef path;
CFURLRef url;
CFMutableDictionaryRef myDictionary = NULL;
path = CFStringCreateWithCString (NULL, fileutf8,kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path,kCFURLPOSIXPathStyle, 0);
CFRelease (path);
myDictionary = CFDictionaryCreateMutable(NULL, 0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
pdfContext = CGPDFContextCreateWithURL (url, &size, myDictionary);
CFRelease(url);
CFRelease(myDictionary);// rendering code follows
Long story short I can't see if the PDF looks good cause I don't find it in iTunes under the File Sharing area. Am I missing something?
Not the final solution to your question but I would add something like
NSFileManager createFileAtPath:
or someObject writeToFile:file atomically:YES];
after the NSString * file row and verify if any file at all is created.
Run the app in the simulator, then open a terminal and do a
find ~/* | grep mypdf.pdf
That command should find the file under the Simulators documents directory. With a jailbroken device and a ssh shell you can try the same test on the phone, but for creating files the simulator tends to work ok.
Assuming you have set the UIFileSharingEnabled in info.plist your App will show in iTunes. And if mypdf.pdf is created, even when empty, it should show in iTunes, too. iTunes does not filter but will show anything that is located in the documents directory.
Once you have verified that a file can be created continue with stepping through the second code block you posted, using the debugger and see how the data is treated. I never created a PDF file so I cannot help you much there.