parallax/jsPDF · error · Error

toDataUrl not implemented.

Error message

toDataUrl not implemented.

What it means

toDataURL is an unconditional stub in context2d: it always throws 'toDataUrl not implemented.' (note the lowercase 'rl' in the message vs. the correct 'URL' method name). jsPDF's context2d cannot rasterize the accumulated PDF drawing back into a PNG/JPEG data URL, so the Canvas2D method is intentionally absent.

Source

Thrown at src/modules/context2d.js:1213

    if (doStackPop && this.ctxStack.length !== 0) {
      this.ctx = this.ctxStack.pop();
      this.fillStyle = this.ctx.fillStyle;
      this.strokeStyle = this.ctx.strokeStyle;
      this.font = this.ctx.font;
      this.lineCap = this.ctx.lineCap;
      this.lineWidth = this.ctx.lineWidth;
      this.lineJoin = this.ctx.lineJoin;
      this.lineDash = this.ctx.lineDash;
      this.lineDashOffset = this.ctx.lineDashOffset;
    }
  };

  /**
   * @name toDataURL
   * @function
   */
  Context2D.prototype.toDataURL = function() {
    throw new Error("toDataUrl not implemented.");
  };

  //helper functions

  /**
   * Get the decimal values of r, g, b and a
   *
   * @name getRGBA
   * @function
   * @private
   * @ignore
   */
  var getRGBA = function(style) {
    var rxRgb = /rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
    var rxRgba = /rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)/;
    var rxTransparent = /transparent|rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*0+\s*\)/;

    var r, g, b, a;

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Export the document via doc.output('datauristring') or doc.output('blob') for a PDF data URL instead.
  2. If a PNG/JPEG thumbnail is required, render the same drawing to an offscreen HTML <canvas> and call its native toDataURL, then feed that image into jsPDF via addImage.
  3. Remove toDataURL-based code paths when targeting jsPDF context2d.

Example fix

// before
const png = ctx.toDataURL(); // throws [105]

// after: export the PDF itself as a data URL
const pdfDataUri = doc.output('datauristring');
Defensive patterns

Strategy: fallback

Validate before calling

// toDataURL is an unconditional stub; choose the right export surface.
function exportFromContext(ctx, doc) {
  // Prefer the PDF data URL over the stubbed context2d.toDataURL.
  if (doc && typeof doc.output === 'function') return doc.output('datauristring');
  throw new Error('No export available');
}

Type guard

// No type narrowing helps — the method exists but throws.
// Probe capability:
function contextCanToDataURL(ctx) {
  try { ctx.toDataURL(); return true; } catch (e) { return false; }
}

Try / catch

try {
  return ctx.toDataURL();
} catch (e) {
  if (/toDataUrl not implemented/.test(e.message)) {
    return doc.output('datauristring'); // PDF data URL instead
  }
  throw e;
}

Prevention

When it happens

Trigger: Any call to doc.context2d.toDataURL(); generic canvas-export utilities that probe for toDataURL; snapshot/thumbnail pipelines expecting a Canvas2D-compatible surface.

Common situations: Treating jsPDF's context2d as a drop-in Canvas2D replacement; libraries that auto-export a context via toDataURL for previews.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/5f90b096800e773e. Report an issue: GitHub.