0

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?

2 Answers 2

0

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.

0
0

To view the PDF file, you can use webviews.

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *file = [docsDirectory stringByAppendingPathComponent:@"mypdf.pdf"];

// use the code for webView

UIWebView *attachmentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(10,0,300,400)];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL fileURLWithPath:file]];   
[attachmentWebView loadRequest:request];
[request release];
[self.view addSubview:attachmentWebView];
[attachmentWebView release];
1
  • Useful as well thanks. Its easy to just pop up that Webview and see if anything was created.
    – Mike S
    Dec 13, 2010 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.