Convert source code to syntax

Background

OpenOffice Writer cannot link to an ASCII text source file, apply syntax highlighting, transfer it to a frame, and update the contents of the frame whenever the source file changes. However, OpenOffice Writer can reference images and automatically update images when they change.

Problem

Images must be high resolution (300 dpi or more) with syntax coloring suitable for a white background (i.e. a printed page).

Question

How to create high-quality images automatically from source code files, for example:

  • SQL
  • PostgreSQL Functions;
  • Java
  • bash scripts; and
  • R and PL / R?

Attempts

Most attempts were a variation on the following topic:

$ enscript --color -f Courier12 -B -1 --highlight=sql -h -o - source.sql |\
  convert - -trim -border 10 source.png

There are several problems with this approach:

  • ( -resample -density ).
  • (, ).
  • Courier100 .png, .
  • -border 10 lightgray.

PostScript - ImageMagick - GIMP, . , , GIMP nil.

+5
1

Windows, Linux :

:

  • , .
  • HTML- ( FONT).
  • HTML- PS.
  • PS PNG.
  • PNG .
  • , , HTML.
  • .

:

  • gvim - C:\Program Files\Vim
  • moria - C:\Program Files\Vim\vim73\colors
  • wkhtmltopdf - C:\Program Files\wkhtml
  • Ghostscript - C:\Program Files\gs
  • ImageMagick - C:\Program Files\ImageMagick

. ImageMagick convert.exe, Windows convert. - convert.exe ( ImageMagick PATH).

:

  • GS_LIB= C:\Program Files\gs\gs9.00\lib
  • GS_PROG= C:\Program Files\gs\gs9.00\bin\gswin32.exe
  • PATH= "C:\Program Files\Vim\vim73";"C:\Program Files\wkhtml";"C:\Program Files\gs\gs9.00\bin"

:

@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
+5

All Articles