Java servlet to work as a proxy for html2canvas

So I wrote about how I used the html2canvas to solve one of the problems at work in this post. Now have a read of the documentation for html2canvas, and focus on the bit about same origin content. So in summary, if the web page you are trying to capture the screenshot of, contains an image that comes from a different domain, that image wont be in the screenshot that you just captured with the library. So the only way to ensure cross origin content is included in the screenshot is via a proxy. Now the author of html2canvas, has provided proxies, for Python and Node.js, but they are not of use to me as I was using the html2canvas in a Java project. So I had to write my own little Java servlet to get the job done. So it was a very simple servlet and I was just surprised that there wasn't a Java based proxy out there.

Anyway so the servlet that I had to write to work as a proxy was something similar to what I have shared in this Github repo. I am sure you realise that you may need to modify the code to suit your needs.

Also if you are keen on knowing more about cross origin content i.e. HTTP access control, have a read of this article.

Comments

Popular posts from this blog

Upload to AWS S3 from Java API

Addressing app review rejections for auto-renewing subscription in-app purchase (iOS)

Getting started with iOS programming using Swift (Part 1)