Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Xcode是否将PDF另存为图像?_Iphone_Image - Fatal编程技术网

Iphone Xcode是否将PDF另存为图像?

Iphone Xcode是否将PDF另存为图像?,iphone,image,Iphone,Image,我有一个问题,是否可以将PDF保存到相机卷?我的意思是,我知道如何保存图片,但你也能保存PDF吗?不,那是不可能的。苹果只允许照片和视频存储在照片库中。PDF格式的文件可以存储在iBooks或其他可以处理PDF的程序中,但照片库不能接受PDF您可以将PDF转换为一组图像,并将其导入到卷中。您无法将实际的PDF添加到卷中。如果您尝试间接添加,而有人尝试过,则无法查看 照相胶卷是用来拍照的。 iBooks是用于PDF的。As@jshin47-以下片段将引导您继续: 这将本地文档目录中名为test.p

我有一个问题,是否可以将PDF保存到相机卷?我的意思是,我知道如何保存图片,但你也能保存PDF吗?

不,那是不可能的。苹果只允许照片和视频存储在照片库中。PDF格式的文件可以存储在iBooks或其他可以处理PDF的程序中,但照片库不能接受PDF

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

如果您尝试间接添加,而有人尝试过,则无法查看

照相胶卷是用来拍照的。
iBooks是用于PDF的。

As@jshin47-以下片段将引导您继续:

这将本地文档目录中名为test.pdf的pdf转换为名为test.png的png。我在PDF中使用了A4尺寸,但如果您不在英国/欧洲,您可能需要使用我们的字母尺寸

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

非常感谢。它似乎正在工作,但图片仅为白色..?很可能在文档文件夹中找不到名为“test.PDF”的有效PDF。如果url为nil——比如说,如果找不到文件,就会是nil——那么它只会生成一个空白的PNG。我添加了四行来创建PDF并将其保存在documents文件夹中。如果生成的图像正确,那么问题很可能是url不是有效PDF文件的url。一个问题:这很好:)但我如何使用UIWebview(UIWebview.request.url.absoluteString)而不是文档文件夹中的PDF?那么我如何将PDF转换为图像?