What does pdfmake return on successful generation of pdf or on failure? - pdfmake

I am using pdfmake to generate pdf documents. pdfMake.createPdf() method returns undefined. How to find out if createPdf() completed successfully or if it failed?
One way is to check if the file exists in the location it is supposed to be created in. Is there a smarter way?
Thanks,
Harsha

If it's not too late...
I'm using PDFMake in angular 4 and using pdfMake.createPdf(docDefinition) is returning an object which you can use to download/open/print you'r pdf.
pdfMake.createPdf(docDefinition).download();
pdfMake.createPdf(docDefinition).open();
pdfMake.createPdf(docDefinition).print();
you can use this code to know when it's done:
pdfMake.createPdf(dd).download('file.pdf', () => {
console.log("success");
});

Related

Is it possible to use ActiveStorage without a file input?

I haven't seen any documentation on the matter, but to elaborate:
I want to use active storage to upload files in my rails app without having to use a browser's file input element. Whether it be using Drag/Drop, or various custom file pickers, it'd be nice to tell ActiveStorage to upload a file and save it without having to use a file input element.
Also: afaik, it's not allowed to hide a file input and to set it's file contents (as sort of a work around).
Is this possible? Does anyone have an example of how this is done without a file input element?
You can use the DirectUpload class for this purpose. Upon receiving a file from your library of choice, instantiate a DirectUpload and call its create method. create takes a callback to invoke when the upload completes:
import { DirectUpload } from "activestorage"
// on file selection/drop {
const url = element.dataset.directUploadUrl
const upload = new DirectUpload(file, url)
upload.create((error, blob) => {
if (error) {
// Handle the error
} else {
// Add an appropriately-named hidden input to the form with a value of blob.signed_id
}
})
// }
This class is the rare exception to the rule that undocumented Rails APIs are internal. We just haven’t gotten around to documenting it yet.

Dynamic Data To Google Sheet

I'm trying to pull dynamic data (form) to a google sheet.
I can't seem to find the right function.
I'm running this:
function name(){
return $('input[type="text"]').val();
}
I tried this:
function fullname(){
return $('#form-field-1-1').val();
}
No success for now.
I've attached the elements below.
Thank you [https://i.stack.imgur.com/Tt5Gk.png]
Your best choise is to use a Variable "DOM element" and capture it by ID. but if you prefer a custom JS this will do:
function(){
return document.getElementById('form-field-1-1').innerHTML;
}
Hope it helps.

Updating panel contents in a Firefox extension

I'm trying to go by the suggestion in https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/panel of using a contentScript to update the contents in my panel. Currently, I have a server that returns the html that I want to display in my panel. I do panel.postMessage("update_panel", contents); when I have the response ready, and have a contentScriptFile associated with the panel that contains
self.port.on("update_panel", handleMessage);
function handleMessage(message) {
document.write(message);
}
However, I don't see anything being updated, and I'm also unable to debug the contentScriptFile (is there an way to do so?).
What am I doing wrong?
I ended up figuring something out.
panel.port.on("updating_done", function(response) {
console.log(response);
});
panel.port.emit("update_panel", contents);
If anyone can explain why this works and postMessage doesn't, that would be great.

Webix: how to dynamically load components from external js file into a layout?

I would like to know how to update a row/col and or layout from an external js file on webix. Let's say I have a menu at the left of the screen (col[]) and want to update the right column based on a menu selection. If the menu is composed by
Customers
Orders
Products
And want to update the right column based on the selection calling customers.js, orders.js and products.js
Just like http://webix.com/demos/admin-app/#!/app/orders
That example is very advanced for me, I would like to learn some basic method.
Thanks
Oscar P
You can use webix.ui command or addView API to add a new UI to some specific place on the page.
webix.ajax("config.json", function(text){
$$("layout").addView( JSON.parse(text) );
})
or
webix.ajax("config.json", function(text){
webix.ui( JSON.parse(text), $$("cell_to_replace"));
})
Aquatic,
I also found out an example with .showBatch() API but the console shows "Uncaught TypeError: $$(...).addView is not a function" on both functions, are those part of PRO version? what is wrong?
My code is:
$$("workArea").addView("clientes");
or
$$("workArea").showBatch("batClientes");
on:{
onMenuItemClick:function(id) {
$$("workArea").addView(id);
}
}

HTMLDocument object from HTTP read()

I need to call at server side, an URL and work with the HTML content off the response. For this I'm using the HTTP library from Dart like this :
http.read('myUrl').then((contents) {
//contents to HTMLDocument format //Need to transform the String contents to HTML object
});
And I want to convert the response to a HTMLDocument (or other object I don't know) to be able to retrieve element in it by HTML tag or CSS class, like with JQuery for example.
Does anybody have an idea to perform this ?
You canuse html5lib package from pub. It allows to parse HTML and present it DOM like element tree on server side. The element tree will eventually "be compatible with dart:html, so the same code will work on the client and the server" in the future. See the readme for a getting started example.
"I need to call at server side"
Not sure exactly what you mean.
If you are running in the browser and calling the server you could try using a DocumentFragment. Something like this:
http.read(url).then((html) {
var fragment = new DocumentFragment(html);
var element = fragment.query('.foo');
// code here...
});
Otherwise if you're running server side, as the other answer mentions, html5lib is the way to go. Last time I looked the query() method in html5lib only supported tagname queries not classes, or ids.

Resources