iOS开发之Quartz2D生成PDF-Part1
使用iOS的Quartz2D 生成PDF文件
首先创建一个工程,导入CoreText.framework框架。在PDFViewController.h
文件中引入CoreText文件
#import <CoreText/CoreText.h>
在PDFViewController.m
文件中创建一个新方法:
-(void)drawText
{
NSString* fileName = @"Invoice.PDF";
NSArray *arrayPaths =
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
NSString* textToDraw = @"Hello World";
CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
// 使用 Core Text Framesetter.
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGRect frameRect = CGRectMake(0, 0, 300,