ionic3 中查看pdf

本文展示了如何在Angular应用中集成ng2-pdf-viewer库,以实现PDF文件的查看功能。通过引入模块,配置组件,并在页面中使用 PdfViewer 组件,可以实现PDF的展示、翻页等功能。同时,提供了逻辑层代码,演示了如何监听页面变化并获取PDF信息。
npm install ng2-pdf-viewer@3.0.8 --save

需要使用 3.0.8版本的
在跟组件中注册模块

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';

import { PdfViewerModule } from 'ng2-pdf-viewer';

@NgModule({
  imports: [BrowserModule, PdfViewerModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})

class AppModule {}

platformBrowserDynamic().bootstrapModule(AppModule);

在页面中使用

<ion-header>
  <ion-navbar>
    <ion-title>
      在页面中使用
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <button (click)="next()">下一页</button>
  <pdf-viewer [src]="'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf'" //PDF所在地址
  [render-text]="true"
  [original-size]="false"
  style="width: 2000px; height: 1000px"  PDF大小
  [render-text]="true"  
  [show-all]="false"   // 不全部展示所有PDF
  [(page)] = "page"   // 展示第几页
  [stick-to-page]="true"  
  (pages-initialized)="pageInitialized($event)"
  (after-load-complete)="callBackFn($event)"  //获取PDF信息 如有多少页 等PDF信息
></pdf-viewer>
</ion-content>

逻辑层

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
  selector: 'page-about',
  templateUrl: 'about.html'
})
export class AboutPage {
public page = 1  // 一上来只让它展示第一页
  constructor(public navCtrl: NavController) {

  }
  next(){
    this.page++     // 每次点击下一页按钮就到下一页 
    console.log(this.page)
  }
  callBackFn ( pdf ) { 
    console.log(pdf)       // PDF 信息
    // 用“pdf”做任何事情
 }
}
Paperback: 338 pages Publisher: Packt Publishing - ebooks Account (August 3, 2015) Language: English ISBN-10: 1783552603 ISBN-13: 978-1783552603 Key Features Create hybrid mobile applications by combining the capabilities of Ionic, Cordova, and AngularJS Reduce the time to market your application using Ionic, that helps in rapid application development Detailed code examples and explanations, helping you get up and running with Ionic quickly and easily Book Description With the growth of the start-up market, the time it takes to market your app ideas is crucial. Developing apps using each platform specific format is time consuming and will put you behind in the rat race. Enter the hybrid mobile space: using knowledge of web technologies, one can transform their ideas into complete apps in no time and distribute them to a wide market of people. Apps developed using web technologies need to have a robust, testable, and scalable client side JavaScript framework. This is where a beautiful CSS framework named Ionic meets AngularJS to provide an elegant, robust, testable, and scalable framework enabling the building of hybrid mobile apps. With this book, you will learn hybrid mobile application development using Ionic. This book uses Cordova 5.0.0, Ionic CLI 1.5.0 & Ionic 1.0.0 to explain the concepts and build apps. To begin with, the book helps you understand where Ionic fits in today&#39;s world. Then you will deep dive into Ionic CSS components, Ionic-Angular directives, and services. You will also examine theming Ionic apps using the built in SCSS setup. Next, you will learn to build an Ionic client for a secure REST API, where you will implement user authentication and token-based development. Cordova and ngCordova will be explored and you will learn how you can integrate device specific features like a camera and Bluetooth with an Ionic app. You will wrap up the book by building a messaging app, which will deal with integrating REST API as well as device features. By the end of this book you will be able to develop a hybrid mobile application from start to finish. What you will learn Learn how a hybrid mobile application works Familiarize yourself with Cordova and see how it fits into hybrid mobile application development Seamlessly work with Ionic CSS components and Ionic-Angular JavaScript components like directives and services Learn how to theme Ionic apps, as well as customize components using Ionic SCSS support Develop an app that builds a client for a Secure REST API using Ionic & Angular Develop a real-time chat app using Firebase, that consumes ngCordova Learn how to generate a device specific installer for an Ionic app using Ionic CLI as well as Ionic Cloud services
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值