User Jarrod from the StackOverflow forum posted a very useful function to change the color of the image drawn in an HTML Canvas.

I modified his function to take into account where the image’s current position is in the Canvas.

The answer is … you can’t! Well, generally speaking, that is.

Here are the reasons why:

  1. First things first, for security reasons, you cannot even simulate running the context menu’s Copy Image command.
  2. In Internet Explorer, you can copy a portion or all of the Canvas to an Image using document.body.createControlRange.
  3. In some later versions of Firefox, the ClipboardEvent lets you do copy an Image to clipboard.
  4. In Chrome, there is no way to do so except for some workaround using a littler helper called Flash.
  5. Then again, Flash won’t work in Safari browser.

With these findings, to provide the same consistency across browsers, it is best not to add this feature to your web application for consistency reasons which can bring confusion to some users who are not technically inclined why they will be forced to use certain browsers that only this feature works.

This was an interesting scenario that I came across with. PDF.JS by default can let you select text and copy them to the clipboard. However, since my requirement had us do with creating annotations and since it is messy to mess around the DIV layers of the PDF.JS pages, we had to create a separate Canvas element to draw out annotations in.

Now, the problem is that since there is an extra Canvas layer on top of the existing Canvas layer of PDF.JS where they draw their images if the PDF contains pictures, selecting text is not possible.

However, through a CSS attribute it is possible to let mouse clicks pass through the Canvas element using the pointer-event attribute. The values for these are auto for enabled and none for disabled.

If you plan to use Javascript, use = ‘auto|none’

Related Posts Plugin for WordPress, Blogger...