Giter Site home page Giter Site logo

jdryg / angular-pdf-viewer Goto Github PK

View Code? Open in Web Editor NEW
22.0 9.0 10.0 1.36 MB

Just another Angular directive for displaying PDF files using PDF.js

Home Page: http://jdryg.github.io/angular-pdf-viewer

License: Do What The F*ck You Want To Public License

JavaScript 0.25% HTML 0.26% CSS 0.11% Java 99.37%
angular pdf-viewer pdfjs directive

angular-pdf-viewer's Introduction

angular-pdf-viewer

Just another Angular directive for displaying PDF files using PDF.js

Live demo

If you want to try out different PDFs, check TCPDF examples

Features

  • Continuous view
  • All pages are inserted into the DOM when the PDF is loaded.
  • Lazy page rendering
  • A page is actually rendered only when it enters the viewport for the first time.
  • As of v1.1.2 pages far away from the current viewport are removed, to minimize memory usage.
  • Text layer (optional)
  • Annotation layer
  • Requires the text layer to be present.
  • Currently supports only link annotations correctly.
  • Text annotations should appear in the document (PDF.js handles them) but their styling and required images are missing.
  • Zoom to
  • Value
  • Fit the width of the widest page
  • Fit the height of 1st page
  • Jump to page
  • Password protected PDFs
  • You should specify a callback (password-callback) to the directive, which will be called every time a password protected PDF is encountered. It's up to you to decide if you are going to show a prompt dialog, or handle it transparently from the user.
  • Searching (with highlighting)
  • Requires the text layer to be present

Directive attributes

  • src: (input) URL to the PDF file
  • file: (input) File object obtained from an input field. See demo for details.
  • current-page: (output) The current page index (in case you want to show the number somewhere in your UI)
  • initial-scale: (input) The initial zoom level of the document. Either "fit_width", "fit_height" or a floating point value.
  • progress-callback: (input) A function which will be called everytime something changes (e.g. download progress, page rendering progress or errors from those operations).
  • password-callback: (input) A function which will be called when trying to open a password protected PDF. Should return the correct password or null in case you don't have a password.
  • render-text-layer: (input) Boolean indicating whether you want to generate the text layer for each page.
  • search-term: (input) Text to search inside the PDF
  • search-result-id: (output) The currently selected search result index.
  • search-num-occurences: (output) The number of occurences of the currently specified search term.
  • api: (output) An object with several functions you can use to communicate with the directive.

Note that you can specify only one of the 'src' and 'file' attributes. In case you want to use both, you have to make sure you null out the other one, because the update order is not guaranteed.

Search functionality requires the text layer to be present.

See partials/demo.html for details on the directive syntax and js/controllers.js for details on how to use the directive API and the progress callback.

API

TODO

  • getNextZoomInScale(scale)
  • getNextZoomOutScale(scale)
  • zoomTo(scale)
  • getZoomLevel()
  • goToPage(pageIndex)
  • goToNextPage()
  • goToPrevPage()
  • getNumPages()
  • findNext()
  • findPrev()

Styling

TODO

Dependencies

  • Angular.js
  • PDF.js (including pdf.worker.js, text_layer_builder.js, annotations_layer_builder.js and ui_utils.js from PDF.js web folder)

License

angular-pdf-viewer.js is copyright © 2015 jdryg

The rest of the code (PDF.js, Angular.js, etc.) isn't covered by this license! If you don't agree with their licenses, I guess you shouldn't use this code. But I'm not a lawyer, so don't take my word on that :)

angular-pdf-viewer.js is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the COPYING file for more details.

WTFPL

If you happen to build something cool with it, I'll be glad to hear about it.

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.