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.
The images need to be high-resolution (300 dpi or greater) with syntax colouring appropriate for a white background (i.e., a printed page).
How can high-quality images be created automatically from source code files, such as:
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:
-resample
and -density
offer no improvement).Courier100
produces several .png
files, which would need to be stitched together.-border 10
unexpectedly changes the background colour from white to lightgray.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.
Simply open the file on command line with vim <filename> , type :syntax on<ENTER> , then :hardcopy<ENTER> to print it.
Converting HTML to JPG with the Windows screen capture tool Open your HTML file in your browser or any viewable tool. Take a snapshot of an area with your screen capture tool (Snipping tool on Windows, for example). Click File > Save as. Select the location and select the Save as type as JPG.
The Syntax highlighting feature makes PHP code more readable as any other language file integrated in Visual Studio. Script code blocks, variables, keywords, strings, script tags and comments are distinguished to make programming easier.
The following software packages are available for both Windows and Linux systems, and are required for a complete, working solution:
Here is how the solution works:
FONT
tags).Install the components into the following locations:
C:\Program Files\Vim
C:\Program Files\Vim\vim73\colors
C:\Program Files\wkhtml
C:\Program Files\gs
C:\Program Files\ImageMagick
Note: ImageMagick has a program called convert.exe
, which cannot supersede the Windows convert
command. Because of this, the full path to convert.exe
must be hard-coded in the batch file (as opposed to adding ImageMagick to the PATH
).
Add or update the following environment variables:
C:\Program Files\gs\gs9.00\lib
C:\Program Files\gs\gs9.00\bin\gswin32.exe
"C:\Program Files\Vim\vim73";"C:\Program Files\wkhtml";"C:\Program Files\gs\gs9.00\bin"
Here is the batch source text:
@ECHO OFF
ECHO Converting %1 to %1.html ...
gvim -e %1 -c "set nobackup" -c ":colorscheme moria" -c :TOhtml -c wq -c :q
ECHO Converting %1.html to %1.ps ...
wkhtmltopdf --quiet --dpi 1200 %1.html %1.ps
ECHO Converting %1.pdf to %1.png ...
IF EXIST %1.png DEL /q %1.png
gswin32 -q -dBATCH -dNOPAUSE -dSAFER -dNOPROMPT ^
-sDEVICE=png16m -dDEVICEXRESOLUTION=600 -dDEVICEYRESOLUTION=600 ^
-dDEVICEWIDTH=4958 -dDEVICEHEIGHT=7017 -dNOPLATFONTS ^
-dTextAlphaBits=4 -sOutputFile=%1.png %1.ps
ECHO Trimming %1.png ...
move %1.png %1.orig.png
"C:\Program Files\ImageMagick\convert.exe" -trim +repage -trim +repage ^
-bordercolor "#f0f0f0" -border 25x25 %1.orig.png %1.png
ECHO Removing old files ...
IF EXIST %1.orig.png DEL /q %1.orig.png
IF EXIST %1.html DEL /q %1.html
IF EXIST %1.ps DEL /q %1.ps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With