├── CHANGES.md ├── LICENSE.md ├── Makefile ├── README.md ├── dist ├── .gitignore ├── ng-pdfviewer.min.js └── ng-pdfviewer.min.map ├── example ├── index.html ├── ng-pdfviewer.js ├── pdf.compat.js ├── pdf.js ├── pdf.worker.js ├── test.js ├── test.pdf └── test2.pdf └── ng-pdfviewer.js /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Changes 2 | 3 | * 0.2.0: 4 | - All viewer instances need an ID now; commands are sent to specific instances. 5 | - A progress callback can be specified to track download progress. 6 | - Provide an example. 7 | - Provide a source map along with the minified source code. 8 | 9 | * 0.1.0: 10 | - Initial release. 11 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Andreas Krennmair 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SRC=ng-pdfviewer.js 2 | MIN_SRC=$(patsubst %.js,dist/%.min.js,$(SRC)) 3 | 4 | all: $(MIN_SRC) 5 | 6 | dist/%.min.js: %.js 7 | closure-compiler --js $< --js_output_file $@ --create_source_map $(patsubst %.js,%.map,$@) --source_map_format=v3 8 | echo '//@ sourceMappingURL=$(patsubst %.js,%.map,$@)' >> $@ 9 | 10 | check: 11 | jshint $(SRC) 12 | 13 | .PHONY: check 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ng-pdfviewer 2 | 3 | # *** WARNING *** Since I keep getting support requests for this: I haven't maintained ng-pdfviewer for ages, and I do not plan to do any further work on it. DO NOT USE THIS IN PRODUCTION!!! 4 | 5 | AngularJS PDF viewer directive using pdf.js. 6 | 7 | ``` html 8 | 9 | 10 |
11 | {{currentPage}}/{{totalPages}} 12 |
13 | 14 | ``` 15 | 16 | and in your AngularJS code: 17 | 18 | ``` js 19 | 20 | var app = angular.module('testApp', [ 'ngPDFViewer' ]); 21 | 22 | app.controller('TestCtrl', [ '$scope', 'PDFViewerService', function($scope, pdf) { 23 | $scope.viewer = pdf.Instance("viewer"); 24 | 25 | $scope.nextPage = function() { 26 | $scope.viewer.nextPage(); 27 | }; 28 | 29 | $scope.prevPage = function() { 30 | $scope.viewer.prevPage(); 31 | }; 32 | 33 | $scope.pageLoaded = function(curPage, totalPages) { 34 | $scope.currentPage = curPage; 35 | $scope.totalPages = totalPages; 36 | }; 37 | }]); 38 | ``` 39 | 40 | ## Requirements 41 | 42 | * AngularJS (http://angularjs.org/) 43 | * PDF.js (http://mozilla.github.io/pdf.js/) 44 | 45 | ## Usage 46 | 47 | Include `ng-pdfviewer.js` as JavaScript file, along with `pdf.js` and `pdf.compat.js`. 48 | 49 | Declare `ngPDFViewer` as dependency to your module. 50 | 51 | You can now use the `pdfviewer` tag in your HTML source. 52 | 53 | ## License 54 | 55 | MIT. See LICENSE.md for further details. 56 | 57 | ## Author 58 | 59 | Andreas Krennmair 60 | -------------------------------------------------------------------------------- /dist/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akrennmair/ng-pdfviewer/b2bfe63bb21e75c6724a1a0d0d1a7a131d16f6cf/dist/.gitignore -------------------------------------------------------------------------------- /dist/ng-pdfviewer.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | AngularJS PDF viewer directive using pdf.js. 3 | 4 | https://github.com/akrennmair/ng-pdfviewer 5 | 6 | MIT license 7 | */ 8 | angular.module("ngPDFViewer",[]).directive("pdfviewer",["$parse",function(){var d=null,e=null;return{restrict:"E",template:"",scope:{onPageLoad:"&",loadProgress:"&",src:"@",id:"="},controller:["$scope",function(a){a.pageNum=1;a.pdfDoc=null;a.scale=1;a.documentProgress=function(c){a.loadProgress&&a.loadProgress({state:"loading",loaded:c.loaded,total:c.total})};a.loadPDF=function(c){console.log("loadPDF ",c);PDFJS.getDocument(c,null,null,a.documentProgress).then(function(b){a.pdfDoc= 9 | b;a.renderPage(a.pageNum,function(){a.loadProgress&&a.loadProgress({state:"finished",loaded:0,total:0})})},function(b){console.log("PDF load error: "+b);a.loadProgress&&a.loadProgress({state:"error",loaded:0,total:0})})};a.renderPage=function(c,b){console.log("renderPage ",c);a.pdfDoc.getPage(c).then(function(c){var e=c.getViewport(a.scale),f=d.getContext("2d");d.height=e.height;d.width=e.width;c.render({canvasContext:f,viewport:e}).then(function(){b&&b(!0);a.$apply(function(){a.onPageLoad({page:a.pageNum, 10 | total:a.pdfDoc.numPages})})},function(){b&&b(!1);console.log("page.render failed")})})};a.$on("pdfviewer.nextPage",function(c,b){b===e&&a.pageNum 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ng-pdfviewer.js test 12 | 13 | 14 |
15 |
16 |
17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | 25 |
26 |
27 |
28 | {{currentPage}}/{{totalPages}} 29 |
30 |
31 | 32 |
33 |
34 | 35 | 36 | -------------------------------------------------------------------------------- /example/ng-pdfviewer.js: -------------------------------------------------------------------------------- 1 | ../ng-pdfviewer.js -------------------------------------------------------------------------------- /example/pdf.compat.js: -------------------------------------------------------------------------------- 1 | "undefined"===typeof PDFJS&&(("undefined"!==typeof window?window:this).PDFJS={}); 2 | (function(){function b(e,d){return new a(this.slice(e,d))}function c(a,d){2>arguments.length&&(d=0);for(var b=0,c=a.length;b>4,f=a+1>6:64,g=a+2>2)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(h)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)); 11 | return c})})();(function(){"atob"in window||(window.atob=function(b){b=b.replace(/=+$/,"");if(1==b.length%4)throw Error("bad atob input");for(var c=0,a,e,d=0,f="";e=b.charAt(d++);~e&&(a=c%4?64*a+e:e,c++%4)?f+=String.fromCharCode(255&a>>(-2*c&6)):0)e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);return f})})(); 12 | (function(){"undefined"===typeof Function.prototype.bind&&(Function.prototype.bind=function(b){var c=this,a=Array.prototype.slice.call(arguments,1);return function(){var e=Array.prototype.concat.apply(a,arguments);return c.apply(b,e)}})})(); 13 | (function(){"dataset"in document.createElement("div")||Object.defineProperty(HTMLElement.prototype,"dataset",{get:function(){if(this._dataset)return this._dataset;for(var b={},c=0,a=this.attributes.length;ch&&c&&g.push(b);0<=h&&f&&g.splice(h,1);a.className=g.join(" ")}if(!("classList"in document.createElement("div"))){var c={add:function(a){b(this.element,a,!0,!1)},remove:function(a){b(this.element,a,!1,!0)},toggle:function(a){b(this.element,a,!0,!0)}};Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){if(this._classList)return this._classList;var a=Object.create(c,{element:{value:this, 15 | writable:!1,enumerable:!0}});Object.defineProperty(this,"_classList",{value:a,writable:!1,enumerable:!1});return a},enumerable:!0})}})();(function(){if("console"in window){if(!("bind"in console.log)){var b=console.log;console.log=function(a){return b(a)};var c=console.error;console.error=function(a){return c(a)};var a=console.warn;console.warn=function(b){return a(b)}}}else window.console={log:function(){},error:function(){},warn:function(){}}})(); 16 | (function(){function b(a){c(a.target)&&a.stopPropagation()}function c(a){return a.disabled||a.parentNode&&c(a.parentNode)}-1!=navigator.userAgent.indexOf("Opera")&&document.addEventListener("click",b,!0)})();(function(){"language"in navigator||Object.defineProperty(navigator,"language",{get:function(){var b=navigator.userLanguage||"en-US";return b.substring(0,2).toLowerCase()+b.substring(2).toUpperCase()},enumerable:!0})})(); 17 | (function(){0=rb&&(H("Info: "+a),PDFJS.LogManager.notify("info",a))}function B(a){ra>=sa&&(H("Warning: "+a),PDFJS.LogManager.notify("warn",a))}function l(a){if(1c)return b;switch(a.substr(0,c)){case "http":case "https":case "ftp":case "mailto":return!0;default:return!1}}function V(a,b,c){Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!1}); 4 | return c}function Q(a){var b,c=a.length,d="";if("\u00fe"===a[0]&&"\u00ff"===a[1])for(b=2;ba[2]&&(b[0]=a[2],b[2]=a[0]);a[1]>a[3]&&(b[1]=a[3],b[3]=a[1]);return b};q.intersect=function(a,b){function c(a,b){return a-b}var d=[a[0],a[2],b[0],b[2]].sort(c),e=[a[1],a[3],b[1],b[3]].sort(c),f=[];a=q.normalizeRect(a);b=q.normalizeRect(b);if(d[0]===a[0]&&d[1]===b[0]||d[0]===b[0]&&d[1]===a[0])f[0]=d[1],f[2]=d[2];else return!1;if(e[0]===a[1]&&e[1]===b[1]||e[0]===b[1]&&e[1]=== 15 | a[1])f[1]=e[1],f[3]=e[2];else return!1;return f};q.sign=function(a){return 0>a?-1:1};q.concatenateToArray=function(a,b){Array.prototype.push.apply(a,b)};q.prependToArray=function(a,b){Array.prototype.unshift.apply(a,b)};q.extendObj=function(a,b){for(var c in b)a[c]=b[c]};q.getInheritableProperty=function(a,b){for(;a&&!a.has(b);)a=a.get("Parent");return!a?null:a.get(b)};q.inherit=function(a,b,c){a.prototype=Object.create(b.prototype);a.prototype.constructor=a;for(var d in c)a.prototype[d]=c[d]};q.loadScript= 16 | function(a,b){var c=document.createElement("script"),d=!1;c.setAttribute("src",a);b&&(c.onload=function(){d||b();d=!0});document.getElementsByTagName("head")[0].appendChild(c)};var r=ub.Util=q,vb=PDFJS,da=function(a,b,c,d,e,f){this.viewBox=a;this.scale=b;this.rotation=c;this.offsetX=d;this.offsetY=e;var g=(a[2]+a[0])/2,h=(a[3]+a[1])/2,j,m,k;c%=360;switch(0>c?c+360:c){case 180:c=-1;m=j=0;k=1;break;case 90:c=0;m=j=1;k=0;break;case 270:c=0;m=j=-1;k=0;break;default:c=1,m=j=0,k=-1}f&&(m=-m,k=-k);0===c? 17 | (d=Math.abs(h-a[1])*b+d,e=Math.abs(g-a[0])*b+e,f=Math.abs(a[3]-a[1])*b,a=Math.abs(a[2]-a[0])*b):(d=Math.abs(g-a[0])*b+d,e=Math.abs(h-a[1])*b+e,f=Math.abs(a[2]-a[0])*b,a=Math.abs(a[3]-a[1])*b);this.transform=[c*b,j*b,m*b,k*b,d-c*b*g-m*b*h,e-j*b*g-k*b*h];this.width=f;this.height=a;this.fontScale=b};da.prototype={clone:function(a){a=a||{};var b="scale"in a?a.scale:this.scale,c="rotation"in a?a.rotation:this.rotation;return new da(this.viewBox.slice(),b,c,this.offsetX,this.offsetY,a.dontFlip)},convertToViewportPoint:function(a, 18 | b){return r.applyTransform([a,b],this.transform)},convertToViewportRectangle:function(a){var b=r.applyTransform([a[0],a[1]],this.transform);a=r.applyTransform([a[2],a[3]],this.transform);return[b[0],b[1],a[0],a[1]]},convertToPdfPoint:function(a,b){return r.applyInverseTransform([a,b],this.transform)}};vb.PageViewport=da;var tb=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,728,711,710,729,733,731,730,732,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 19 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8226,8224,8225,8230,8212,8211,402,8260,8249,8250,8722,8240,8222,8220,8221,8216,8217,8218,8482,64257,64258,321,338,352,376,381,305,322,339,353,382,0,8364],wb=PDFJS,T=function(){this._status=ya;this._handlers=[]},ya=0,K=2,ea={handlers:[],running:!1,unhandledRejections:[],pendingRejectionCheck:!1,scheduleHandlers:function(a){a._status!=ya&&(this.handlers=this.handlers.concat(a._handlers),a._handlers=[], 20 | this.running||(this.running=!0,setTimeout(this.runHandlers.bind(this),0)))},runHandlers:function(){for(;0c&&(c=f.length)}d=0;for(e=a.length;df&&"DeviceGray"!==this.name&&"DeviceRGB"!==this.name){for(var g=8>=d?new Uint8Array(f):new Uint16Array(f),h=0;ha?0:255e?0:255f?0:255a?0:255a?0:a;d[e+1]=255b?0:b;d[e+2]=255f?0:f},La=function(){this.name="DeviceCMYK";this.numComps=4;this.defaultColor=new Float32Array([0,0,0,1])};La.prototype={getRgb:function(a,b){var c=new Uint8Array(3);ga(a,b,1,c,0);return c},getRgbItem:function(a,b,c,d){ga(a,b,1,c,d)},getRgbBuffer:function(a,b,c,d,e,f){f=1/((1<>2)},isPassthrough:t.prototype.isPassthrough,createRgbBuffer:t.prototype.createRgbBuffer, 42 | isDefaultDecode:function(a){return t.isDefaultDecode(a,this.numComps)},usesZeroToOneRange:!0};Fa=La;var Ca,Ma=function(a,b,c){this.name="Lab";this.numComps=3;this.defaultColor=new Float32Array([0,0,0]);a||l("WhitePoint missing - required for color space Lab");b=b||[0,0,0];c=c||[-100,100,-100,100];this.XW=a[0];this.YW=a[1];this.ZW=a[2];this.amin=c[0];this.amax=c[1];this.bmin=c[2];this.bmax=c[3];this.XB=b[0];this.YB=b[1];this.ZB=b[2];(0>this.XW||0>this.ZW||1!==this.YW)&&l("Invalid WhitePoint components, no fallback available"); 43 | if(0>this.XB||0>this.YB||0>this.ZB)G("Invalid BlackPoint, falling back to default"),this.XB=this.YB=this.ZB=0;if(this.amin>this.amax||this.bmin>this.bmax)G("Invalid Range, falling back to defaults"),this.amin=-100,this.amax=100,this.bmin=-100,this.bmax=100},ha=function(a){return a>=6/29?a*a*a:108/841*(a-4/29)},ia=function(a,b,c,d,e,f){var g=b[c],h=b[c+1];b=b[c+2];!1!==d&&(g=0+100*g/d,h=a.amin+h*(a.amax-a.amin)/d,b=a.bmin+b*(a.bmax-a.bmin)/d);h=h>a.amax?a.amax:ha.bmax?a.bmax:b< 44 | a.bmin?a.bmin:b;d=(g+16)/116;g=d-b/200;h=a.XW*ha(d+h/500);d=a.YW*ha(d);g=a.ZW*ha(g);1>a.ZW?(a=3.1339*h+-1.617*d+-0.4906*g,b=-0.9785*h+1.916*d+0.0333*g,h=0.072*h+-0.229*d+1.4057*g):(a=3.2406*h+-1.5372*d+-0.4986*g,b=-0.9689*h+1.8758*d+0.0415*g,h=0.0557*h+-0.204*d+1.057*g);e[f]=255*Math.sqrt(0>a?0:1b?0:1h?0:1=f||0>=h)G("Bad shading domain.");else{for(j=d;j<=f;j+=h)k=b.getRgb(m([j]),0),k=r.makeCssRgb(k),c.push([(j-d)/n,k]);d="transparent";a.has("Background")&&(k=b.getRgb(a.get("Background"),0),d=r.makeCssRgb(k));e||(c.unshift([0,d]),c[1][0]+=N.SMALL_NUMBER);g||(c[c.length-1][0]-=N.SMALL_NUMBER,c.push([1,d]));this.colorStops=c}};ja.fromIR=function(a){var b=a[1],c=a[2],d=a[3],e=a[4],f=a[5],g=a[6];return{type:"Pattern",getPattern:function(a){var j;2== 49 | b?j=a.createLinearGradient(d[0],d[1],e[0],e[1]):3==b&&(j=a.createRadialGradient(d[0],d[1],f,e[0],e[1],g));a=0;for(var m=c.length;a>b)*h);g&=(1<g?a=g:ac[s+1]&&(k=c[s+1]);m[j]=k}f.set(a,m);return m}}};var Qa,Ra=function(){this.cache={};this.total=0};Ra.prototype={has:function(a){return a in this.cache},get:function(a){return this.cache[a]},set:function(a,b){1024>this.total&&(this.cache[a]=b,this.total++)}};Qa=Ra;var Sa=function(a){this.stack=a||[]};Sa.prototype={push:function(a){100<=this.stack.length&& 62 | l("PostScript function stack overflow.");this.stack.push(a)},pop:function(){0>=this.stack.length&&l("PostScript function stack underflow.");return this.stack.pop()},copy:function(a){100<=this.stack.length+a&&l("PostScript function stack overflow.");var b=this.stack,c=b.length-a;for(a-=1;0<=a;a--,c++)b.push(b[c])},index:function(a){this.push(this.stack[this.stack.length-a-1])},roll:function(a,b){var c=this.stack,d=c.length-a,e=c.length-1,f=d+(b-Math.floor(b/a)*a),g,h,j;g=d;for(h=e;g>f);break;case "ceiling":e=a.pop();a.push(Math.ceil(e));break;case "copy":e=a.pop();a.copy(e);break;case "cos":e=a.pop();a.push(Math.cos(e));break;case "cvi":e=a.pop()|0;a.push(e);break;case "cvr":break;case "div":f=a.pop();e=a.pop();a.push(e/f);break;case "dup":a.copy(1);break;case "eq":f=a.pop();e=a.pop();a.push(e==f);break;case "exch":a.roll(2, 65 | 1);break;case "exp":f=a.pop();e=a.pop();a.push(Math.pow(e,f));break;case "false":a.push(!1);break;case "floor":e=a.pop();a.push(Math.floor(e));break;case "ge":f=a.pop();e=a.pop();a.push(e>=f);break;case "gt":f=a.pop();e=a.pop();a.push(e>f);break;case "idiv":f=a.pop();e=a.pop();a.push(e/f|0);break;case "index":e=a.pop();a.index(e);break;case "le":f=a.pop();e=a.pop();a.push(e<=f);break;case "ln":e=a.pop();a.push(Math.log(e));break;case "log":e=a.pop();a.push(Math.log(e)/Math.LN10);break;case "lt":f= 66 | a.pop();e=a.pop();a.push(ee?Math.ceil(e):Math.floor(e);a.push(e);break;case "xor":f=a.pop();e=a.pop();I(e)&&I(f)?a.push(e!=f):a.push(e^f);break;default:l("Unknown operator "+e)}return a.stack}};Pa=Ta;var Oa,Ua=function(a){this.lexer=a;this.operators=[];this.prev=this.token=null};Ua.prototype={nextToken:function(){this.prev=this.token;this.token= 68 | this.lexer.getToken()},accept:function(a){return this.token.type==a?(this.nextToken(),!0):!1},expect:function(a){if(this.accept(a))return!0;l("Unexpected symbol: found "+this.token.type+" expected "+a+".")},parse:function(){this.nextToken();this.expect(y.LBRACE);this.parseBlock();this.expect(y.RBRACE);return this.operators},parseBlock:function(){for(;;)if(this.accept(y.NUMBER))this.operators.push(this.prev.value);else if(this.accept(y.OPERATOR))this.operators.push(this.prev.value);else if(this.accept(y.LBRACE))this.parseCondition(); 69 | else break},parseCondition:function(){var a=this.operators.length;this.operators.push(null,null);this.parseBlock();this.expect(y.RBRACE);if(this.accept(y.IF))this.operators[a]=this.operators.length,this.operators[a+1]="jz";else if(this.accept(y.LBRACE)){var b=this.operators.length;this.operators.push(null,null);var c=this.operators.length;this.parseBlock();this.expect(y.RBRACE);this.expect(y.IFELSE);this.operators[b]=this.operators.length;this.operators[b+1]="j";this.operators[a]=c;this.operators[a+ 70 | 1]="jz"}else l("PS Function: error parsing conditional.")}};Oa=Ua;var y={LBRACE:0,RBRACE:1,NUMBER:2,OPERATOR:3,IF:4,IFELSE:5},A=function(a,b){this.type=a;this.value=b},Va={};A.getOperator=function(a){var b=Va[a];return b?b:Va[a]=new A(y.OPERATOR,a)};A.LBRACE=new A(y.LBRACE,"{");A.RBRACE=new A(y.RBRACE,"}");A.IF=new A(y.IF,"IF");A.IFELSE=new A(y.IFELSE,"IFELSE");var Na,Wa=function(a){this.stream=a;this.nextChar()};Wa.prototype={nextChar:function(){return this.currentChar=this.stream.getByte()},getToken:function(){for(var a= 71 | !1,b=this.currentChar;;){if(0>b)return EOF;if(a){if(10===b||13===b)a=!1}else if(37==b)a=!0;else if(!Lexer.isSpace(b))break;b=this.nextChar()}switch(b|0){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:case 43:case 45:case 46:return new A(y.NUMBER,this.getNumber());case 123:return this.nextChar(),A.LBRACE;case 125:return this.nextChar(),A.RBRACE}for(a=String.fromCharCode(b);0<=(b=this.nextChar())&&(65<=b&&90>=b||97<=b&&122>=b);)a+=String.fromCharCode(b);switch(a.toLowerCase()){case "if":return A.IF; 72 | case "ifelse":return A.IFELSE;default:return A.getOperator(a)}},getNumber:function(){for(var a=this.currentChar,b=String.fromCharCode(a);0<=(a=this.nextChar());)if(48<=a&&57>=a||45===a||46===a)b+=String.fromCharCode(a);else break;a=parseFloat(b);isNaN(a)&&l("Invalid floating point number: "+a);return a}};Na=Wa;var z=function(a){if(a.data)this.data=a.data;else{var b=a.dict;a=this.data={};a.subtype=b.get("Subtype").name;var c=b.get("Rect");a.rect=r.normalizeRect(c);a.annotationFlags=b.get("F");c=b.get("C"); 73 | a.color=E(c)&&3===c.length?c:[0,0,0];b.has("BS")?(c=b.get("BS"),a.borderWidth=c.has("W")?c.get("W"):1):(c=b.get("Border")||[0,0,1],a.borderWidth=c[2]||0);var d;c=b.get("AP");O(c)?(c=c.get("N"),O(c)?(b=b.get("AS"))&&c.has(b.name)&&(d=c.get(b.name)):d=c):d=void 0;this.appearance=d;a.hasAppearance=!!this.appearance}};z.prototype={getData:function(){return this.data},hasHtml:function(){return!1},getHtmlElement:function(){throw new S("getHtmlElement() should be implemented in subclass");},getEmptyContainer:function(a, 74 | b){!R||l("getEmptyContainer() should be called from main thread");b=b||this.data.rect;var c=document.createElement(a);c.style.width=Math.ceil(b[2]-b[0])+"px";c.style.height=Math.ceil(b[3]-b[1])+"px";return c},isViewable:function(){var a=this.data;return!(!a||a.annotationFlags&&a.annotationFlags&34||!a.rect)},loadResources:function(a){var b=new C;this.appearance.dict.getAsync("Resources").then(function(c){c?(new ObjectLoader(c.map,a,c.xref)).load().then(function(){b.resolve(c)}):b.resolve()}.bind(this)); 75 | return b},getOperatorList:function(a){var b=new C;if(!this.appearance)return b.resolve(new OperatorList),b;var c=this.data,d=this.appearance.dict,e=this.loadResources("ExtGState ColorSpace Pattern Shading XObject Font".split(" ")),f=d.get("BBox")||[0,0,1,1],g=d.get("Matrix")||[1,0,0,1,0,0],h;var d=c.rect,j=r.getAxialAlignedBoundingBox(f,g),f=j[0],m=j[1],k=j[2],j=j[3];f===k||m===j?h=[1,0,0,1,d[0],d[1]]:(k=(d[2]-d[0])/(k-f),j=(d[3]-d[1])/(j-m),h=[k,0,0,j,d[0]-f*k,d[1]-m*j]);e.then(function(d){var e= 76 | new OperatorList;e.addOp("beginAnnotation",[c.rect,h,g]);a.getOperatorList(this.appearance,d,e);e.addOp("endAnnotation",[]);b.resolve(e)}.bind(this));return b}};z.getConstructor=function(a,b){if(a){if("Link"===a)return Xa;if("Text"===a)return Ya;if("Widget"===a){if(b)return"Tx"===b?Za:X}else return z}};z.fromData=function(a){var b=z.getConstructor(a.subtype,a.fieldType);if(b)return new b({data:a})};z.fromRef=function(a,b){var c=a.fetchIfRef(b);if(O(c)){var d=c.get("Subtype");if(d=J(d)?d.name:""){var e= 77 | r.getInheritableProperty(c,"FT"),e=J(e)?e.name:"";if(e=z.getConstructor(d,e)){c=new e({dict:c,ref:b});if(c.isViewable())return c;L("unimplemented annotation type: "+d)}}}};z.appendToOperatorList=function(a,b,c,d){var e=new C;c=[];for(var f=0,g=a.length;fb.fontDirection?"rtl":"ltr";a&&(e.fontWeight=a.black?a.bold? 81 | "bolder":"bold":a.bold?"bold":"normal",e.fontStyle=a.italic?"italic":"normal",b=a.loadedName,e.fontFamily=(b?'"'+b+'", ':"")+(a.fallbackName||"Helvetica, sans-serif"));c.appendChild(d);return c},getOperatorList:function(a){if(this.appearance)return z.prototype.getOperatorList.call(this,a);var b=new C,c=new OperatorList,d=this.data,e=d.defaultAppearance;if(!e)return b.resolve(c),b;for(var f=Stream,g=e.length,h=new Uint8Array(g),j=0;jf;++f)g=a[f],h=e[f],"setFont"===g?(d.fontRefName=h[0],g=h[1],0>g?(d.fontDirection=-1,d.fontSize=-g):(d.fontDirection=1,d.fontSize=g)):"setFillRGBColor"===g?d.rgb=h:"setFillGray"===g&&(g=255*h[0],d.rgb=[g,g,g]);b.resolve(c);return b}});Za=ab;var Ya,bb=function(a){z.call(this,a);if(!a.data){a=a.dict;var b=this.data,c=a.get("Contents"),d=a.get("T");b.content=Q(c||"");b.title=Q(d||"");b.name=!a.has("Name")?"Note":a.get("Name").name}};r.inherit(bb,z, 83 | {getOperatorList:function(){var a=new C;a.resolve(new OperatorList);return a},hasHtml:function(){return!0},getHtmlElement:function(){!R||l("getHtmlElement() shall be called from main thread");var a=this.data,b=a.rect;10>b[3]-b[1]&&(b[3]=b[1]+10);10>b[2]-b[0]&&(b[2]=b[0]+(b[3]-b[1]));var c=this.getEmptyContainer("section",b);c.className="annotText";var d=document.createElement("img");d.style.height=c.style.height;var e=a.name;d.src=PDFJS.imageResourcesPath+"annotation-"+e.toLowerCase()+".svg";d.alt= 84 | "[{{type}} Annotation]";d.dataset.l10nId="text_annotation_type";d.dataset.l10nArgs=JSON.stringify({type:e});var f=document.createElement("div");f.setAttribute("hidden",!0);var e=document.createElement("h1"),g=document.createElement("p");f.style.left=Math.floor(b[2]-b[0])+"px";f.style.top="0px";e.textContent=a.title;if(!a.content&&!a.title)f.setAttribute("hidden",!0);else{for(var b=document.createElement("span"),a=a.content.split(/(?:\r\n?|\n)/),h=0,j=a.length;hf;++f)e[f]=Math.round(255*d[f]);b.style.borderColor=r.makeCssRgb(e);b.style.borderStyle="solid";d=a[3]-a[1]-2*c;b.style.width=a[2]-a[0]-2*c+"px";b.style.height=d+"px";b.href=this.data.url||"";return b}});Xa=cb;PDFJS.maxImageSize=void 0===PDFJS.maxImageSize?-1:PDFJS.maxImageSize;PDFJS.disableFontFace=void 0===PDFJS.disableFontFace?!1:PDFJS.disableFontFace;PDFJS.getDocument=function(a, 88 | b,c,d){var e,f;"string"===typeof a?a={url:a}:"object"==typeof a&&null!==a&&void 0!==a&&"byteLength"in a?a={data:a}:"object"!==typeof a&&l("Invalid parameter in getDocument, need either Uint8Array, string or a parameter object");!a.url&&!a.data&&l("Invalid parameter array, need either .data or .url");var g={};for(e in a)g[e]="url"===e&&"undefined"!==typeof window?sb(window.location.href,a[e]):a[e];a=new PDFJS.Promise;e=new PDFJS.Promise;f=new db(a,e,b,d);a.then(function(){f.passwordCallback=c;f.fetchDocument(g)}); 89 | return e};var eb=function(a,b){this.pdfInfo=a;this.transport=b};eb.prototype={get numPages(){return this.pdfInfo.numPages},get fingerprint(){return this.pdfInfo.fingerprint},get embeddedFontsUsed(){return this.transport.embeddedFontsUsed},getPage:function(a){return this.transport.getPage(a)},getDestinations:function(){return this.transport.getDestinations()},getJavaScript:function(){var a=new PDFJS.Promise;a.resolve(this.pdfInfo.javaScript);return a},getOutline:function(){var a=new PDFJS.Promise; 90 | a.resolve(this.pdfInfo.outline);return a},getMetadata:function(){var a=new PDFJS.Promise,b=this.pdfInfo.metadata;a.resolve({info:this.pdfInfo.info,metadata:b?new PDFJS.Metadata(b):null});return a},isEncrypted:function(){var a=new PDFJS.Promise;a.resolve(this.pdfInfo.encrypted);return a},getData:function(){var a=new PDFJS.Promise;this.transport.getData(a);return a},dataLoaded:function(){return this.transport.dataLoaded()},destroy:function(){this.transport.destroy()}};var fb=function(a,b){this.pageInfo= 91 | a;this.transport=b;this.stats=new za;this.stats.enabled=!!w.PDFJS.enableStats;this.commonObjs=b.commonObjs;this.objs=new na;this.pendingDestroy=this.cleanupAfterRender=this.receivingOperatorList=!1;this.renderTasks=[]};fb.prototype={get pageNumber(){return this.pageInfo.pageIndex+1},get rotate(){return this.pageInfo.rotate},get ref(){return this.pageInfo.ref},get view(){return this.pageInfo.view},getViewport:function(a,b){2>arguments.length&&(b=this.rotate);return new PDFJS.PageViewport(this.view, 92 | a,b,0,0)},getAnnotations:function(){if(this.annotationsPromise)return this.annotationsPromise;var a=new PDFJS.Promise;this.annotationsPromise=a;this.transport.getAnnotations(this.pageInfo.pageIndex);return a},render:function(a){function b(a){var b=f.renderTasks.indexOf(d);0<=b&&f.renderTasks.splice(b,1);f.cleanupAfterRender&&(f.pendingDestroy=!0);f._tryDestroy();a?e.reject(a):e.resolve();c.timeEnd("Rendering");c.timeEnd("Overall")}var c=this.stats;c.time("Overall");this.pendingDestroy=!1;this.displayReadyPromise|| 93 | (this.receivingOperatorList=!0,this.displayReadyPromise=new C,this.operatorList={fnArray:[],argsArray:[],lastChunk:!1},this.stats.time("Page Request"),this.transport.messageHandler.send("RenderPageRequest",{pageIndex:this.pageNumber-1}));var d=new gb(b,a,this.objs,this.commonObjs,this.operatorList,this.pageNumber);this.renderTasks.push(d);var e=new hb(d),f=this;this.displayReadyPromise.then(function(a){f.pendingDestroy?b():(c.time("Rendering"),d.initalizeGraphics(a),d.operatorListChanged())},function(a){b(a)}); 94 | return e},getTextContent:function(){var a=new PDFJS.Promise;this.transport.messageHandler.send("GetTextContent",{pageIndex:this.pageNumber-1},function(b){a.resolve(b)});return a},getOperationList:function(){var a=new PDFJS.Promise;a.resolve({dependencyFontsID:null,operatorList:null});return a},destroy:function(){this.pendingDestroy=!0;this._tryDestroy()},_tryDestroy:function(){if(this.pendingDestroy&&!(0!==this.renderTasks.length||this.receivingOperatorList))delete this.operatorList,delete this.displayReadyPromise, 95 | this.objs.clear(),this.pendingDestroy=!1},_startRenderPage:function(a){this.displayReadyPromise.resolve(a)},_renderPageChunk:function(a){r.concatenateToArray(this.operatorList.fnArray,a.fnArray);r.concatenateToArray(this.operatorList.argsArray,a.argsArray);this.operatorList.lastChunk=a.lastChunk;for(var b=0;b\\376\\377([^<]+)/g,function(a,c){for(var d=c.replace(/\\([0-3])([0-7])([0-7])/g,function(a,b,c,d){return String.fromCharCode(64*b+8*c+1*d)}),e="",f=0;f"+e}),a=(new DOMParser).parseFromString(a,"application/xml")):a instanceof Document||l("Metadata: Invalid metadata object"); 112 | this.metaDocument=a;this.metadata={};this.parse()};mb.prototype={parse:function(){var a=this.metaDocument.documentElement;if("rdf:rdf"!==a.nodeName.toLowerCase())for(a=a.firstChild;a&&"rdf:rdf"!==a.nodeName.toLowerCase();)a=a.nextSibling;var b=a?a.nodeName.toLowerCase():null;if(a&&"rdf:rdf"===b&&a.hasChildNodes()){var a=a.childNodes,c,d,e,f,g,h;e=0;for(g=a.length;eg)return setTimeout(c,0),b}},endDrawing:function(){this.ctx.restore();F.clear();this.textLayer&&this.textLayer.endLayout();this.imageLayer&&this.imageLayer.endLayout()},setLineWidth:function(a){this.current.lineWidth=a;this.ctx.lineWidth=a},setLineCap:function(a){this.ctx.lineCap=Bb[a]}, 120 | setLineJoin:function(a){this.ctx.lineJoin=Cb[a]},setMiterLimit:function(a){this.ctx.miterLimit=a},setDash:function(a,b){var c=this.ctx;"setLineDash"in c?(c.setLineDash(a),c.lineDashOffset=b):(c.mozDash=a,c.mozDashOffset=b)},setRenderingIntent:function(){},setFlatness:function(){},setGState:function(a){for(var b=0,c=a.length;bb?(b=-b,d.fontDirection=-1):d.fontDirection=1;this.current.font=c;this.current.fontSize=b;if(!c.coded){var d=c.black?c.bold?"bolder":"bold":c.bold?"bold":"normal",e=c.italic?"italic":"normal",c='"'+(c.loadedName||"sans-serif")+'", '+c.fallbackName,f=16<=b?b:16;this.current.fontSizeScale=16!=f?1:b/16;this.ctx.font=e+" "+d+" "+f+"px "+c}},setTextRenderingMode:function(a){this.current.textRenderingMode=a},setTextRise:function(a){this.current.textRise= 129 | a},moveText:function(a,b){this.current.x=this.current.lineX+=a;this.current.y=this.current.lineY+=b},setLeadingMoveText:function(a,b){this.setLeading(-b);this.moveText(a,b)},setTextMatrix:function(a,b,c,d,e,f){this.current.textMatrix=[a,b,c,d,e,f];this.current.x=this.current.lineX=0;this.current.y=this.current.lineY=0},nextLine:function(){this.moveText(0,this.current.leading)},applyTextTransforms:function(){var a=this.ctx,b=this.current;a.transform.apply(a,b.textMatrix);a.translate(b.x,b.y+b.textRise); 130 | 0= 143 | a);this.baseTransform=this.baseTransformStack.pop()},beginGroup:function(a){this.save();var b=this.ctx;a.isolated||G("TODO: Support non-isolated groups.");a.knockout&&L("Support knockout groups.");var c=b.mozCurrentTransform;a.matrix&&b.transform.apply(b,a.matrix);a.bbox||l("Bounding box is required.");var d=r.getAxialAlignedBoundingBox(a.bbox,b.mozCurrentTransform);a=Math.max(Math.ceil(d[2]-d[0]),1);var e=Math.max(Math.ceil(d[3]-d[1]),1);a=F.getCanvas("groupAt"+this.groupLevel,a,e,!0).context;e= 144 | d[0];d=d[1];a.translate(-e,-d);a.transform.apply(a,c);b.setTransform(1,0,0,1,0,0);b.translate(e,d);c="strokeStyle fillStyle fillRule globalAlpha lineWidth lineCap lineJoin miterLimit globalCompositeOperation font".split(" ");d=0;for(e=c.length;d=c&&1E3>=d)a:{var g=a.data,h,j,m=c+1,k=new Uint8Array(m*(d+1)),s=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=3,p=4*c,l=0;0!==g[3]&&(k[0]=1,++l);for(h=1;h>2)+(g[n+4]?4:0)+(g[n-p+ 148 | 4]?8:0),s[q]&&(k[j+h]=s[q],++l),n+=4;g[n-p]!==g[n]&&(k[j+h]=g[n]?2:4,++l);n+=4;if(1E3>4,k[h]&=s>>2|s<<2);j.push(h%m);j.push(h/m|0);--l}while(n!== 149 | h);r.push(j);--f}}f=function(a){a.save();a.scale(1/c,-1/d);a.translate(0,-d);a.beginPath();for(var b=0,e=r.length;b>24&255)+String.fromCharCode(q>>16& 160 | 255)+String.fromCharCode(q>>8&255)+String.fromCharCode(q&255));g="url(data:font/opentype;base64,"+btoa(k)+");";P.insertRule('@font-face { font-family:"'+a+'";src:'+g+"}");q=[];g=0;for(h=b.length;g', 17 | scope: { 18 | onPageLoad: '&', 19 | loadProgress: '&', 20 | src: '@', 21 | id: '=' 22 | }, 23 | controller: [ '$scope', function($scope) { 24 | $scope.pageNum = 1; 25 | $scope.pdfDoc = null; 26 | $scope.scale = 1.0; 27 | 28 | $scope.documentProgress = function(progressData) { 29 | if ($scope.loadProgress) { 30 | $scope.loadProgress({state: "loading", loaded: progressData.loaded, total: progressData.total}); 31 | } 32 | }; 33 | 34 | $scope.loadPDF = function(path) { 35 | console.log('loadPDF ', path); 36 | PDFJS.getDocument(path, null, null, $scope.documentProgress).then(function(_pdfDoc) { 37 | $scope.pdfDoc = _pdfDoc; 38 | $scope.renderPage($scope.pageNum, function(success) { 39 | if ($scope.loadProgress) { 40 | $scope.loadProgress({state: "finished", loaded: 0, total: 0}); 41 | } 42 | }); 43 | }, function(message, exception) { 44 | console.log("PDF load error: " + message); 45 | if ($scope.loadProgress) { 46 | $scope.loadProgress({state: "error", loaded: 0, total: 0}); 47 | } 48 | }); 49 | }; 50 | 51 | $scope.renderPage = function(num, callback) { 52 | console.log('renderPage ', num); 53 | $scope.pdfDoc.getPage(num).then(function(page) { 54 | var viewport = page.getViewport($scope.scale); 55 | var ctx = canvas.getContext('2d'); 56 | 57 | canvas.height = viewport.height; 58 | canvas.width = viewport.width; 59 | 60 | page.render({ canvasContext: ctx, viewport: viewport }).promise.then( 61 | function() { 62 | if (callback) { 63 | callback(true); 64 | } 65 | $scope.$apply(function() { 66 | $scope.onPageLoad({ page: $scope.pageNum, total: $scope.pdfDoc.numPages }); 67 | }); 68 | }, 69 | function() { 70 | if (callback) { 71 | callback(false); 72 | } 73 | console.log('page.render failed'); 74 | } 75 | ); 76 | }); 77 | }; 78 | 79 | $scope.$on('pdfviewer.nextPage', function(evt, id) { 80 | if (id !== instance_id) { 81 | return; 82 | } 83 | 84 | if ($scope.pageNum < $scope.pdfDoc.numPages) { 85 | $scope.pageNum++; 86 | $scope.renderPage($scope.pageNum); 87 | } 88 | }); 89 | 90 | $scope.$on('pdfviewer.prevPage', function(evt, id) { 91 | if (id !== instance_id) { 92 | return; 93 | } 94 | 95 | if ($scope.pageNum > 1) { 96 | $scope.pageNum--; 97 | $scope.renderPage($scope.pageNum); 98 | } 99 | }); 100 | 101 | $scope.$on('pdfviewer.gotoPage', function(evt, id, page) { 102 | if (id !== instance_id) { 103 | return; 104 | } 105 | 106 | if (page >= 1 && page <= $scope.pdfDoc.numPages) { 107 | $scope.pageNum = page; 108 | $scope.renderPage($scope.pageNum); 109 | } 110 | }); 111 | } ], 112 | link: function(scope, iElement, iAttr) { 113 | canvas = iElement.find('canvas')[0]; 114 | instance_id = iAttr.id; 115 | 116 | iAttr.$observe('src', function(v) { 117 | console.log('src attribute changed, new value is', v); 118 | if (v !== undefined && v !== null && v !== '') { 119 | scope.pageNum = 1; 120 | scope.loadPDF(scope.src); 121 | } 122 | }); 123 | } 124 | }; 125 | }]). 126 | service("PDFViewerService", [ '$rootScope', function($rootScope) { 127 | 128 | var svc = { }; 129 | svc.nextPage = function() { 130 | $rootScope.$broadcast('pdfviewer.nextPage'); 131 | }; 132 | 133 | svc.prevPage = function() { 134 | $rootScope.$broadcast('pdfviewer.prevPage'); 135 | }; 136 | 137 | svc.Instance = function(id) { 138 | var instance_id = id; 139 | 140 | return { 141 | prevPage: function() { 142 | $rootScope.$broadcast('pdfviewer.prevPage', instance_id); 143 | }, 144 | nextPage: function() { 145 | $rootScope.$broadcast('pdfviewer.nextPage', instance_id); 146 | }, 147 | gotoPage: function(page) { 148 | $rootScope.$broadcast('pdfviewer.gotoPage', instance_id, page); 149 | } 150 | }; 151 | }; 152 | 153 | return svc; 154 | }]); 155 | --------------------------------------------------------------------------------