我试图在应用程序中显示pdf文件,我已经测试了不同的选项--所有这些选项都基于pdf.js库https://github.com/mozilla/pdf.js并使用了角指令--我尝试了这个https://github.com/akrennmair/ng-pdfviewer,它提供了一个指令,并且在它内部有一个服务和控制器,但是我们的应用程序结构有点不同,我不得不将服务和控制器分开,当我完成实现不起作用时,我采取了另一种方法https://github.com/sayanee/angularjs-pdf角-pdf指令,它看起来更简单和容易实现,但不幸的是结果是一样的。它只是不加载文档,它可以是我的url路径pdf文件是错误的,我试图复制的结构一样的例子,这是一个例子https://github.com/sayanee/angularjs-pdf/tree/master/example上的命令到pdf可以加载和看到它在画布。
这就是控制器的样子,这基本上和萨亚尼一样
这是我的文件夹结构
/content
-----/mypdf.pdf
/app
----/JS
-----/pdfviewer
------/partials
--------/canvas.html
------/pdfviewer.html
------/pdfviewer.controller.html
------/pdfviewer.module.html
----/index.html
在我的controller.js里
$scope.pdfUrl ='./content/mypdf.pdf';
console.log( 'controller PDFViewerCtrl::'+ $scope.pdfUrl);
$scope.scroll = 0;
$scope.loading = 'loading';
$scope.getNavStyle = function(scroll) {
if(scroll > 100) return 'pdf-controls fixed';
else return 'pdf-controls';
};
$scope.onError = function(error) {
console.log(error);
};
$scope.onLoad = function() {
$scope.loading = '';
};
$scope.onProgress = function(progress) {
console.log(progress);
};
在pdfviewer.html中,我只保留画布
<hr>
{{loading}}
<canvas id="pdf" class="rotate0" ng-model="pdfUrl"></canvas>
在我的pdfviewer.html里
<ion-view class="pdfViewer" view-title="PDF" hide-nav-bar="false">
<ion-nav-buttons side="right">
</ion-nav-buttons>
<ion-nav-buttons side="left">
Done
</ion-nav-buttons>
<ion-content>
<div class="wrapper" ng-controller="PDFViewerCtrl">
<ng-pdf template-url="templates/pdfViewer/partials/canvas.html" canvasid="pdf" scale="page-fit" page=1>
</ng-pdf>
</div>
</ion-content>
</ion-view>
该模块如下所示:
angular.module('myapp', ['pdf'])
我还在pdf.js中添加了index.html库和指令
<script src="js/lib/pdf.js"></script>
<script src="js/directives/angular-pdf.js"></script>
我可以看到它调用指令,然后转到pdf库,但是,它挂在PDFJS.getDocument中,永远不会回来,所以我只能看到加载标签。
我很确定pdf.js和指令是否有效,但我不确定它是否适用于使用cordova、Angularjs和Ionic的混合移动应用程序。
我会感谢任何其他建议,以显示内部或外部的应用程序或。
发布于 2015-09-28 05:16:02
我终于可以将pdf.js与ionic项目集成在一起,然后我可以在移动混合应用程序中显示pdf文件,所以这里还有inAppBrowser cordova插件https://github.com/apache/cordova-plugin-inappbrowser之外的其他选项,这是在ionic应用程序中实现pdf.js和角离子的链接。
我希望它能帮助那些在移动混合应用程序中寻找pdf查看器的人。
https://stackoverflow.com/questions/32761896
复制相似问题