在哪里存储创建的PDF文件? [英] Where to store a created PDF File?

查看:195
本文介绍了在哪里存储创建的PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

收到以下错误:

CGDataConsumerCreateWithFilename: failed to open `/name' for writing: Permission denied.

使用此代码(不是我的):

With this code (not mine):

- (void)createPDFWithName
{
//NSURL * newFilePath = [[NSURL alloc] initFileURLWithPath:name];
NSString * newFilePath = @"name";

CGRect page = CGRectMake(0, 0, 300, 300);

NSDictionary * metaData = nil;

if (!UIGraphicsBeginPDFContextToFile(newFilePath, page, metaData )) {
    NSLog(@"error creating PDF context");
    return;
}

UIGraphicsBeginPDFPage();
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndPDFContext();
}

所以:我应该在哪里存储此PDF文件?我尝试了NSBundle MainBundle的操作,但也没有用.

So: Where should I store this PDF-File? I tried the NSBundle MainBundle thing and it did not work either.

谢谢!

推荐答案

您应该阅读文件系统上可以创建文件的各个位置.其中之一是文档路径,下面是一个示例.

You should read about the various places on the file system that you can create files. One of these is the documents path, an example is below.

- (NSString *)documentPath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return documentPath;
}

NSString * newFilePath = [[self documentPath] stringByAppendingPathComponent:@"name.pdf"];

这篇关于在哪里存储创建的PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆