Unable to use latest version of jsPDF, gives error - jspdf

I am trying to use jsPDF, but when I use the CDN URL given below,
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.2.0/jspdf.umd.min.js"></script>
We get the following error,
Summary:4644 Uncaught ReferenceError: jsPDF is not defined
But when I use the one below which is the older version it works,
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script>
Is the new version only for node?

You should use const doc = new window.jspdf.jsPDF(); in the newer verions.
Instead of const doc = new jsPDF();.
Here is where I found it:
https://github.com/MrRio/jsPDF/issues/2972

Related

jsPDF upgrade from 1.5.3 to 2.5.1 don't work

I use the jsPDF version 1.5.3 (jspfd.min.js downloaded and saved) and it works fine for every years. Yet i have tested the version 2.5.1 (jspfd.min.js downloaded and saved from unpkg). This gives the error: Uncaught ReferenceError: jsPDF is not defined. This is not possible because the variable/function is definitely present. With version 1.5.3 this error should otherwise also appear, but this is not the case. When (with 2.5.1) i call in the Firefox console the variable jsPDF it changes automatically to jspdf and display an object. Call really jsPDF it ist the error. When i change the name in my script from new jsPDF to new jspdf it gives the error: Uncaught TypeError: jspdf is not a constructor. What is the problem?
Apparently there are some breaking changes in version 2.0.0.
We also changed the name of the global variable to jspdf (lower case)
when using script tags to be consistent with the new es modules format
and named imports/exports.
Adding the following line should work for backward compatibility:
window.jsPDF = window.jspdf.jsPDF
You need to import the module as follows:
import { jsPDF } from "jspdf";
For other module formats, take a look at the repo doc directly: https://github.com/parallax/jsPDF, ex.:
// Node.js
const { jsPDF } = require("jspdf");
// Globals
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// ...

Roomle SDK in Rails 6, using webpacker, throws errors

Using instructions on roomle github page how to setup web SDK I'm getting JS errors in console and cofigurator is not rendered inside canvas.
Init script:
window.__RML__ENV__ = {
assetPath: '/roomle_assets/'
};
import RoomleSdk from '#roomle/web-sdk';
document.addEventListener('turbolinks:load', async function () {
const scene = document.getElementById("scene");
const roomleConfigurator = await RoomleSdk.getConfigurator();
roomleConfigurator.boot();
await roomleConfigurator.getApi().init(scene);
await roomleConfigurator.getApi().loadConfigurableItemById('item:id');
});
Assets are loaded and placed correctly. First error is shown on roomleConfigurator.boot() and for other I'm not sure.
Webpack compiles all files correctly and this is only code that is included alongside required packages from Rails itself.
When using example from documentation https://docs.roomle.com/web/guides/tutorial/glbviewer/ for GLB viewer implementation only second error is shown. Uncaught TypeError: can't convert undefined to object animateCamera pixotron-539caf55.js:502 ...
Errors are rather long so here is the link with .txt and corresponding screenshots with specific lines that errors refer to. https://drive.google.com/file/d/1E75ox8dWfxoo8wBoe-UlMUgIorUIqM1Z/view?usp=sharing
I'm uising #roomle/web-sdk version version 2.5.0

Webpacker load error (Uncaught TypeError: $(...).metisMenu is not a function)

Trying to get a (what should be) simple module to work: metisMenu
However, unfortunately I'm failing in doing so, apparently something in my Webpacker setup because when loading my page I get the error: Uncaught TypeError: $(...).metisMenu is not a function
There is an issue in loading the module in application.js. The module is being loaded in vendor/assets/javascripts/app.js
I have jQuery correctly installed
the following snippet into the head section makes it work (but this is without the use of Webpaker):
<script src="https://cdn.jsdelivr.net/npm/jquery"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/metismenu"></script>
.
I've created a github branch. Please help! https://github.com/henkjanwils/metisMenu-error

jsPDF "Object expected" Exception in IE when trying to save the PDF

When trying to save the PDF file, the following stack trace occurs and the file is not downloaded:
TypeError: Object expected
at API.save (http://localhost:8080/applications/lib/jspdf/jspdf.debug.js:3648:11)
at Anonymous function (http://localhost:8080/applications/js/<my_custom_js_file>.js:288:12)
at Anonymous function (http://localhost:8080/applications/lib/angular-1.5.8/angular.min.js:158:482)
at e (http://localhost:8080/applications/lib/angular-1.5.8/angular.min.js:45:442)
at Anonymous function (http://localhost:8080/applications/lib/angular-1.5.8/angular.min.js:48:300)
Also tried with a simple example and had the same results:
var doc = new jsPDF();
doc.text("hello", 20, 20);
doc.save("table.pdf");
IE does not support native Promise. Therefore, the initialization script fails at line 12016 of Version 1.5.3:
SCRIPT5009: 'Promise' is undefined
jspdf.debug.js (12016,5)
Afterwards, the script is no longer initializing the required context.
A fix should be a 3rd party promise library - I have solved it by including the following resources before including jspdf.debug.js:
<script type="text/javascript" src="/applications/lib/ie-promise/es6-promise.js"></script>
<script type="text/javascript" src="/applications/lib/ie-promise/es6-promise#4/dist/es6-promise.auto.js"></script>

TypeError: this.internal.getCurrentPageInfo is not a function in jspdf

When i try to convert html table to pdf using jspdf then get this error:
TypeError: this.internal.getCurrentPageInfo is not a function
Same code is used here https://codepen.io/someatoms/pen/adojWy
I took reference from https://github.com/simonbengtsson/jsPDF-AutoTable/blob/master/examples/examples.js#L142
The codepen example was using an old version of jspdf. Fixed the codepen example now by updating to the latest version.

Resources