简体   繁体   English

如何将NSData转换为PDF?

[英]How do I convert NSData to a PDF?

I have pdf files stored on Parse.com, I want to download them and set them as images. 我有在Parse.com上存储的pdf文件,我想下载它们并将它们设置为图像。 I have googled around trying to find out how to do this but I'm still clueless. 我在谷歌周围试图找出如何做到这一点,但我仍然无能为力。 I have got my parse object downloading successfully, the pdf file is stored in the field "image" 我已成功下载我的parse对象,pdf文件存储在“image”字段中

                //DOWNLOAD IMAGE CODE
                PFFile *image = object[@"image"];
                [image getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {

                    //we have data, now we want to convert it to a UIImage

                }];

just have no idea what to do with the data. 只是不知道如何处理数据。 Can someone please give me some pointers? 有人可以给我一些指示吗? thanks 谢谢

I haven't done this, but I think what you need to do is to first create a data provider out of your data using a call like CGDataProviderCreateWithCFData(), then use the data provider to create a PDF object using CGPDFDocumentCreateWithProvider. 我还没有这样做,但我认为您需要做的是首先使用CGDataProviderCreateWithCFData()之类的调用从数据中创建数据提供程序,然后使用数据提供程序使用CGPDFDocumentCreateWithProvider创建PDF对象。

These are Core Foundation calls so you need to do manual memory management of the CF objects (ARC doesn't manage CF objects) 这些是Core Foundation调用,因此您需要对CF对象进行手动内存管理(ARC不管理CF对象)

You should be able to Google around using those terms and find code to do what you want. 您应该能够谷歌使用这些条款并找到代码来做你想做的事情。

Are the files store on parse as images or PDF's? 文件存储在解析为图像或PDF吗?

It sounds to me like you've got actual PDF files on parse. 听起来像你在解析时得到了实际的PDF文件。 You can't just convert them to an image as they aren't images. 您不能只将它们转换为图像,因为它们不是图像。

If they're PDF files you can save them to disk and then view them with QuickLookPreview https://developer.apple.com/library/prerelease/ios/documentation/NetworkingInternet/Reference/QLPreviewController_Class/index.html#//apple_ref/occ/instp/QLPreviewController/currentPreviewItem 如果它们是PDF文件,您可以将它们保存到磁盘,然后使用QuickLookPreview查看它们https://developer.apple.com/library/prerelease/ios/documentation/NetworkingInternet/Reference/QLPreviewController_Class/index.html#//apple_ref/ OCC / instp / QLPreviewController / currentPreviewItem

If they're actually images then you simply use: [UIImage imageWithData:data] 如果它们实际上是图像,那么您只需使用:[UIImage imageWithData:data]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM