Created
June 18, 2012 05:13
-
-
Save ponpoko1968/2946953 to your computer and use it in GitHub Desktop.
Fixed syntax error, and bug at https://developer.apple.com/library/mac/#documentation/graphicsimaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html#//apple_ref/doc/uid/TP30001066-CH214-BCIBGJFC
This file contains 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
void MyCreatePDFFile (CGRect pageRect, const char *filename)// 1 | |
{ | |
CGContextRef pdfContext; | |
CFStringRef path; | |
CFURLRef url; | |
CFDataRef boxData = NULL; | |
CFMutableDictionaryRef myDictionary = NULL; | |
CFMutableDictionaryRef pageDictionary = NULL; | |
path = CFStringCreateWithCString (NULL, filename, // 2 | |
kCFStringEncodingUTF8); | |
url = CFURLCreateWithFileSystemPath (NULL, path, // 3 | |
kCFURLPOSIXPathStyle, 0); | |
CFRelease (path); | |
myDictionary = CFDictionaryCreateMutable(NULL, 0, | |
&kCFTypeDictionaryKeyCallBacks, | |
&kCFTypeDictionaryValueCallBacks); // 4 | |
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File")); | |
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name")); | |
pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary); // 5 | |
CFRelease(myDictionary); | |
CFRelease(url); | |
pageDictionary = CFDictionaryCreateMutable(NULL, 0, | |
&kCFTypeDictionaryKeyCallBacks, | |
&kCFTypeDictionaryValueCallBacks); // 6 | |
boxData = CFDataCreate(NULL,(const UInt8 *)&pageRect, sizeof (CGRect)); | |
CFDictionarySetValue(pageDictionary, kCGPDFContextMediaBox, boxData); | |
CGPDFContextBeginPage (pdfContext, pageDictionary); // 7 | |
// insert_draw_something (pdfContext); | |
CGPDFContextEndPage (pdfContext);// 9 | |
CGContextRelease (pdfContext);// 10 | |
CFRelease(pageDictionary); // 11 | |
CFRelease(boxData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment