Hello!
I'm trying to display a pdf file in my app, using core graphics. I made a custom view, with the relevant code here for the view (got some lead from the Quartz 2D Programming Guide):
This, for some reason, doesn't display a pdf file. I had investigated a bit with breakpoints, and it looks like the document variable was null. To confirm my suspicion, the NSLog gets triggered.
And I made sure that the pdf file name is the exact same as the name as the pdf file I added to Xcode.
Please someone help me.
I'm trying to display a pdf file in my app, using core graphics. I made a custom view, with the relevant code here for the view (got some lead from the Quartz 2D Programming Guide):
Code:
- (CGPDFDocumentRef)myGetDocumentRef:(const char *)fileName {
CFStringRef path;
CFURLRef url;
CGPDFDocumentRef document;
size_t count;
path = CFStringCreateWithCString(NULL, fileName, kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
CFRelease(path);
document = CGPDFDocumentCreateWithURL(url);
if(!document) {
NSLog(@"Failed to create document!");
}
CFRelease(url);
count = CGPDFDocumentGetNumberOfPages(document);
return document;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGPDFDocumentRef document;
CGPDFPageRef page;
document = [self myGetDocumentRef:"DocumentName.pdf"];
page = CGPDFDocumentGetPage(document, 1);
CGContextDrawPDFPage(context, page);
CGPDFDocumentRelease(document);
}
This, for some reason, doesn't display a pdf file. I had investigated a bit with breakpoints, and it looks like the document variable was null. To confirm my suspicion, the NSLog gets triggered.
And I made sure that the pdf file name is the exact same as the name as the pdf file I added to Xcode.
Please someone help me.