How do I get jsPDF "loaded" so I can use it if I cannot use import? - jspdf

I am unable to use an import statement to bring in jsPDF in my use case - making a custom component within a Low Code platform (Retool).
import { jsPDF } from "jspdf"; gets this error: Cannot use import statement outside a module
But I also cannot just go straight to var pdf = new jsPDF('p', 'pt', 'a4'); as I get a jsPDF is not a constructor error. And yes, I have tried jspdf and other case versions
I have tried the umd, es and node versions but there is no longer a self-referencing version apparently.
So how do I get jsPDF "loaded" so I can use it if I cannot use import?

This syntax worked:
var { jsPDF } = window.jspdf;
var pdf = new jsPDF();

Related

DevExtreme's DataGrid exportToPDF displays gibberish when used on a table with Russian values in it

When I try to export to PDF DataGrid with Russian values in it, it displays gibberish in this new PDF file even though I managed to set a proper font (PTSans) for jsPDF and when you print just random text it is working fineā€¦
So is there a way to configure table to PDF to display proper Russian?
Actually I suddenly found a solution :D
If anyone will ever have this problem again, this is how you solve it:
const doc = new jsPDF();
const font = "../../../assets/fonts/PTSans-Regular.ttf" // path to .ttf file
doc.addFont(font, "PTSans-Regular", "normal");
exportDataGridToPdf({
jsPDFDocument: doc,
component: grid,
autoTableOptions: {
styles: {
font: 'PTSans-Regular' // this is a part I forgot about before
}
}
}).then(() => {
doc.save(filename);
})
Basically you need to set up font for your language in jsPdf as well as set up the same in styles for jsPDF-autoTable options.
Huge thanks to Alisher from DevExpress Support whose answer helped me to figure it out.

No pdf generated

i use jsPDF and plugin jsPDF-AutoTable
I have a html table i want to print
$('#printFreeRoom').on('click', function (e) {
freeRoomAvailableReport($("#freeRoomTableResult"));
});
function freeRoomAvailableReport(tableId) {
var doc = new jsPDF('p', 'pt');
doc.text("From HTML", 40, 50);
var res = doc.autoTableHtmlToJson(tableId);
doc.autoTable(res.columns, res.data, {
startY: 60
});
doc.output('dataurlnewwindow');
doc.save('test.pdf');
}
nothing is generated when i click on the button.
I created a example on jsfiddle
http://jsfiddle.net/8da5e1fj/
seem like a chrome problem...
tried other example: http://jsfiddle.net/8tLt9yof/10/ and get same result.
You need to add FileSaver.js to use doc.save() also, Chrome has issues with doc.output('dataurlnewwindow')
Hence, here is a working fiddle for doc.save fiddle
And, to open the PDF in new window try this -
var blob = doc.output("blob");
window.open(URL.createObjectURL(blob));
Just an additional "Enter" on the browser address bar will show the PDF in chrome.
UPDATE
Longer URL's are not supported by Chrome as per this. Canvas in the fiddle is generating base64 URL which Chrome fails to load.

dart - "There is no such getter 'function' in" issues

I'm starting learning dart, I've installed the Dart Editor normally on a Linux system, but the problem comes up when I start to code a simple snippet of code for instance this:
import 'dart:html';
void main() {
querySelector('#status').innerHtml = "Hola mundo";
var button = new ButtonElement();
button.text = "Haz click";
button.on.click.add( (e){
var div = new Element.html("<div>puto</div>");
document.body.elements.add(div);
});
document.body.elements.add(button);
}
I get three warnings with the same messages: "There is no such getter 'function' in..." in three different parts of the code:
I got this code in a book, so the code is correct, How do I resolve this problem? thanks
edit: I cannot run this code with these warnings as you could expect.
The book is probably out of date from the current library APIs.
Try changing elements to children, e.g. document.body.children.add(elem2); is an example in the DOM section of Dart: Up and Running.
See the api
https://api.dartlang.org/apidocs/channels/stable/#dart-dom-html.Element#id_onClick
ElementStream<MouseEvent> get onClick
Stream of click events handled by this Element.
This syntax is outdated
// button.on.click.add( (e){
button.onClick.listen(callback);
// or button.on['my-custom-event'].litsen();

How would you auto format hyperlinks using meteor

I am working on a chat room application and would like to auto format hyperlinks so they can be visited without copy/paste.
I found autolink.js and was able to get it to work using a static HTML template but have not been able to get it working with meteor.
Any suggestions?
Edit -
Meteor Version 0.6.1
Chatroom Application - https://github.com/SmashBrando/chatroom
Autolink.js - https://github.com/bryanwoods/autolink-js
(this is not setup as it did not work)
Put this in the helper you want to display the hyperlink. Assuming you've got the autolink.js all set up in your /client/lib folder just use it with your helper
e.g
client js
Template.hello.greeting = function() {
return "This is a link to Google http://google.com".autoLink()
}
and you need to make sure your HTML uses handlebars that can give html output (thats with 3 curly braces either side instead of 2):
html in your template
{{{greeting}}}
This should output
This is a link to Google http://google.com
Using transform to autolink on cursors
When using a handlebars helper that returns a cursor such as Messages.find() in your code you need to transform your collection. So with your code you need to alter the return value:
Template.messages.messages = function () {
return Messages.find({}, { sort: {time: -1}, transform: function(doc) {
if(doc.message) doc.message = doc.message.autoLink()
return doc;
}
});
};
A transform changes the documents in your collection, so in the above each one's message is autoLinked.
You also need to let let handlebars display this as clickable links by altering your handlebars for the HTML to use 3 curly braces to make sure your 's aren't escaped.:
<template name="message">
<p><strong>{{name}}:</strong> {{{message}}}</p>
</template>

Import SWF to FLA

I can show a swf into flash simply with this code
var request:URLRequest = new URLRequest("myswf.swf");
var loader:Loader = new Loader()
loader.load(request);
addChild(loader);
But with import > import to stage there is no any swf when ctrl+enter.
There is only 5-6 empty frame in timeline. How can I solve this problem??
Another question, how can I do this with as 2.0 (im not familiar with as 2.0). This code not working :
loadMovie("myswf.swf");
Thanks in advance
Loader() and addChild() are both AS3, so won't work in AS2.
loadMovie() is a movieClip method, so it needs a movieClip instance to operate on:
myMovieClip.loadMovie("myswf.swf");
To load your swf into the main timeline, try:
this.loadMovie("myswf.swf");

Resources