How to use the jspdf.API function in jspdf

To help you get started, we’ve selected a few jspdf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bcgov / range-web / src / components / rangeUsePlanPage / pdf / jspdf.js View on Github external
import jsPDF from 'jspdf'
import 'jspdf-autotable'

/* eslint-disable func-names */

// https://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113
const splitRegex = /\r\n|\r|\n/g
jsPDF.API.textEx = function(text, x, y, hAlign, vAlign) {
  let currX = x
  let currY = y
  const fontSize = this.internal.getFontSize() / this.internal.scaleFactor

  // As defined in jsPDF source code
  const lineHeightProportion = 1.15

  let splittedText = null
  let lineCount = 1
  if (
    vAlign === 'middle' ||
    vAlign === 'bottom' ||
    hAlign === 'center' ||
    hAlign === 'right'
  ) {
    splittedText = typeof text === 'string' ? text.split(splitRegex) : text
github simonbengtsson / jsPDF-AutoTable / src / main.ts View on Github external
// Assign false to enable `doc.lastAutoTable.finalY || 40` sugar;
jsPDF.API.lastAutoTable = false;
jsPDF.API.previousAutoTable = false; // deprecated in v3
jsPDF.API.autoTable.previous = false; // deprecated in v3

jsPDF.API.autoTableSetDefaults = function(defaults) {
    setDefaults(defaults, this);
    return this;
};

jsPDF.autoTableSetDefaults = function(defaults, doc) {
    setDefaults(defaults, doc);
    return this;
};

jsPDF.API.autoTableHtmlToJson = function(tableElem, includeHiddenElements) {
    includeHiddenElements = includeHiddenElements || false;

    if (!tableElem || !(tableElem instanceof HTMLTableElement)) {
        console.error("A HTMLTableElement has to be sent to autoTableHtmlToJson");
        return null;
    }

    let {head, body, foot} = parseHtml(tableElem, includeHiddenElements, false);
    let firstRow = head[0] || body[0] || foot[0];

    return {columns: firstRow, rows: body, data: body};
};

/**
 * @deprecated
 */
github simonbengtsson / jsPDF-AutoTable / src / main.ts View on Github external
this.previousAutoTable = table;
    this.lastAutoTable = table;
    this.autoTable.previous = table; // Deprecated

    applyUserStyles();
    resetState();
    return this;
}
jsPDF.API.autoTable = autoTable;

// Assign false to enable `doc.lastAutoTable.finalY || 40` sugar;
jsPDF.API.lastAutoTable = false;
jsPDF.API.previousAutoTable = false; // deprecated in v3
jsPDF.API.autoTable.previous = false; // deprecated in v3

jsPDF.API.autoTableSetDefaults = function(defaults) {
    setDefaults(defaults, this);
    return this;
};

jsPDF.autoTableSetDefaults = function(defaults, doc) {
    setDefaults(defaults, doc);
    return this;
};

jsPDF.API.autoTableHtmlToJson = function(tableElem, includeHiddenElements) {
    includeHiddenElements = includeHiddenElements || false;

    if (!tableElem || !(tableElem instanceof HTMLTableElement)) {
        console.error("A HTMLTableElement has to be sent to autoTableHtmlToJson");
        return null;
    }
github geomoose / gm3 / src / gm3 / components / print / printModal.js View on Github external
makePDF(layout) {
        // check for and install the geopdf plugin
        if(!jsPDF.API.setGeoArea) {
            GeoPdfPlugin(jsPDF.API);
        }
        // new PDF document
        const doc = new jsPDF(layout.orientation, layout.units, layout.page);
        loadFonts(this.props.fontIndexUrl)
            .then(fontIndex => {
                for (const fontName in fontIndex.FONTS) {
                    // add the file to the VFS
                    doc.addFileToVFS(fontName, fontIndex.FONTS[fontName]);
                    // add the font.
                    const parts = fontName.replace('.ttf', '').split('-');
                    doc.addFont(fontName, parts[0], parts[1].toLowerCase());
                }

                this.paintPDF(doc, layout);
            });
github simonbengtsson / jsPDF-AutoTable / src / main.ts View on Github external
drawTable(table);

    table.finalY = table.cursor.y;
    this.previousAutoTable = table;
    this.lastAutoTable = table;
    this.autoTable.previous = table; // Deprecated

    applyUserStyles();
    resetState();
    return this;
}
jsPDF.API.autoTable = autoTable;

// Assign false to enable `doc.lastAutoTable.finalY || 40` sugar;
jsPDF.API.lastAutoTable = false;
jsPDF.API.previousAutoTable = false; // deprecated in v3
jsPDF.API.autoTable.previous = false; // deprecated in v3

jsPDF.API.autoTableSetDefaults = function(defaults) {
    setDefaults(defaults, this);
    return this;
};

jsPDF.autoTableSetDefaults = function(defaults, doc) {
    setDefaults(defaults, doc);
    return this;
};

jsPDF.API.autoTableHtmlToJson = function(tableElem, includeHiddenElements) {
    includeHiddenElements = includeHiddenElements || false;

    if (!tableElem || !(tableElem instanceof HTMLTableElement)) {
github simonbengtsson / jsPDF-AutoTable / src / autoTableText.ts View on Github external
const jsPDF = require('jspdf');

/**
 * Improved text function with halign and valign support
 * Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113
 */
jsPDF.API.autoTableText = function(text, x, y, styles) {
    styles = styles || {};
    let FONT_ROW_RATIO = 1.15;

    if (typeof x !== 'number' || typeof y !== 'number') {
        console.error('The x and y parameters are required. Missing for text: ', text);
    }
    let k = this.internal.scaleFactor;
    let fontSize = this.internal.getFontSize() / k;

    let splitRegex = /\r\n|\r|\n/g;
    let splitText = null;
    let lineCount = 1;
    if (styles.valign === 'middle' || styles.valign === 'bottom' || styles.halign === 'center' || styles.halign === 'right') {
        splitText = typeof text === 'string' ? text.split(splitRegex) : text;
        lineCount = splitText.length || 1;
    }
github simonbengtsson / jsPDF-AutoTable / src / main.ts View on Github external
if (!tableElem || !(tableElem instanceof HTMLTableElement)) {
        console.error("A HTMLTableElement has to be sent to autoTableHtmlToJson");
        return null;
    }

    let {head, body, foot} = parseHtml(tableElem, includeHiddenElements, false);
    let firstRow = head[0] || body[0] || foot[0];

    return {columns: firstRow, rows: body, data: body};
};

/**
 * @deprecated
 */
jsPDF.API.autoTableEndPosY = function() {
    console.error("Use of deprecated function: autoTableEndPosY. Use doc.previousAutoTable.finalY instead.");
    let prev = this.previousAutoTable;
    if (prev.cursor && typeof prev.cursor.y === 'number') {
        return prev.cursor.y;
    } else {
        return 0;
    }
};

/**
 * @deprecated
 */
jsPDF.API.autoTableAddPageContent = function(hook) {
    console.error("Use of deprecated function: autoTableAddPageContent. Use jsPDF.autoTableSetDefaults({didDrawPage: () => {}}) instead.");
    if (!jsPDF.API.autoTable.globalDefaults) {
        jsPDF.API.autoTable.globalDefaults = {};
github FirefoxUX / photon-icons / svgToPdf.js View on Github external
//TODO: image
            default:
                if (remove) {
                    console.log("can't translate to pdf:", node ? node.localName : 'unknown');
                    node.remove();
                }
        }
    });
    if (error) {
        console.log(error);
        return null;
    }
    return pdf;
};

jsPDF.API.addSVG = function(element, x, y, options) {
    'use strict'

    options = (typeof(options) == 'undefined' ? {} : options);
    options.x_offset = x;
    options.y_offset = y;

    let rv = svgElementToPdf(element, this, options);
    if (!rv) {
        return null;
    }
    return this;
};

var svgToPdf = function (svg) {
    let width = parseInt(svg.getAttribute('width'), 10);
    let height = parseInt(svg.getAttribute('height'), 10);
github simonbengtsson / jsPDF-AutoTable / src / main.ts View on Github external
if (!tableElem || !(tableElem instanceof HTMLTableElement)) {
        console.error("A HTMLTableElement has to be sent to autoTableHtmlToJson");
        return null;
    }

    let {head, body, foot} = parseHtml(tableElem, includeHiddenElements, false);
    let firstRow = head[0] || body[0] || foot[0];

    return {columns: firstRow, rows: body, data: body};
};

/**
 * @deprecated
 */
jsPDF.API.autoTableEndPosY = function() {
    console.error("Use of deprecated function: autoTableEndPosY. Use doc.previousAutoTable.finalY instead.");
    let prev = this.previousAutoTable;
    if (prev.cursor && typeof prev.cursor.y === 'number') {
        return prev.cursor.y;
    } else {
        return 0;
    }
};

/**
 * @deprecated
 */
jsPDF.API.autoTableAddPageContent = function(hook) {
    console.error("Use of deprecated function: autoTableAddPageContent. Use jsPDF.autoTableSetDefaults({didDrawPage: () => {}}) instead.");
    if (!jsPDF.API.autoTable.globalDefaults) {
        jsPDF.API.autoTable.globalDefaults = {};
github simonbengtsson / jsPDF-AutoTable / src / main.ts View on Github external
* @deprecated
 */
jsPDF.API.autoTableEndPosY = function() {
    console.error("Use of deprecated function: autoTableEndPosY. Use doc.previousAutoTable.finalY instead.");
    let prev = this.previousAutoTable;
    if (prev.cursor && typeof prev.cursor.y === 'number') {
        return prev.cursor.y;
    } else {
        return 0;
    }
};

/**
 * @deprecated
 */
jsPDF.API.autoTableAddPageContent = function(hook) {
    console.error("Use of deprecated function: autoTableAddPageContent. Use jsPDF.autoTableSetDefaults({didDrawPage: () => {}}) instead.");
    if (!jsPDF.API.autoTable.globalDefaults) {
        jsPDF.API.autoTable.globalDefaults = {};
    }
    jsPDF.API.autoTable.globalDefaults.addPageContent = hook;
    return this;
};

/**
 * @deprecated
 */
jsPDF.API.autoTableAddPage = function() {
    console.error("Use of deprecated function: autoTableAddPage. Use doc.addPage()");
    this.addPage();
    return this;
};

jspdf

PDF Document creation from JavaScript

MIT
Latest version published 2 months ago

Package Health Score

97 / 100
Full package analysis