Background
OpenOffice Writer lacks the ability to link to an ASCII text source file, apply syntax highlighting, wrap it in a frame, and update the frame contents whenever the source file changes. However, OpenOffice Writer can link to images, and will update the images automatically when they change.
Problem
The images need to be high-resolution (300 dpi or greater) with syntax colouring appropriate for a white background (i.e., a printed page).
Question
How can high-quality images be created automatically from source code files, such as:
- SQL;
- PostgreSQL functions;
- Java;
- bash scripts; and
- R and PL/R?
Attempts
Most attempts have been a variation on the following theme:
$ enscript --color -f Courier12 -B -1 --highlight=sql -h -o - source.sql |\
convert - -trim -border 10 source.png
There are a few problems with this approach:
- The resolution is lacking (using
-resampleand-densityoffer no improvement). - The syntax highlighting is unsuitable for a white page (can probably change enscript’s colour theme).
- Using
Courier100produces several.pngfiles, which would need to be stitched together. - The
-border 10unexpectedly changes the background colour from white to lightgray.
Manual Solution
Converting the source files to PostScript — avoiding ImageMagick altogether — and then importing them into The GIMP will produce the desired results. Unfortunately, that solution involves a bit of manual work, and my GIMP batch programming experience is next to nil.
Software Requirements
The following software packages are available for both Windows and Linux systems, and are required for a complete, working solution:
General Steps
Here is how the solution works:
FONTtags).Installation
Install the components into the following locations:
C:\Program Files\VimC:\Program Files\Vim\vim73\colorsC:\Program Files\wkhtmlC:\Program Files\gsC:\Program Files\ImageMagickNote: ImageMagick has a program called
convert.exe, which cannot supersede the Windowsconvertcommand. Because of this, the full path toconvert.exemust be hard-coded in the batch file (as opposed to adding ImageMagick to thePATH).Environment Variables
Add or update the following environment variables:
C:\Program Files\gs\gs9.00\libC:\Program Files\gs\gs9.00\bin\gswin32.exe"C:\Program Files\Vim\vim73";"C:\Program Files\wkhtml";"C:\Program Files\gs\gs9.00\bin"Batch File
Here is the batch source text: