2

I'm new to Backbonejs so maybe my problem is trivial. I want to generate a pdf with jsPDF in my backbonejs app. I'm using requirejs for scriptloading.

What I did:

  1. I included the jsPDF script via bower and set the path in my main.js:

    [...],
        paths: {
            [...],
            jspdf: '../bower_components/jspdf/jspdf'
        }
    });
    [...]
    

This worked afaik since no error was thrown.

  1. I included jsPDF in my view where I want to use it:

    define([
        'jquery',
        'jqueryui',
        'underscore',
        'backbone',
        'templates',
        'base64',
        'jspdf'
    ], function ($, ui, _, Backbone, JST, Base64, jsPDF ) {
        'use strict';
    [...]
    }
    
  2. I tried to create a new jsPDF with:

    generatePdf: function() {
            var doc = new jsPDF();
    }
    

And here I got the console output 'Uncaught TypeError: undefined is not a function'. What did I do wrong?

Thanks for any help!

Tim

EDIT:

Ok think I solved the problem. Since jsPDF seems to be not AMD-capable, I added

    jspdf: {
        exports: 'jsPDF'
    }

to the shim config and then it worked properly.

1
  • 3
    Please add your edit as an answer and mark it as answered.
    – njtman
    Commented Mar 4, 2014 at 23:57

1 Answer 1

2

Ok think I solved the problem. Since jsPDF seems to be not AMD-capable, I added

jspdf: {
    exports: 'jsPDF'
}

to the shim config and then it worked properly.

1
  • am still looking for AMD version
    – Muhaimin
    Commented Jun 23, 2014 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.