jsPDF upgrade from 1.5.3 to 2.5.1 don't work - jspdf

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();
// ...

Related

Why does Fpdi fail to extend TCPDF when using PHP8.1?

I'm using:
TCPDF version 6.4.4.
FPDI version 2.3.6
PHP Version 8.1.7 (Running on Apache and Windows Server 2012,a dev environment)
And, I don't think it's relevant but I'm also using
tcpdf-extension
These were installed with composer:
{
"require": {
"tecnickcom/tcpdf": "6.4.4",
"setasign/fpdi": "^2.0",
"naitsirch/tcpdf-extension": "dev-master"
}
}
I am also using a Java/PHP bridge. This is relevant because it changes the error message, however, I doubt this is the cause of the issue.
The problem I'm having is that Fpdi fails to extend TCPDF.
The error message I get looks like this:
PHP Fatal error: During class fetch: Uncaught Error: Call to a member function invokeBegin()
on null in http://127.0.0.1:8080/JavaBridge/java/Java.inc:557
Stack trace:
#0 http://127.0.0.1:8080/JavaBridge/java/Java.inc(56): java_Client->invokeMethod(0, 'typeExists', Array)
#1 C:\Program Files (x86)\PHP\v8.1\vendor\setasign\fpdi\src\Tcpdf\Fpdi.php(33):
java_autoload_function('setasign\\Fpdi\\F...')
...
#8 {main} in C:\Program Files (x86)\PHP\v8.1\vendor\setasign\fpdi\src\Tcpdf\Fpdi.php on line 33
It is failing to fetch a class and the php/java bridge, as a last ditch effort to load it, is attempting to fetch the missing class with a java autoloader, which it fails to do because it's not a java class. Unfortunately, it doesn't give me the full name of the class that's it is trying to load. But this error occurs in setasign\fpdi\src\Tcpdf\Fpdi.php on line 33. Which reads:
class Fpdi extends \TCPDF
My code that invokes this looks like this:
define("COMPOSER_AUTOLOADER","C:\\Program Files (x86)\\PHP\\v8.1\\vendor\\autoload.php");
require_once(COMPOSER_AUTOLOADER);
use setasign\Fpdi\Tcpdf\Fpdi;
class PDF extends Fpdi {
...//functions related to my use case
}
My code that calls this extended class:
// initiate PDF
$pdf = new PDF($data['orientation'], 'mm', USLETTER, true, 'UTF-8', false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetDisplayMode('real');
$pdf->SetAutoPageBreak(true, 1);
//set margins
$pdf->SetMargins(0,0);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);
...
$pdf->AddPage($data['orientation']);
...
$pdf->Output('newpdf.pdf', 'I');
Also probably relevant, I set up a test that uses only the TCPDF library without Fpdi and it fails to load the constants that are supposed to be set up in TCPDF_static.php. (USLETTER for instance), but if I manually define that constant, it does load the PDF as expected:
require_once("C:\\Program Files (x86)\\PHP\\v8.1\\vendor\\autoload.php");
use setasign\Fpdi\Tcpdf\Fpdi;
define ('USLETTER',array( 612.000, 792.000));
$pdf = new TCPDF('', 'in', USLETTER, true, 'UTF-8', false);
...
$pdf->AddPage();
...
$pdf->Output('newpdf.pdf', 'I');
Another detail: this code was working fine with PHP 5.6 and some older versions of TCPDF (6.2.11) and Fpdi (1.4.2). Upgrading to PHP 8.1.7 required updating these libraries.
Why is TCPDF failing to load its constants and, more importantly, why can't Fpdi extend TCPDF?

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

Unable to use latest version of jsPDF, gives error

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

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.

React Rails Component is not defined

I'm trying to get the react-rails gem (version 2.1) working in my Rails 4.2.4 app. I've gone through the setup steps in the Readme and I'm using webpacker for the js preprocessing. I have a component inside of app/javascript/components/label.js that looks like this:
import React, {PureComponent} from 'react';
import ReactDOM from 'react-dom'
export default class Label extends PureComponent {
render () {
return (
<div>Something rendered in React</div>
)
}
}
And then I reference this in my view with the following line:
= react_component("Label")
As far as I can see from the Readme, this should be all that is necessary in order to render the component (provided the application pack is included in the layout, which it is)
= javascript_pack_tag 'application'
So I'm confused as to why I'm getting the error in my browser that the component is not defined.
Uncaught ReferenceError: Label is not defined
Opening app/javascript/packs/application.js I can see the following:
console.log('Hello World from Webpacker')
// Support component names relative to this directory:
var componentRequireContext = require.context("components", true)
var ReactRailsUJS = require("react_ujs")
ReactRailsUJS.useContext(componentRequireContext)
First I verified that the console log is displayed in the browser (it is). I'm not sure what componentRequireContext does, but if it is relative to the current file, then it seems odd that it points to components and not ../components, but changing this doesn't render the component. However, I can get the component rendering if I add the following line:
window.Label = require('../components/label.js');
I thought the React Rails gem took care of this though, provided the components were saved in the app/javascript/components directory? There's nothing in the Readme that says that I need to explicitly declare and require the component, or am I mistaken?
It looks like you have a capitalization issue. You named the file 'label.js' but you are looking for '= react_component("Label")' So it looks and doesn't find what Label is. Then when you set Label on the window then react is like "Oh ok, Label is actually label.js." and it does stuff. TLDR capitalization matters.

Resources