Code Monkey home page Code Monkey logo

ember-pdfjs's Introduction

Ember PDFJS Addon

Latest NPM release Downloads per month Total downloads Dependencies Dev Dependencies Issues Issues Ember Observer Score

This addon will provide some useful components for viewing and interacting with PDF documents to your ember-cli project. This addon unites the Ember framework ecosystem and the PDFJS open source project by Mozilla.

Installation

Within your ember-cli project:

  • ember install ember-pdfjs

This will add a pdf-document component to your application.

Standalone Sample

Though this project is an addon type for including a component in your Ember project, you can also kick the tires on the component in a live sample with this project.

git clone [email protected]:mysterlune/ember-pdfjs.git
cd ember-pdfjs && npm install && bower install
ember serve

... and in typical Ember fashion, a development server will fire up on port 4200. Then, simply visit:

http://localhost:4200

... and take a look at the familar, lovely "tracemonkey" document.

Usage

In a template, just do:

{{pdf-document src=[model.src]}}

or

{{pdf-document src="/path/to/your.pdf"}}

[model.src] can be a Uint8Array, as PDFJS allows this as a source type for the ...getDocument() signature.

Password Protected PDF Support

The addon also allows for the registration of an Ember action handler for use when a PDF is password protected. In a template you would add an action closure:

{{pdf-document src=[model.src] onPassword=(action 'myPasswordAction')}}

The associated action handler would look something like the following:

import { PasswordResponses } from 'ember-pdfjs/components/pdf-document';

export default Ember.Controller.extend({
    actions: {
        'myPasswordAction': function(setPassword, reason) {
            // The reason value provides an indication of first prompt
            // versus incorrect password prompt
            let promptText = 'Enter the password to open this PDF file.';
            if (reason === PasswordResponses.INCORRECT_PASSWORD) {
                promptText = 'Invalid password. Please try again.';
            }

            // Prompt the user for their password in some application-specific way
            let password = promptUserForPassword(promptText);

            // Callback with the password received from the prompt
            setPassword(password);
        }
    }
});

The action receives two parameters:

  • setPassword - A callback function that is used to set the password received from the user
  • reason - The "reason" that the password is being requested. One of:
    • PasswordResponses.NEED_PASSWORD (First time prompt)
    • PasswordResponses.INCORRECT_PASSWORD (Re-prompt when previous password was incorrect)

Note on Security

You will get errors and it will not load if you try to link to something not hosted on your domain. You will need to update contentSecurityPolicy in your Ember project accordingly.

Checkout Ember Igniter for a how-to on updating contentSecurityPolicy for your app.

Caveats

The goals of this project are spelled out in Issues. If there are recommendations that you need for own project, likely they will benefit others.

Running Tests

  • ember test

Contributing

If you have an "ember-ish"/"pdf.js-ish" addon project in the works -- or don't think this project will work for your needs -- please let's try to pull this together into one solution.

The Ember Community maintains a fundamental precept of common solutions to common problems. Proliferating addon solutions is kinda bunk, from a community perspective.

Please contribute!

We confessed that we're not the only ones trying to climb the same mountain.

-- DHH, on the character of the Rails Community

ember-pdfjs's People

Contributors

ember-tomster avatar jameschao avatar mysterlune avatar phillipweston avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ember-pdfjs's Issues

Invalid attempt to destructure non-iterable instance

TypeError: Invalid attempt to destructure non-iterable instance in IE11

I'm not sure if the square brackets are even necessary, but I get the error with or without them, and both work in Chrome.
{{pdf-document src=[resource.mediaPath]}}

image

Slow build times

Default install gives the following on ember serve:

[BABEL] Note: The code generator has deoptimised the styling of "highlight/pdf.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "highlight/pdf.worker.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "highlight/templates/pdf.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "highlight/templates/pdf.worker.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "highlight/tests/pdf.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "highlight/tests/pdf.worker.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "pdf.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "pdf.worker.js" as it exceeds the max of "100KB".

Processing these files slowed the build time from ~4s to ~50s.

Adding the following to ember-cli-build.js in my app ignored the pdfjs files and restored fast builds (~5s now):

    babel: {
      ignore: ['pdf.js', 'pdf.worker.js']
    }

Perhaps it makes sense to add this to the addon itself?

Goals

What does this do, or what will it do? Is this project still alive?

Cannot read property 'workerSrc' of undefined

I tried to include this add-on in an our existing ember-cli build. Am getting an error Cannot read property 'workerSrc' of undefined. Can you please let me know, anything I have to include to make it run properly ?

The version which I have used is 0.4.11

screen shot 2017-06-06 at 8 34 07 pm

screen shot 2017-06-06 at 8 34 22 pm

TypeError: pdfjsLib is undefined

Ember version : 2.5.1

I have installed ember-pdfjs in my project. After installing I was not able to start project, as it says

"broccoli-merge-trees", "broccoli-static-compiler" is missing.

I installed both and after starting my route was not loading. In console I got the error

'TypeError: pdfjsLib is undefined'

Please provide a solution for the same. Anyone else got this error?

Update

Issue is in

bower_components/pdfjs-dist/web/pdf_viewer.js

BroccoliMergeTrees failure when using Ember CLI >= 2.13.x

We have been working on an upgrade to our app to use a more recent version of the Ember. I tried to use the most current release (2.14.2), and I get the following error when building with ember-pdfjs:

`โ ‹ Building[BABEL] Note: The code generator has deoptimised the styling of "test-app/pdf.worker.js" as it exceeds the max of "500KB".
cleaning up...
Build failed.
The Broccoli Plugin: [BroccoliMergeTrees: TreeMerger (appAndDependencies)] failed with:
TypeError: test-app/pdf.js: Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got null
at Object.validate (/Users/timothy/temp/scratch/test-app/node_modules/babel-types/lib/definitions/index.js:109:13)
at Object.validate (/Users/timothy/temp/scratch/test-app/node_modules/babel-types/lib/index.js:505:9)
at NodePath._replaceWith (/Users/timothy/temp/scratch/test-app/node_modules/babel-traverse/lib/path/replacement.js:176:7)
at NodePath._remove (/Users/timothy/temp/scratch/test-app/node_modules/babel-traverse/lib/path/removal.js:58:10)
at NodePath.remove (/Users/timothy/temp/scratch/test-app/node_modules/babel-traverse/lib/path/removal.js:30:8)
at PluginPass.CallExpression (/Users/timothy/temp/scratch/test-app/node_modules/babel-plugin-transform-es2015-modules-amd/lib/index.js:42:12)
at NodePath._call (/Users/timothy/temp/scratch/test-app/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/Users/timothy/temp/scratch/test-app/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (/Users/timothy/temp/scratch/test-app/node_modules/babel-traverse/lib/path/context.js:105:12)
at TraversalContext.visitQueue (/Users/timothy/temp/scratch/test-app/node_modules/babel-traverse/lib/context.js:150:16)

The broccoli plugin was instantiated at:
at BroccoliMergeTrees.Plugin (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/node_modules/broccoli-plugin/index.js:7:31)
at new BroccoliMergeTrees (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/node_modules/broccoli-merge-trees/index.js:16:10)
at Function.BroccoliMergeTrees [as _upstreamMergeTrees] (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/node_modules/broccoli-merge-trees/index.js:10:53)
at mergeTrees (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/lib/broccoli/merge-trees.js:85:33)
at EmberApp._mergeTrees (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/lib/broccoli/ember-app.js:1817:12)
at EmberApp.appAndDependencies (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/lib/broccoli/ember-app.js:1137:17)
at EmberApp.javascript (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/lib/broccoli/ember-app.js:1237:30)
at EmberApp.toArray (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/lib/broccoli/ember-app.js:1674:12)
at EmberApp.toTree (/Users/timothy/temp/scratch/test-app/node_modules/ember-cli/lib/broccoli/ember-app.js:1696:38)
at module.exports (/Users/timothy/temp/scratch/test-app/ember-cli-build.js:22:14)`

In order to isolate/verify the issue, I began systematically trying ember versions from our current (2.10.2) up to 2.14.2. My methodology was:

  1. Remove old Ember CLI, clear node/bower cache, and install new Ember CLI
  2. Create a new ember app (i.e. > ember new test-app)
  3. Install the ember-pdfjs addon (i.e. > ember install ember-pdfjs)
  4. Build the app (i.e. > ember build)

When I do the above, the build succeeds for Ember v2.12.x and earlier. It fails when the Ember version if 2.13.x or later, with the error above. Please note that this is easy to recreate (as noted above) by just creating a new app, installing the addon, and building using 2.13.x or above.

For thoroughness, here is information about my Ember environment (via > ember -v):
ember-cli: 2.13.3 node: 6.9.4 os: darwin x64

Thanks in advance for any help/thoughts you might have

Installation error "Cannot find module 'broccoli-static-compiler'"

I got the following error while running ember install ember-pdfjs and ember serve.

Installed packages for tooling via npm.
Cannot find module 'broccoli-static-compiler'
Error: Cannot find module 'broccoli-static-compiler'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/guysungkim/Documents/emberJS-Projects/bbook/node_modules/ember-pdfjs/index.js:3:17)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

Any suggestion would be appreciated.
Thanks !

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.