Creating and showing pdf in Ionic

后端 未结 1 475
走了就别回头了
走了就别回头了 2021-01-05 22:18
  1. I am using PDFMAKE to create a base64 encoded pdf and I tried to show it with the Iframe by giving the encoded base64 to iframe src. It works on PC but it didn\'t w

相关标签:
1条回答
  • 2021-01-05 23:11

    So for our company app we used angular-pdf Viewer:

    Here is the template for the pdf viewer template, putting inside a ion-scroll allows for pinch zoom and it works great.

    <div ng-show="notLoaded" class=" center bar bar-subheader">
        <h1 class="title">Loading PDF...</h1>
    </div>
    <div class="tabs tabs-icon-left">
        <a class="tab-item" ng-click="goPrevious()">
            <i class="icon ion-arrow-left-c"></i>
            Prev
        </a>
        <a class="tab-item" ng-click="goNext()">
            <i class="icon ion-arrow-right-c"></i>
            Next
        </a>
    </div>
    
    <ion-scroll zooming="true" direction="xy" class="has-header">
        <canvas class="padding" id="pdf" class="rotate0"></canvas>
    </ion-scroll>
    

    then on the page that shows the pdf:

    <ion-view>
        <div class="bar bar-header bar-positive">
            <button ng-click="$ionicGoBack()" class="button button-clear button-light icon-left ion-chevron-left">Go Back</button>
        </div>
        <div class="has-header">
            <ng-pdf template-url="components/pdfviewer/viewer.html" canvasid="pdf" scale="0.675">
            </ng-pdf>
        </div>
    </ion-view>
    

    You feed the template to the pdf viewer and it will show up on the page.

    To use it first include the right js files:

    <script src="bower_components/pdfjs-dist/build/pdf.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/angular-pdf-viewer/dist/angular-pdf-viewer.min.js"></script>
    

    then inject pdf:

    var app = angular.module('App', ['pdf']);
    

    you can read more about it here, but using it in combination with ion-scroll it works just like you think it should on a native device:

    https://github.com/winkerVSbecks/angular-pdf-viewer

    0 讨论(0)
提交回复
热议问题