I'm having trouble learning anything from the documentation, how am I supposed to know which options exists in for example the .html method? It only says I can add an options object, but doesn't say what those options can be. What am I missing here?
jsPDF.API is a STATIC property of jsPDF class. jsPDF.API is an object you can add methods and properties to. The methods / properties you add will show up in new jsPDF objects. One property is prepopulated. It is the 'events' Object. Plugin authors can add topics, callbacks to this object. These will be reassigned to all new instances of jsPDF.
var doc = new jsPDF(orientation, unit, format, compress); The constructor can take several parameters. orientation - The default value for orientation is "portrait". We can set it to "landscape" if we want a different page orientation. unit - We can tell jsPDF in which units we want to work.
Shouldn't you also be using the jspdf.plugin.from_html.js library? Besides the main library (jspdf.js), you must use other libraries for "special operations" (like jspdf.plugin.addimage.js for using images).
jspdf.js, line 4603 Starts a new pdf form object, which means that all consequent draw calls target a new independent object until endFormObject is called. The created object can be referenced and drawn later using doFormObject. Nested form objects are possible. x, y, width, height set the bounding box that is used to clip the content.
As a possible alternative to find out, you can follow a source link for particular method (Documentation) to see the code. In this case it's:
https://rawgit.com/MrRio/jsPDF/master/docs/modules_html.js.html#line749
This is what options object can be:
options = options || {};
options.callback = options.callback || function () {};
options.html2canvas = options.html2canvas || {};
options.html2canvas.canvas = options.html2canvas.canvas ||
this.canvas;
options.jsPDF = options.jsPDF || this;
From the documentation you can see the code behind the .html module:
/**
* Generate a PDF from an HTML element or string using.
*
* @name html
* @function
* @param {Element|string} source The source element or HTML string.
* @param {Object=} options An object of optional settings.
* @description The Plugin needs html2canvas from niklasvh
*/
jsPDFAPI.html = function (src, options) {
'use strict';
options = options || {};
options.callback = options.callback || function () {};
options.html2canvas = options.html2canvas || {};
options.html2canvas.canvas = options.html2canvas.canvas || this.canvas;
options.jsPDF = options.jsPDF || this;
// Create a new worker with the given options.
var pdf = options.jsPDF;
var worker = new Worker(options);
if (!options.worker) {
// If worker is not set to true, perform the traditional 'simple' operation.
return worker.from(src).doCallback();
} else {
// Otherwise, return the worker for new Promise-based operation.
return worker;
}
return this;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With