Documentation for jsPDF that actually tells me the options I can set?

Viewed 8903

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?

2 Answers

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;
  };
Related