首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > PowerDesigner >

创设PDF

2012-06-30 
创建PDF- (void) createPDF {NSMutableData *outputData [[NSMutableData alloc] init]CGDataConsumerR

创建PDF

- (void) createPDF {NSMutableData *outputData = [[NSMutableData alloc] init];    CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData((CFMutableDataRef)outputData);    CFMutableDictionaryRef attrDictionary = NULL;        attrDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);    CFDictionarySetValue(attrDictionary, kCGPDFContextTitle, @"My Document");    CGContextRef pdfContext = CGPDFContextCreate(dataConsumer, NULL, attrDictionary);     CFRelease(dataConsumer);    CFRelease(attrDictionary);    UIImage *myUIImage = [UIImage imageNamed:@"wheat.png"];    CGImageRef pageImage = [myUIImage CGImage];    CGPDFContextBeginPage(pdfContext, NULL);    CGContextDrawImage(pdfContext, CGRectMake(0, 0, [myUIImage size].width, [myUIImage size].height), pageImage);    CGContextSelectFont(pdfContext, "Helvetica", 35, kCGEncodingMacRoman);    CGContextSetTextDrawingMode(pdfContext, kCGTextFill);    CGContextSetRGBFillColor(pdfContext, 0, 0, 0, 1);    const char *text = "Hello World!";    CGContextShowTextAtPoint(pdfContext, 260, 390, text, strlen(text));CGPDFContextEndPage(pdfContext);    CGPDFContextClose(pdfContext);    CGContextRelease(pdfContext);     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    NSString *documentsDirectory = [paths objectAtIndex:0];    NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"tmp.pdf"];    [outputData writeToFile:appFile atomically:YES];[outputData release];}
?

热点排行