Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 240
Tommy Stenberg Avatar asked Jan 17 '19 08:01

Tommy Stenberg


People also ask

What is jspdf API?

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.

How do I set the orientation of a jspdf document?

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.

Should I also be using jspdf from_HTML library?

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).

What is doformobject in jspdf?

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.


Video Answer


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;
like image 199
Vadi Avatar answered Oct 19 '22 23:10

Vadi


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;
  };
like image 29
nmbrphi Avatar answered Oct 20 '22 00:10

nmbrphi