Generate document thumbnails

不羁的心 提交于 2019-12-03 21:54:06

Since you have an UIView that can display any of this documents you could just take a shortcut:

-Create an instance of your preview controller with displayed document

-Do not add this view/controller to anything

-Create image from its layer

This might help:

+ (UIImage *)imageFromView:(UIView *)view {
    CALayer *layer = view.layer;
    UIGraphicsBeginImageContext([layer frame].size);
    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();    
    return outputImage;
}

Play around a bit with layers and initialization as I didn't test the code..

The better option of you can use a uiwebview in which you can just load the file giving the filepath. Then take the screen shot by using the code given above by Matic Oblak and you are done.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!