angularjs pdf插件_angular-pdf-viewer

Angular PDF Viewer

An AngularJS directive to display PDFs. DEMO

Dependencies

Usage

bower install angular-pdf-viewer

Include the path to the lib, AngularJS and PDFJS:

Include the lib as a dependency in your angular app:

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

Directive

The URL, request headers, scale and delegate-handle can be set using the attributes:

delegate-handle="my-pdf-container"

url="pdfUrl"

scale="1"

show-toolbar="true"

headers="{ 'x-you-know-whats-awesome': 'EVERYTHING' }">

Delegate Service (pdfDelegate)

The pdfDelegate service allows you to access and control individual instances of a directive. This allows us to have multiple instances of the same directive in the same controller.

Inject the pdfDelegate service into your controller. You can then fetch an instance using it's delegate handle and call methods on it:

pdfDelegate.$getByHandle('my-pdf-container').zoomIn();

The following methods are available to the delegate:

prev

next

zoomIn(amount) default amount = 0.2

zoomOut(amount) default amount = 0.2

zoomTo(amount)

rotate (clockwise by 90 degrees)

getPageCount

getCurrentPage

goToPage(pageNumber)

load

Change the PDF File

In order to replace the active PDF with another one, you can call the load method of the delegate. For example:

pdfDelegate

.$getByHandle('my-pdf-container')

.load('url-of-the-new-file.pdf');

Example

Run npm install && bower install to install all dependencies. And then gulp dev to start a local server. The example will now be available at localhost:3000/src

Toolbar

The default toolbar can be shown or hidden using the show-toolbar attribute. Since the PDF can be easily controlled using the delegate service it's quite trivial to build a custom toolbar. Or place the toolbar on a separate scope.

Similar projects

Credit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值