Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3443772
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:49:56+00:00 2026-05-18T08:49:56+00:00

Background OpenOffice Writer lacks the ability to link to an ASCII text source file,

  • 0

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:

  1. The resolution is lacking (using -resample and -density offer no improvement).
  2. The syntax highlighting is unsuitable for a white page (can probably change enscript’s colour theme).
  3. Using Courier100 produces several .png files, which would need to be stitched together.
  4. The -border 10 unexpectedly 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:49:57+00:00Added an answer on May 18, 2026 at 8:49 am

    Software Requirements

    The following software packages are available for both Windows and Linux systems, and are required for a complete, working solution:

    • gvim – Used to export syntax highlighted source code to HTML.
    • moria – Colour scheme for syntax highlighting.
    • wkhtmltopdf – Converts HTML documents to PDF or PostScript (PS) documents.
    • Ghostscript – Used to convert PS to PNG.
    • ImageMagick – Used to trim the PNG and add a border.

    General Steps

    Here is how the solution works:

    1. Load the source code into an editor that can add splashes of colour.
    2. Export the source code as an HTML document (with embedded FONT tags).
    3. Convert the HTML document to a PS file.
    4. Convert the PS file to a PNG file.
    5. Trim the white border of the PNG and the overzealous source code border.
    6. Add a border around the image, using the same background colour as the HTML document.
    7. Delete temporary files.

    Installation

    Install the components into the following locations:

    • 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

    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).

    Environment Variables

    Add or update the following environment variables:

    • 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"

    Batch File

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background Whitepixel is open source (GPLv3) GPU-accelerated password hash auditing software for AMD/ATI graphics
Background: I want to check-out the source code from Cliche , which is stored
Background In a targeted issue tracking application (in django) users are able add file
Background - I want to extract specific columns from a csv file. The csv
Background My project is urgent and requires that I iterate a large XML file
Background I'm customising a tumblr theme (Source: hasaportfolio ), and I am trying to
Background I first wanted to upload a file via json and get a response
Background: One of the problems with using a local static variable in a function
Background: As a short project over winter break, I'm trying to implement a programming
Background I'm trying to implement a simple web server part as a web interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.