Meteor - importing jsPDF without atmosphere

774 views Asked by At

In the beginning I wanted the option of being able to add different fonts into the generated pdf file. The answer for that was found here in StackOverFlow, however, if I had added jsPDF through atmosphere using the cli command "meteor add jsPDF:core" I could not edit the files as they would be regenerated and therefore written over (jspdf.js file somewhere stashed in meteors file structures).

Therefore, I tried to import jsPDF the normal way

<script type="text/javascript" src="jsPDF/jspdf.js"></script>
<script type="text/javascript" src="jsPDF/jspdf.plugin.standard_fonts_metrics.js"></script> 
<script type="text/javascript" src="jsPDF/jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="jsPDF/jspdf.plugin.from_html.js"></script>

(jQuery is already included with meteor).

I then try to run my code

doc.save('hello.pdf');

and get

Uncaught ReferenceError: saveAs is not defined"

from jspdf.js

This error did not occur when I had installed jsPDF through meteor (reason I want it manually is to edit the jsPDF files).

1

There are 1 answers

3
piscator On

Importing packages with jQuery is not the preferred way in Meteor. Instead you could follow these steps.

Create a directory packages in your project.

Clone the library in /packages

git clone https://github.com/michaelbishop/meteor-jsPDF.git
mv meteor-jsPDF jspdf

Then you can add this package manually to your project and edit the files you want:

meteor add jspdf

Stackoverflow discussion about adding packages manually: How to install atmosphere packages without meteorite?