Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Uncaught TypeError: Cannot read property 'getContext' of null

918 views
Skip to first unread message

pdfjs...@gmail.com

unread,
Mar 19, 2014, 9:41:56 AM3/19/14
to
I have a button which on click executes this function.This code is to draw a line on canvas element on which PDF file gets rendered on a webpage by using PDF.JS. But i get an error "Uncaught TypeError: Cannot read property 'getContext' of null". What should i do.

function abc()
{
alert("msg");
var c=document.getElementById("canvas1");
alert(c);
var ctx= c.getContext('2d');
alert(ctx);
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(300,150);
ctx.stroke();
}

Brendan Dahl

unread,
Mar 19, 2014, 2:02:53 PM3/19/14
to pdfjs...@gmail.com, dev-p...@lists.mozilla.org
I’m not sure if you’re using our viewer or one of your own, but the viewer in pdf.js has canvas with ids like ‘page1’ not ‘canvas1’.
> _______________________________________________
> dev-pdf-js mailing list
> dev-p...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-pdf-js

0 new messages