Determine Ghostscript Version

Determine ghostscript version

Tyler, dude. Have I been demoted from being a Stack Ove-R-flow peer to a "reader" of your blog? Or is that a promotion ;)

This feels a little hackish to me, but should get the job done. Add this as the first few lines of the function and remove the os argument:

testme <- c(UNIX = "gs -version", 
Win32 = "gswin32c -version",
Win64 = "gswin64c -version")
os <- names(which(sapply(testme, system) == 0))

I've used the -version switch so that R doesn't try to load Ghostscript unnecessarily.

On my Ubuntu system, when I run this, os returns, as expected, UNIX, and on my Windows system where I have the 32-bit version of Ghostscript installed, it returns Win32. Try it out on your 64-bit machine running the 32-bit GS and let me know how it works.


Update

After reading the help pages for system() and system2(), I learned about Sys.which(), which seems to be exactly what you're looking for. Here it is in action on my Ubuntu system:

Sys.which(c("gs", "gswin32c", "gswin64c"))
# gs gswin32c gswin64c
# "/usr/bin/gs" "" ""
names(which(Sys.which(c("gs", "gswin32c", "gswin64c")) != ""))
# [1] "gs"

Thus, OS specification can be skipped entirely in the mergePDF() function:

mergePDF <- function(infiles, outfile) {
gsversion <- names(which(Sys.which(c("gs", "gswin32c", "gswin64c")) != ""))
pre = " -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="
system(paste(paste(gsversion, pre, outfile, sep = ""), infiles, collapse = " "))
}

You may want to do some error checking. If the length of gsversion is > 1 or is 0, for instance, you may want to stop the function and prompt the user to either install Ghostscript or to verify their Ghostscript version.

How can I check IF a version of Ghostscript is installed and IF SO where it is installed?

I think it's safe to assume that the Ghostscript executable will be located in the same directory as the DLL, so something like this should work:

Const HKLM    = &h80000002
Const baseKey = "SOFTWARE\GPL Ghostscript"
Const value = "GS_DLL"

Set reg = GetObject("winmgmts://./root/default:StdRegProv")

If reg.EnumKey(HKLM, baseKey, subkeys) <> 0 Then
WScript.Echo "Cannot enumerate subkeys of " & baseKey & "."
WScript.Quit 1
End If

For Each sk In subkeys
If reg.GetStringValue(HKLM, baseKey & "\" & sk, value, gsLib) <> 0 Then
WScript.Echo "Cannot read value " & value & "."
WScript.Quit 1
End If
Next

Set fso = CreateObject("Scripting.FileSystemObject")

gsDir = fso.GetParentFolderName(gsLib)
gs = fso.BuildPath(gsDir, "gswin32.exe")

WScript.Echo gs

How to get PDF Version with ghostscript (GS) on Linux

You aren't 'changing' the PDF version there. When you interpret a PDF file with Ghostscript it doesn't just play around with bits of it. It fully interprets the input, creating a sequence of graphics primitives.

These are then sent to the 'device' for processing. For rendering devices (eg png16m) these are rendered to a bitmap. For the pdfwrite device, it takes those primitives and converts them into new PDF operations. The output should be visually the same, but it is not the same sequence of PDF operations as were in the original file.

So what you are actually doing is creating a brand new PDF file, which is compatible with version 1.4 of the PDF specification. In this case that means it doesn't use any features of later versions of the spec, it may not use any 1.4 features either, its just guaranteed not to need a version higher than that.

You don't need GS to find out the existing level of a PDF file, its in the header of the file. PDF files should begin with '%PDF-x.y' though they are considered valid if the header appears anywhere in the first 1024 bytes (IIRC) of the file. x is the major version and y is the minor version of the specification required by this PDF file. SO a 1.4 file would begin %PDF-1.4

However, you should be aware that some PDF files are 'economical with the truth', especially ones which have been edited, and don't always declare the correct version required.

display ghostscript version number through PHP in ubuntu

Possibly ghostscrsipt is writing the data out to STDERR instead of STDOUT. Try doing

/usr/bin/gs --version 2>&1 

to redirect stderr to stdout and try again

Treepoem barcode generator unable to find ghostscript

You are installing on Windows, the Windows binary differs in name from the Linux binaries and indeed differs depending whether you installed the 64 or 32-bit version.

On Linux (and MacOS) the Ghostscript binary is called 'gs', on Windows its 'gswin32' or 'gswin64' or 'gswin32c' or 'gswin64c' depending on whether you want the 32 or 64 bit version, and the command line or windowed executable.

My guess is that your script is looking for simply 'gs' and is probably expecting the path to be in the $PATH environment variable, its not clear to me what its expecting.

You could probably 'fix' this by making sure the installation path is in the $PATH environment variable and copying the executable to 'gs.exe' in that directory.

Other than that you'll need someone who can tell you what the script is looking for. Quite possibly you could just grep it.

Ghostscript - determine the final substituted font at runtime

The answer is 'not really'. The font substitution mechanism in Ghostscript is quite complex and involves some heuristics based on the font characteristics. It also dependsw on how you have configured Ghostscript and the fonts installed.

In your specific case you will probably find that there is a definition in fontmap.GS for Arial. In fact the default fontmap.GS includes this:

/Arial /ArialMT ;

However, unless you installed on a Windows system (and used the GS installer to set FontPath) it won't have actually installed a reference for ArialMT. So, since ArialMT isn't defined, it reverts to the 'if all else fails' font, which is Helvetica. Pretty much what you see on the back channel above.

Your best bet for avoiding font substitution problems is to carefully configure fontmap.GS, the version shipped with the Ghostscript sources is an example, its not intended to be used 'as is' on every system.



Related Topics



Leave a reply



Submit