Qlik Community

QlikView Extensions

Discussion Board for collaboration on QlikView Extensions.

Highlighted
msmichael
New Contributor III

why my jsPDF does not work?

Hi experts,

I'm new to QV extensions and JavaScript. I want to create a document extension that uses jsPDF to export some custom charts to pdf. However I'm not able to make it work. I'm using QlikView 11 version.

This is what I did,

create a folder in "C:\Users\usename\AppData\Local\QlikTech\QlikView\Extensions\Document\rrprint"

create a Definition.xml file with contents as below:

<?xml version="1.0" encoding="utf-8"?>
<ExtensionObject Label="rrprint" Path="rrprint" Description="allow share window to export" Type="document">
</ExtensionObject>
 
create a Script.js file with contents as below:
function rrprint_Init() {

Qva.AddDocumentExtension("rrprint",
function () {
var _this = this;
_this.ExtSettings = {};
            _this.ExtSettings.ExtensionName = 'rrprint';
            _this.ExtSettings.LoadUrl = Qva.Remote + (Qva.Remote.indexOf('?') >= 0 ? '&' : '?') + 'public=only' + '&name=';

// Define one or more javascript files to be used within the extension
var jsFiles = [];
jsFiles.push('Extensions/' + _this.ExtSettings.ExtensionName + '/lib/js/jspdf.debug.js');
alert(jsFiles[0]);
Qv.LoadExtensionScripts(jsFiles, function () {
                alert("loaded");
                var d = new jsPDF();

            });
        }
    )
};
    
rrprint_Init();
 
Create sub-folder inside \rrprint folder as .\lib\js\, and put the jspdf.debug.js there.
However, when I run it, I always got error: "jsPDF" is undefined. Is there anything I did incorrectly?
 
Thank you!
Michael
 
 

 

Labels (3)
1 Reply
msmichael
New Contributor III

Re: why my jsPDF does not work?

Another question is, how to import a web hosted library? 

for example, for jsPDF, the lib url is here: "https://unpkg.com/jspdf@latest/dist/jspdf.min.js",

how should I write it in  LoadExtensionScripts function?

I tried below, but does not work,

var jsFiles = [];
 
Qv.LoadExtensionScripts(jsFiles, function () {
                alert("loaded");
                var d = new jsPDF();
                d.text(20, 20, 'Hello landscape world!');
                d.save('Test.pdf');
});
receive this error:
Capture.PNG