Generating thumbnail for iWork documents in swift

99 Views Asked by At

I am trying to convert an iWork file like .pages, .numbers into a thumbnail in iOS, Swift. I can do that for MS Office documents, by loading them into a WKWebview and screenshoting it afterwards by using the actual graphics context:

UIGraphicsBeginImageContextWithOptions(CGSize(width: 290, height: 290), false, 1)
guard let context = UIGraphicsGetCurrentContext() else { return }
self.imageWebView!.layer.render(in: context)
UIGraphicsEndImageContext()
guard let previewImageData = UIImagePNGRepresentation(thumbnail) else { return }

Now, the File is being displayed in the webview just fine but the created preview image isn't. Instead I get an image with the message in it:

Sorry, this document can't be viewed.

The document version may be unsupported or an error occured while reading it.

Any ideas what is going wrong?

0

There are 0 best solutions below