gpt4 book ai didi

iphone - 在 iOS4 中保存 PDF 文件时出现问题

转载 作者:行者123 更新时间:2023-12-03 21:22:18 24 4
gpt4 key购买 nike

我想让我的 iPhone 应用程序创建一个 PDF 文件并将其存储在适当的位置 - 可能是 iBooks 文件夹,以便可以使用 iTunes 轻松检索它,但一旦我让保存部分工作,这是一个更改。我已严格按照 Apple 网站上的 PDF 保存教程进行操作,包括将 CGContextBeginPage 和 CGContextEndPage 替换为其特定于 PDF 的等效项,并且我已检查保存文件名是否设置为正确的位置,但要么没有文件被保存创建或我只是找不到它的存储位置。这是代码,有什么问题吗?是代码的问题,还是这种操作根本无法在模拟器中运行?

    CGRect b = CGRectMake(0, 0, 612, 792);
NSMutableString *exportPath = [[NSMutableString alloc]
initWithString:[[NSBundle mainBundle] bundlePath]];
[exportPath appendString:@"/myfile.pdf"];
CGContextRef pdfContext;
CFStringRef path = CFStringCreateWithCString (NULL, [exportPath UTF8String], kCFStringEncodingUTF8);
CFURLRef url; CFMutableDictionaryRef myDictionary = NULL;

url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
CFRelease(path);
myDictionary = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));

pdfContext = CGPDFContextCreateWithURL (url, &b, myDictionary);
CFRelease(myDictionary);
CFRelease(url);

CGPDFContextBeginPage(pdfContext, NULL);
[self drawToContext: pdfContext Bounds:b];
CGPDFContextEndPage(pdfContext);
CGPDFContextClose(pdfContext);
CGContextRelease (pdfContext);

最佳答案

您正在尝试将 PDF 保存到包中。我很确定你能做到。请改用文档路径。

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *dbpath = [documentsDir stringByAppendingPathComponent:@"myfile.pdf"];

关于iphone - 在 iOS4 中保存 PDF 文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3547008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com