Created
October 12, 2015 23:15
-
-
Save andrey-str/efb44485acba959a8b99 to your computer and use it in GitHub Desktop.
Load and render a page from PDF with QuartzCore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "PDFDocument.h" | |
bool PDFDocument::loadDocument(const char *filename){ | |
CFStringRef path; | |
CFURLRef url; | |
CGPDFDocumentRef document; | |
size_t count; | |
path = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8); | |
url = CFURLCreateWithFileSystemPath (NULL, path, // 1 kCFURLPOSIXPathStyle, 0); | |
CFRelease (path); | |
document = CGPDFDocumentCreateWithURL (url);// 2 | |
CFRelease(url); | |
count = CGPDFDocumentGetNumberOfPages (document);// 3 | |
if (count == 0) { | |
printf("`%s' needs at least one page!", filename); | |
return false; | |
} | |
mDocument = document; | |
return true | |
} | |
void PDFDocument::drawPage(CGContextRef myContext, size_t pageNumber) { | |
assert(mDocument); | |
CGPDFPageRef page; | |
page = CGPDFDocumentGetPage (mDocument, pageNumber); | |
CGContextDrawPDFPage (myContext, page); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#import <QuartzCore/QuartzCore.h> | |
class PDFDocument{ | |
public: | |
bool loadDocument(const char *filename); | |
void drawPage(CGContextRef myContext, size_t pageNumber); | |
private: | |
CGPDFDocumentRef mDocument; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment