2012-03-21 92 views

回答

0

不,这是不可能的。 Apple仅允许照片和视频存储在照片库中。 PDF格式的文件可以存储在iBook笔记本,或者可以处理PDF格式的,但在照片库不能接受其他程序PDF的

0

您可以将PDF转换成一组图像,并且将其导入卷。您无法将实际的PDF添加到卷筒中。

+0

所以我怎么可以将PDF转换为图像? – 2015-03-08 15:20:58

1

正如@ jshin47 - 下面的代码片段将让你去:

把它转换为PDF叫坐在检验.pdf在本地文件目录为PNG叫test.png。我已经使用A4尺寸的PDF,但如果你不在英国/欧洲,你可能需要美国的字母大小。

NSString* localDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0]; 
NSString* pdfPath = [localDocuments stringByAppendingPathComponent:@"test.pdf"]; 

// create a sample PDF (just for illustration) 
UIGraphicsBeginPDFContextToFile(pdfPath, CGRectZero, nil); 
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil); 
[@"Test string" drawInRect:CGRectMake(50, 50, 300, 200) withFont: [UIFont systemFontOfSize: 48.0]]; 
UIGraphicsEndPDFContext(); 

NSURL* url = [NSURL fileURLWithPath: pdfPath]; 

CGPDFDocumentRef document = CGPDFDocumentCreateWithURL ((CFURLRef) url); 

UIGraphicsBeginImageContext(CGSizeMake(596,842)); 
CGContextRef currentContext = UIGraphicsGetCurrentContext(); 

CGContextTranslateCTM(currentContext, 0, 842); 
CGContextScaleCTM(currentContext, 1.0, -1.0); // make sure the page is the right way up 

CGPDFPageRef page = CGPDFDocumentGetPage (document, 1); // first page of PDF is page 1 (not zero) 
CGContextDrawPDFPage (currentContext, page); // draws the page in the graphics context 

UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

NSString* imagePath = [localDocuments stringByAppendingPathComponent: @"test.png"]; 
[UIImagePNGRepresentation(image) writeToFile: imagePath atomically:YES]; 

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); // do error checking in production code 
+0

谢谢!它似乎在工作,但图片只是白色..? – user1110365 2012-03-22 21:11:33

+0

很可能它无法在文档文件夹中找到名为'test.pdf'的有效PDF。如果url为零 - 如果它找不到该文件,则说明 - 那么它只会生成一个空白的PNG。我添加了四行来创建PDF并将其保存在文档文件夹中。如果这样会生成一个图像OK,那么问题很可能是url不是有效PDF文件的URL。 – Obliquely 2012-03-22 22:20:15

+0

一个问题:这工作完美:)但如何使用UIWebview(UIwebview.request.URL.absoluteString)而不是从文档文件夹的PDF? – Nils 2013-11-21 09:39:17