I needed to convert some code into an image for a presentation recently and found a number of different ways of doing so. The easiest, of course, is when you take a screen capture of the code in your IDE. This fails when your code goes well past the side of your screen and you still want to show it all.
Alternatively, you can do this in a two step process.
- Save the code to HTML – I know that both IntelliJ and NetBeans allow you to do this for Java code.
- Use webkit to save to an image – I used PhantomJS for doing this. Take a look at the example code of how to do this.
Leave a comment if you’ve had any other good experiences doing this. I’d be interested in other ways that have worked for you.