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

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?

Related

Dart plugin dynamic linking

I am having trouble utilising the libserialport.dart package. I have put a libserialport.so in the root of the project. When trying to run an application I get the following error:
Unhandled exception: Invalid argument(s): Failed to load dynamic library 'libserialport.so': libserialport.so: cannot open shared object file: No such file or directory
This tells me that the package is looking for the file somwhere else - but where?
The original library links the library this way, which results in it not finding the library:
LibSerialPort? _dylib;
LibSerialPort get dylib {
return _dylib ??= LibSerialPort(ffi.DynamicLibrary.open(
resolveDylibPath(
'serialport',
dartDefine: 'LIBSERIALPORT_PATH',
environmentVariable: 'LIBSERIALPORT_PATH',
),
));
}
If I replicate the plugin locally, but changing the linking as such, the library works as expected:
var libraryPath =
path.join(Directory.current.path, 'libserialport.so');
LibSerialPort? _dylib;
LibSerialPort get dylib {
return _dylib ??= LibSerialPort(ffi.DynamicLibrary.open(libraryPath));
}
The question is: where to put the .so file so it would work with the original verison? Where does resolveDylibPath() link to?
If possible I would like to avoid using my modified version as that brings license implications I am not entirely sure how to deal with.
Apparently the function looks for the path in the LIBSERIALPORT_PATH enviroment variable. Setting it to '.' made it work!
In the terminal:
export LIBSERIALPORT_PATH=.

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

Import my own files into the electron renderer process

This seems really dumb, but I need help for importing some source code into the renderer process in electron:
I have an electron app:
index.html (loads window.js with a tag)
- index.js
- window.js
- useful_functions.js
In window.js, I want to import some functions from useful_functions.js, so I've tried the following:
// fails with: Uncaught SyntaxError: Unexpected identifier
import { very_useful } from './useful_functions.js';
// fails with: Uncaught ReferenceError: require is not defined
const { very_useful } = require('./useful_functions.js');
// fails with: Uncaught ReferenceError: require is not defined
require('electron').remote.require('./useful_functions.js')
I also tried the nodeIntegration flag, but that didn't help either
Note: I'm not trying to import npm modules but my own code, in an other file right next to it.
I'm looking for examples, but I only find super small samples with just the basic files. (Or huge apps like atom that would take me a while to figure out)
I don't have webpack setup for this project yet, but I'm sure there is a simpler way to do this very basic task...
Thanks for any help.
In index.html, use require() instead of loading window.js with a tag, i.e., replace:
<script src="window.js"></script>
with:
<script>require('./window.js');</script>
Then, in window.js, the following statement should work too:
const { very_useful } = require('./useful_functions.js');
Note that nodeIntegration: true is needed in the options passed to new BrowserWindow() anyway:
webPreferences:
{
nodeIntegration: true
}
See:
Node Modules
Functions and objects are added to the root of a module by
specifying additional properties on the special exports object.
Variables local to the module will be private, because the module is
wrapped in a function by Node.js (see module wrapper).
Module Wrapper
Before a module's code is executed, Node.js will wrap it with a
function wrapper that looks like the following:
(function(exports, require, module, __filename, __dirname) {
// Module code actually lives in here
});

How to make code in a Firefox Extension execute on a timer

Today is my first day working with firefox extensions.
Basically I am making an extension that will be used on an internal network to check a web server for new notifications.
I used the wizard on the mozilla page to make a skeleton extension and then mainly edited overlay.js with some ajax code.
I am using the "load" event listener to call a setTimeout to my ajax call which then loops with setTimeouts.
The problem appears to be that the "load" event listener is executed on each new browser window. I just want one global timer for this to work off of.
Any ideas?
Update:
I found this: https://developer.mozilla.org/en/JavaScript_code_modules/Using
which seems like what i would want. The problem is I can't figure out how to import the jsm file. What is the directory structure?
Update:
When trying this:
chrome.manifest
content spt chrome/content/
skin spt classic/1.0 chrome/skin/
locale spt en-US chrome/locale/en-US/
overlay chrome://browser/content/browser.xul chrome://spt/content/ff-overlay.xul
style chrome://global/content/customizeToolbar.xul chrome://spt/skin/overlay.css
resource mycontent chrome/content/
First 5 lines of chrome/content/overlay.js
try{
Components.utils.import("resource://spt/mycontent/ajax.jsm");
}catch(err){
alert(err);
}
I get this error:
[Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXPCComponents_Utils.import]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: chrome://spt/content/overlay.js :: :: line 2" data: no]
Or when if I remove the resource alias from chrome.manifest and use this at the beginning of overlay.js
try{
Components.utils.import("chrome://spt/content/ajax.jsm");
}catch(err){
alert(err);
}
I get this error:
[Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXPCComponents_Utils.import]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: chrome://spt/content/overlay.js :: :: line 3" data: no]
Yes, if you have code that should be shared between windows (and should not be executed when a new window is loaded) and that don't need access to the chrome, use JavaScript code modules.
You can import your modules with:
Components.utils.import("resource://youraddon/your_module.jsm");
provided that you setup resource in your chrome.manifest. E.g. if you add
resource youraddon modules/
then you the file must be stored in /path/to/your/addon/modules/your_module.jsm.
Further notes:
Code modules don't have to have the file extensions .jsm. You can leave it .js. Works better sometimes with certain editors (and syntax highlighting etc).
Afaik you cannot use setTimeout in a module as it has no access to the window object. I suggest to use nsITimer.

Resources