我也尝试过以下解决方案来查看uiwebvIEw中的djvu文件,但这没有帮助.
1.在uiwebvIEw中直接打开djvu文件
let urlPage : URL! = URL(string: "http://192.168.13.5:13/myData/5451890-OP.djvu") webVIEw.loadRequest(URLRequest(url: urlPage))
2.其次,我试图将djvu文件转换为pdf,并将转换后的pdf文件转换为视图.
参考链接:https://github.com/MadhuriMane/ios-djvu-reader
但这会使镜像质量低下.
3.我试图在UIdocumentInteractionController()的帮助下预览文件,它的委托方法却没有用.
请建议任何可行的方法.
解决方法 请记住.djvu文件不像EPUB,MOBI,pdf和其他电子书文件格式那样流行,我会采用以下方法解决问题.1)创建Web服务以将djvu文件转换为pdf
例如:http://example.com/djvutopdf/djvufile/outputfile
2)在UIWebVIEw中读取pdf文件
要创建Web服务,我假设您可以访问任何linux分布式服务器,在我的案例中是Ubuntu 16.04.
第一步:安装djvulibre
sudo apt-get install djvulibre-bin ghostscript
第二步:测试运行$djvups inputfile.djvu | ps2pdf – outputfile.pdf.
您也可以使用ddjvu命令.但是,使用ddjvu命令转换的文件比djvups命令大10倍.您可以考虑使用–help探索模式,质量等设置.
第三步:创建Web服务(为了简单起见,我使用PHP,在您方便时使用任何东西[Python golang])
<?PHP$inputfile = $_GET['input_file'];$outputfile = $_GET['output_file'];// use shell exec to execute the command// keep in mind that the conversion takes quite a long timeshell_exec(sprintf("djvups %s | ps2pdf - %s",$inputfile,$outputfile));$name = $outputfile;//file_get_contents is standard function$content = file_get_contents($name);header('Content-Type: application/pdf');header('Content-Length: '.strlen( $content ));header('Content-disposition: inline; filename="' . $name . '"');header('Cache-Control: public,must-revalIDate,max-age=0');header('Pragma: public');header('Expires: Sat,26 Jul 1997 05:00:00 GMT');header('Last-ModifIEd: '.gmdate('D,d M Y H:i:s').' GMT');echo $content;?>
最后一步:在App中加载pdf
正如Apple建议的那样,考虑使用WKWebVIEw代替UIWebVIEw.
if let pdfURL = Bundle.main.url(forResource: "pdffile",withExtension: "pdf",subdirectory: nil,localization: nil) { do { let data = try Data(contentsOf: pdfURL) let webVIEw = WKWebVIEw(frame: CGRect(x:20,y:20,wIDth:vIEw.frame.size.wIDth-40,height:vIEw.frame.size.height-40)) webVIEw.load(data,mimeType: "application/pdf",characterEnCodingname:"",baseURL: pdfURL.deletingLastPathComponent()) vIEw.addSubvIEw(webVIEw) } catch { // catch errors here }}总结
以上是内存溢出为你收集整理的ios – 如何在UIWebview中查看DJVU文件全部内容,希望文章能够帮你解决ios – 如何在UIWebview中查看DJVU文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)