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
- Export the document via doc.output('datauristring') or doc.output('blob') for a PDF data URL instead.
- 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.
- 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
- Use doc.output('datauristring' | 'blob' | 'arraybuffer') for PDF export, never context2d.toDataURL.
- If a raster preview is required, render to a real <canvas> and use its native toDataURL, then addImage into jsPDF.
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
- arcTo not implemented.
- Invalid arguments passed to jsPDF.context2d.rect
- Invalid arguments passed to jsPDF.context2d.fillRect
- Invalid arguments passed to jsPDF.context2d.strokeRect
- Invalid arguments passed to jsPDF.context2d.clearRect
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/5f90b096800e773e.
Report an issue: GitHub.