Ios 以编程方式在iPhone中保存PDF
我的应用程序中有一个PDF文件,如下所示:Ios 以编程方式在iPhone中保存PDF,ios,uiimageview,core-animation,catiledlayer,Ios,Uiimageview,Core Animation,Catiledlayer,我的应用程序中有一个PDF文件,如下所示: NSURL* pdfURL = [NSURL URLWithString:urlStr]; CGPDFDocumentRef PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfURL); CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1); 我知道,对于图像,我们可以使用此方法将其保存在iPhone中: [U
NSURL* pdfURL = [NSURL URLWithString:urlStr];
CGPDFDocumentRef PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfURL);
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
我知道,对于图像,我们可以使用此方法将其保存在iPhone中:
[UIImagePNGRepresentation(image) writeToFile:uniquePath atomically:YES];
但是有没有一种方法可以通过编程方式在iPhone中写入/保存PDF文件?这里有一种简单的方法:
NSData *myFile = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"your_url"]];
[myFile writeToFile:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"yourfilename.pdf"] atomically:YES];
除了UIImage之外,无法通过编程将任何数据保存到iPad内存。@Seb不应该这样做。你在模拟器上测试这个吗?在设备上,您将无法写入捆绑资源路径。如果您还没有这样做,第二行应该调整为使用应用程序的Documents目录。我已经使用了此代码并将其存储在Documents目录中。。但当我在iPad上打开adobe reader应用程序时,它什么也没显示。我没有收到任何pdf文件吗?好的……但这会将数据写入应用程序包目录。有没有办法将其保存在iPad内存中……就像我们将uiimage保存到库中一样……?什么是“iPad内存”?@Seb:Frnd。我的要求是,我需要将我的pdf保存到设备中的一个位置,该位置应该可以被另一个pdf应用程序(如Adobe Reader)访问。。我该怎么做?