Giter Site home page Giter Site logo

rajeshodayanchal / angularjs-pdf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sayanee/angularjs-pdf

0.0 1.0 0.0 4.22 MB

An AngularJS directive <ng-pdf> to display PDF files with PDFJS

Home Page: http://sayan.ee/angularjs-pdf/

License: MIT License

JavaScript 0.23% HTML 0.09% Java 99.64% CSS 0.04%

angularjs-pdf's Introduction

angular-pdf Build Status Dependency Status

Version: 0.3.9

An AngularJS directive ng-pdf to display PDF files with PDFJS.

Overview [demo]

Integrate PDF files right into web pages.

Angular PDF

##Requirements

Check bower.json file for dependencies and their versions:

  1. AngularJS - get the latest angular.min.js

###Features

  1. next / previous page
  • zoom in / out
  • rotate clockwise
  • jump to a page number
  • when scrolling, the pdf controls will get fixed position at the top
  • define the view template
  • define the path to pdf with scope variable
  • handles error
  • show loading of pdf
  • show progress percentage of loading pdf

Getting Started

  1. install or copy over the file dist/angular-pdf.min.js or dist/angular-pdf.js

    bower install angular-pdf
  2. include the path to the direcitve file in index.html

    <script src="js/vendor/angular-pdf/dist/angular-pdf.js"></script>
  3. include the directive as a dependency when defining the angular app:

    var app = angular.module('App', ['pdf']);
  4. include the directive with the attribute path to the partial under a controller

    <div class="wrapper" ng-controller="DocCtrl">
        <ng-pdf template-url="/partials/viewer.html"></ng-pdf>
    </div>
  5. include the canvas element to display the pdf in the template-url file

    <canvas id="pdf-canvas"></canvas>
  6. include the path to the pdf file in the controller

    app.controller('DocCtrl', function($scope) {
        $scope.pdfUrl = '/pdf/relativity.pdf';
    });

###Options

  1. Next / Previous page: Include the controls in the view file as defined in the attribute template-url

    <button ng-click="goPrevious()"><</span></button>
    <button ng-click="goNext()">></span></button>
    
  2. Zoom in / out: Include the controls in the view file as defined in the attribute template-url

    <button ng-click="zoomIn()">+</span></button>
    <button ng-click="zoomOut()">-</span></button>
    
  3. Rotate clockwise: Include the controls in the view file as defined in the attribute template-url and the initial class rotate0

    <button ng-click="rotate()">90</span></button>
    ...
    <canvas id="pdf-canvas" class="rotate0"></canvas>

    include the css styles:

    .rotate0 {-webkit-transform: rotate(0deg); transform: rotate(0deg); }
    .rotate90 {-webkit-transform: rotate(90deg); transform: rotate(90deg); }
    .rotate180 {-webkit-transform: rotate(180deg); transform: rotate(180deg); }
    .rotate270 {-webkit-transform: rotate(270deg); transform: rotate(270deg); }
  4. Jump to page number: Include the controls in the view file as defined in the attribute template-url

    <span>Page: </span><input type="text" min=1 ng-model="pageNum"><span> / {{pageCount}}</span>
  5. Fixed pdf controls upon scrolling: Wrap the controls in the view file as defined in the attribute template-url with a tag nav with an ng-class. Amend the scroll amount as required.

    <nav ng-class="{'pdf-controls fixed': scroll > 100, 'pdf-controls': scroll <= 100}">
    ...
    </nav>

    And include the relevant css styles as required:

    .pdf-controls { width: 100%; display: block; background: #eee; padding: 1em;}
    .fixed { position: fixed; top: 0; left: calc(50% - 480px); z-index: 100; width: 100%; padding: 1em; background: rgba(238, 238, 238,.9); width: 960px; }
  6. open the file index.html with a web server

###Handle error

  1. in the controller, you can call the function $scope.onError:

    $scope.onError = function(error) {
    	// handle the error
    	// console.log(error);
    }

###Show loading

  1. in the controller, you can call the function $scope.onLoad when the pdf succesfully loaded:

    $scope.loading = 'loading';
    
    $scope.onLoad = function() {
    // do something when pdf is fully loaded
    // $scope.loading = '';

}


###Show progress percentage

1. in the controller, you can call the function `$scope.onProgress`

  ```js
  $scope.onProgress = function(progress) {
  	// handle a progress bar
  	// progress% = progress.loaded / progress.total 
  	// console.log(progress);
}

##Variations

  1. If using with Angular UI modal, pageNum attribute is no longer required. Checkout the implementation

##Similar projects

  1. angular-pdf-viewer - a more self-contained directive

##Credit

PDF example used is Relativity: The Special and General Theory by Albert Einstein as kindly organized and made available free by Project Gutenberg.

#Contribute

Please see CONTRIBUTING.md for details.

#Versioning

This repository follows the Semantic Versioning guidelines:

  1. For patches, run the command:

    grunt bump
    
  • For minor release, run the command:

     grunt bump:minor
    
  • For major release, run the command:

     grunt bump:major
    

License

(C) Sayanee Basu 2014, released under an MIT license

angularjs-pdf's People

Contributors

dokenzy avatar drag0ndust avatar maciekrb avatar patrickkettner avatar sayanee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.