I'm writing a book and sometimes I must show some screenshots taken from my terminal window. Problem is they are not good for print, so I need to increase their quality (resolution). Is there any way to take screenshots at a higher resolution? At the moment, I'm using Ubuntu (is there any way to simulate HIdpi and take the screenshot?).
Take high quality screenshots of the terminal window
screenshotterminal
Best Answer
The best way to get print-quality output from what is actually text is to actually represent it as text, rather than as a picture. If you take an actual screenshot of the terminal emulator window, then by definition of a screenshot, you'll get a screen-resolution bitmap.
You can use the
script
command to make a record of everything that's output to the terminal. A nice thing about usingscript
is that it doesn't require any cooperation from the application or from the terminal. However it does have: a downside: the resulting transcript includes the escape sequences sent by the application as-is, including cursor motion, overwrites, etc. so in the general case you need to essentially write a terminal emulator to parse its output.You can run the application in screen, and use its
hardcopy
command (C-a h
). This produces a file (calledhardcopy.0
by default) that contains the content of the screen. This does not contain any markup (bold, color, etc.).Xterm has a print feature, which you can invoke from the Ctrl+Mouse1 (Ctrl+left-click) menu. By default, this only prints the text, but you can tell Xterm to include escape sequences for video attributes:
You can add a menu entry or keyboard shortcut to the
print
function withcolorAttr=2
to get this effect. By default, the currently visible screen and the saved lines are included; this can be controlled via theprintOptsImmediate
resource or via arguments to theprint
function. For example, to only get the visible part, you can useThe output is in a file called
XTerm
followed by a timestamp (you can change the prefix with theprintFileImmediate
resource). This contains ANSI escape sequences to change text attributes, which you can convert to whatever format you use to typeset your book (e.g. via HTML).A perhaps more convenient approach would be to use Emacs as the terminal emulator. Install a print-to-PDF-file printer (cups-pdf, should be available in your distribution). Set it as the default printer in Emacs (use the configuration interface or put
(setq printer-name "pdf")
in your.emacs
). RunM-x term
to get a terminal emulator, and select “File” → “Postscript Print Buffer” in the menu to print. (Don't use the plain “Print Buffer”, that would produce a low-quality bitmap.)