使用quartz2d生成pdf文档,我们需要创建pdf文档的上下文
UIGraphicsBeginPDFContextToFile
第一个参数为PDF文档存储路迹,通过下面代码获取document的路径
NSArray*array=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
//PDF存储路径
NSString *path=[array[0]stringByAppendingPathComponent:@"token.pdf"];
创建pdf的页面,每一个pdf页面通过下面代码创建
UIGraphicsBeginPDFPage();
生成pdf的函数
NSArray*array=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
//PDF存储路径
NSString *path=[array[0]stringByAppendingPathComponent:@"token.pdf"];
NSLog(@"%@",path);
//创建pdf上下文
UIGraphicsBeginPDFContextToFile(path,CGRectZero,nil);
for (inti=0;i<3;i++) {
if (i%2==0) {
//创建pdf页面
UIGraphicsBeginPDFPage();
}
UIImage *image=[UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",i+1]];
[image drawInRect:CGRectMake(0, (i%2)*396,306,396)];
}
//关闭上下文
UIGraphicsEndPDFContext();