Login to a website and take screenshot using PhantomJS on the server side
In this blog I will discuss about taking screenshots using PhantomJS by logging in to a site and taking screenshot a particular link or URL. I am not going describe how PhantomJS can be invoked on the server side.
Taking screenshots of visualizations with SVGs is not an easy task at least in Java. I have tried to produce the pdf of web pages with SVG content using the Apache Batik library but was not very successful. So, I have tried the alternatives and one of the options was PhantomJs.
PhantomJS is a headless browser and is capable of taking screenshots of complex visualizations otherwise difficult to capture. So, phantom is as good as Mozilla or Chrome but runs in-memory, so it is headless. PhantomJS has many applications and one of them is that it can be used to produce quality reports in different file formats like pdf and images.
The following is the screenshot.js file from PhantomJS web site. I have modified the code to log in using PhantomJS and take the screenshot and save it as a file on the file system.
Also note that when we start a process using command-line/shell script, do not forget the read the
InputStream, and the
ErrorStream of the
Hope you have followed the comments and understood the how to part of it. If you have any questions, please post them so that I will answer the questions.
Wish you happy coding and thanks for reading the article.
Java BI Developer,
Helical IT Solutions.
Best Open Source Business Intelligence Software Helical Insight is Here