Ghostscript: ps2pdf doesn't work with Win 7 32-bit - windows

I have the latest GPL Ghostscript v9.05 and I am running it on Win 32 bit systems. On my XP machine, both commands
ps2pdf -v -
and
rungs -v (used internally by TeXLive)
report of Ghostscript 9.05 being available as follows:
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
On another Win 7 computer, the command
ps2pdf -v -
at the command line is not recognised as being a valid ps2pdfsyntax but rungs -v works fine.
I have read on the internet about setting temporary directories for Ghostscript here:
http://schlingel.bplaced.net/?p=54
and it says basically to edit the gssetgs.bat file in the lib folder of Ghostscript and add the lines:
set path=%ProgramFiles%\gs\gs9.02\lib;%ProgramFiles%\gs\gs9.02\bin;%windir%\SysWOW64
set TMP=%YOUR_TEMP%
set TEMP=%TMP%
This needs to be modified appropriately by replacing 9.02 with 9.05 in my case. Now on Win 7, how should the last two lines regarding the temporary folder be? Can I have for Set TMP as follows:
set TMP=%"C:\Users\hihi\AppData\Local\Temp"%
Is it the right syntax?
I have also put the tmp and temp variables in my Environment variables.
Update
A. Using ps2pdf, here is how I convert a PS to a PDF file on my Win 7 machine and I get an error:
C:\work\misc>ps2pdf -dNOSAFER -sDEVICE=pdfwrite -r720 -dCompatibilityLevel=1.5 -dUseFlateCompression=true -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dEPSCrop "%1.ps" "%1.pdf"
Unknown device:
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
defaultdevice
Note: the above command works fine on my Win XP machine!
B. Using gswin32c here is how I convert a PS to a PDF file on my Win 7 machine and this works:
C:\work\misc>gswin32c.exe -o "%1.pdf" -dNOSAFER -sDEVICE=pdfwrite -r720 dCompatibilityLevel=1.5 -dUseFlateCompression=true -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dNumRenderingThreads=2 -c "60000000 setvmthreshold" -f -dEPSCrop "%1.ps"
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Loading NimbusSanL-Regu font from %rom%Resource/Font/NimbusSanL-Regu... 2837152
1454727 4413848 3026018 1 done.
Loading Dingbats font from %rom%Resource/Font/Dingbats... 2837152 1510862 457461
6 3180865 1 done.
Loading NimbusSanL-Bold font from %rom%Resource/Font/NimbusSanL-Bold... 2857248
1553499 4655000 3251960 1 done.
Note: the above command also works fine on my Win XP machine
To summarise: I have problem with ps2pdf on my Win 7 machine.
New (May 09, 2012)
This is what I get when I rem the last two lines as Ken suggested:
C:\work\misc>ps2pdf -dNOSAFER -r720 -dCompatibilityLevel=1.5 -dUseFlateCompression=true -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dEPSCrop "%1.ps" "%1.pdf"
Unrecoverable error: typecheck in .putdeviceprops
avoiding clean up
The temp folder has those temporary files you mentioned.
The contents of _.at:
-dCompatibilityLevel#1.4
-dNOSAFER
-r720
-dCompatibilityLevel
The contents of _.at2:
-q -P- -dSAFER -dNOPAUSE -dBATCH -sDEVICE#pdfwrite
-sOutputFile#-dUseFlateCompression
-dCompatibilityLevel#1.4
-dNOSAFER
-r720
-dCompatibilityLevel
-c .setpdfwrite -f1.5
Update May 11
Note: This is working fine now on my win 7 machine
C:\work\misc>ps2pdf -dNOSAFER -r720 -dCompatibilityLevel#1.5 -dUseFlateCompression#true -dMaxSubsetPct#100 -dSubsetFonts#true -dEmbedAllFonts#true -dEPSCrop "defense.ps" "defense.pdf"
avoiding clean up
The contents of _.at:
-dCompatibilityLevel#1.4
-dNOSAFER
-r720
-dCompatibilityLevel#1.5
-dUseFlateCompression#true
-dMaxSubsetPct#100
-dSubsetFonts#true
-dEmbedAllFonts#true
-dEPSCrop
The contents of _.at2:
-q -P- -dSAFER -dNOPAUSE -dBATCH -sDEVICE#pdfwrite
-sOutputFile#"defense.pdf"
-dCompatibilityLevel#1.4
-dNOSAFER
-r720
-dCompatibilityLevel#1.5
-dUseFlateCompression#true
-dMaxSubsetPct#100
-dSubsetFonts#true
-dEmbedAllFonts#true
-dEPSCrop
-c .setpdfwrite -f"defense.ps"
Thanks.

Far more likely than a temporary file problem is permissions on the directory where you are trying to write the destination file. The error message you quote occurs long before any temporary files are used, but is a very common error if you try to write to a directory which does not exist, or which the process has no write permission for.
First thing to do is post the actual gswin32 command line you are using.
The syntax you are querying is incorrect. %value% is a Windows scripting operation which says 'replace the stuff between the % signs by the named value'. So if I declare 'set VAL=c:/temp' Then I can say 'set NEWVAL=%VAL%/New' which will make NEWVAL 'c:/temp/new'. You can find more about windows scripting in the Windows help, or by a quick Google.
Given that 'ps2pdf' (which is a Windows script) can't be found on your Windows 7 machine (at least I assume that's what you mean by 'is not recognised as being a valid ps2pdf command') it does seem like you need to add the Ghostscript paths to your environment. Simply altering gssetgs.bat on its own will do nothing, you need to ensure that this script file is called from your autoexec.bat script, so that the additional environment settings are applied.
If you aren't sure what autoexec.bat is, or how to modify it, then again Google should help you pretty quickly.
Did you actually install Ghostscript, or simply copy it ?
Given that Ghostscript works correctly, the problem must be in the shell script 'ps2pdf', or more accurately some change in Windows 7 is causing the old script not to work.
This script is (unfortunately) rather more complex than I would like (I didn't write it). it actually uses about three different scripts to do the work. You really need to find out what is being sent to GS.
Probably the simplest way to do this is to edit 'ps2pdfxx.bat'. At the :end label you'll see 'rem Clean up' followed by two lines beginning 'if exist'. Put rem in front of those two. Add a line which says 'echo avoiding clean up' The end of the file should look like this:
:end
rem Clean up.
rem if exist "%TEMP%_.at" erase "%TEMP%_.at"
rem if exist "%TEMP%_.at"2 erase "%TEMP%_.at"2
echo avoiding clean up
Now run your command line (by the way you really don't need to put -sDEVICE= when using ps2pdf.....)
In your TEMP directory you should have files called _.at and possibly _.at2 which will contain the actual commands being sent to GS.
OK the file _.at is copied into the file .at2, and then.at2 is used as the list of arguments to Ghostscript. Commenting up the file you got:
---This line added by the batch file ps2pdfxx.bat
-q -P- -dSAFER -dNOPAUSE -dBATCH -sDEVICE#pdfwrite
---These lines come from _.at
-sOutputFile#-dUseFlateCompression
-dCompatibilityLevel#1.4
-dNOSAFER
-r720
-dCompatibilityLevel
--This line added by the batch file ps2pdfxx.bat
-c .setpdfwrite -f1.5
There are a number of problems with this:
-sOutputFile#-dUseFlateCompression
This in effect sets the output file to '-dUseFlateCompression'
-c .setpdfwrite -f1.5
I'm not completely sure what this will do. Either it will handle the -f properly and terminate the PostScript input, or it will ignore it as an unrecognised switch (probably the latter). The '1.5' ought to be the input filename, without that Ghostscript doesn't know which file to use..... Even if it did, it will try to write the output to a bogus filename.
To be honest I would suggest that, if you want to set all these switches, you simply invoke Ghostscript directly rather than trying to use the script. In fact I'd recommend that anyway, every time I look at these scripts I shudder more.
Almost everything that the ps2pdf script is doing is being overridden by your command line, or is not required in the first place.

Related

complete noob, How do I make a script to convert individual pages of a PDF as images AND save them in folders with the same name as the PDF?

For example, if I have book1.pdf and book2.pdf, I would like to create a script where the pages of the pdfs are converted to images and are saveed in their separate folders: book1 folder and book2 folder.
It's something this program does but I do not want to pay 27 bucks just for this.
I'm a complete noob when it comes to coding. I installed Ghostscript and added a printer that runs ghostscript, so now I do have the option of opening a PDF (or any document), and print using the Ghostscript printer, and it outputs the resulting images to a folder.
This is the code for printer properties->ports->arguments for this program:
-sDEVICE=jpeg -r300 -dJPEGQ=100 -o -dSAFER -sOutputFile="C:\IMAGEfiles\image%%03d.jpg" -
My goal now is to automate the system so that I can have a list of PDFs and convert their pages into images and sorted into folders based on the same name as the PDFs. Thank you
This isn't a Ghostscript question really, this is a shell script programming problem.
Since you are using C: I'm assuming you are on Windows. I'm also going to assume you have created the folders in advance.
If you then open a command shell and do :
for %s in (*.pdf) do "c:\program files\gs\gs9.52\bin\gswin64c" -sDEVICE=jpeg -r300 -dJPEGQ=100 -dBATCH -dNOPAUSE -sOutputFile=c:/%~ns/image%03d.jpg %s
That will find all the files with names of the form *.pdf, execute Ghostscript (you may have to alter the paths and executable name, it depends on the version you installed) and output the resulting JPG files to a folder whose names is the '*' part of the input filename.
Note that your original command line has both -o and -sOutputFile, you should modify it to remove one or the other. -o is supposed to be followed by the name of the output file and includes -dBATCH and -dNOPAUSE all wrapped up as one. Whereas -sOutputFile= just sets the output filename. Using both is a bad idea, if it works I'm surprised, and it certainly wouldn't surprise me if it stopped working at some point, or had unexpected side effects.

How to append output file name using input file name without extention while using ghostscript?

I'm using GS to "compress" PDF with 2 clicks. I've added a context menu in windows register with abovementioned code.
For instance if I use it on test.pdf the output file will be test.pdf-compressed.pdf. It works, but I would like to get rid of extention in the filename. Is there any way to do so?
I've tryied to use cmd arguments, but it does not seem to work with the postscript.
C:\Program Files\gs\gs9.27\bin\gswin64c.exe -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dCompatibilityLevel=1.4 -sOutputFile=%1%-compressed.pdf -c .setpdfwrite -f %1
This isn't a Ghostscript question. If you get the arguments correct then the parameters passed to Ghostscript will be correct and the output file will be what you want.
You haven't said what you've tried, so that makes it pretty hard to make suggestions. However you should be able to use %~dp1 and/or %~n1 instead of simply %1 to expand to just a path or file. There are other variations, typing "help for" at the Windows command line will give you more details.
Note as always that Ghostscript does not compress PDF files, by using -dPDFSETTINSG=/ebook you are producing a brand-new PDF file which has altered the content from the original (image will be downsampled for example).
Also the sequence -c .setpdfwrite -f has been redundant for years, you don't need it.
[EDIT]
This batch file demonstrates the use of the command shell variable expansion in a batch file
#ECHO OFF
ECHO Input file is %1
ECHO Input directory is %~dp1
\ghostpdl\debugbin\gswin32c -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=%~dp1\new.pdf %1
When saved as test.bat and then test d:\temp\input.ps the following output is generated:
Input file is d:\temp\input.ps
Input directory is d:\temp\
GPL Ghostscript GIT PRERELEASE 9.28 (2019-04-04)
Copyright (C) 2019 Artifex Software, Inc. All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
And a file new.pdf is created in the directory d:\temp
So the variable expansion works as expected, because it happens before the command line is executed.
If it still doesn't work for you, then you're going to have to provide more information. In your place I would start by removing the -dNOPAUSE and -dBATCH switches from the command line, at least that way you'll be able to see if Ghostscript is trying to tell you something.
I've clearly stumbled upon this posting a bit late.
However, I wanted to post my answer in case someone comes looking for a solution to a similar issue, in the future.
I started by creating a new Folder on my Desktop, titled "PDF", in which I placed the "test.pdf" File.
I then created a .BAT File, titled "CompressPDF.bat", to which I added the Script below.
This Script will Loop through and Compress Any/All .PDF Files, that are placed in the "PDF" Folder.
It then correctly appends the "-compressed.pdf" string to the File Name, thereby saving the "test.pdf" File as "test-compressed.pdf", per the request of the OP.
As you will Notice, I have Added the "PAUSE" Command at the very end of the Script.
This will keep the Window from Automatically Closing until you Press Any Key, which will allow you to review any Errors that may have arisen, during the compression process.
#echo off
cd "%USERPROFILE%\Desktop\PDF"
for %%f in (*.pdf) do (
gswin64c.exe -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="%%~nf-compressed.pdf" "%%f"
)
PAUSE
I hope this post is able to help others, who may be looking for an answer to a similar issue.
Please, feel free to response or to reach out to me, if anyone has any questions, as I am always happy to help.

Imagemagick error using overlapcrop on Window with Cygwin

I am using Imageimagick to crop arieal images in equal sizes.
Searching Google imagemagick tutorials led me to Fred Weinhaus scripts tutorial which I followed. When I am passing the command on bash or cmd based on syntax given in this website (bash /fullpathto/scriptname.sh with arguments /fullpathto/inputimage /fullpathto/outputimage)
I am getting error
$ overlapcrop -s 128 -o 50% -m matrix -M -L \
-R 'F:\bash\top_potsdam_2_10_RGB' 'F:\bash\o.jpg'
error Invalid Parameter - F:\bash\top_potsdam_2_10_RGB
FILE F:\bash\top_potsdam_2_10_RGB DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE
Even if we set the directory in the path, we get the same error:
$ overlapcrop -s 128 -o 50% -m matrix -M -L -R top_potsdam_2_10_RGB.png o.png
--Screenshots of imagemagick --help and convert --help
error I am getting
Windows is useless when it comes to quoting, so maybe try escaping the % sign by adding a second one or a caret (^) in front of it.
Also, try removing the F: from the paths and try putting the files in the current directory in case the slashes are causing errors.
Finally, you may have your PATH set incorrectly so that when the script executes the convert command it finds the Windows utility that converts filesystems to NTFS rather than the ImageMagick utility that converts images.
Try running:
convert /?
and seeing if you get an error/help message from Windows CONVERT.EXE or something from ImageMagick. If you get the Windows one, your PATH is incorrect and you need to put the directory where you installed ImageMagick ahead (in front of) C:\WINDOWS\System32 or wherever Windows CONVERT.EXE lives and restart your Command Prompt window.

Linux unable to open X server

I am creating some images using the following script. The script runs and creates the file. However I am getting an error. If I ssh into the server using the -Y it I do not receive the error.
gs -sDEVICE=pngalpha -sOutputFile=/home/pi/my_image.png -q -r200 -g200x100 -
display: unable to open X server `' # error/display.c/DisplayImageCommand/426
I am using perl and I did set the EVN{DISPLAY}'"0.0" still errors. However I actually don't want to display the file. Only create them and store the file in the /home/pi/ directory.
Try adding -dSAFER -dBATCH -dNOPAUSE to the options. These are standard best-practice flags to use when outputting to file.

Untar multipart tarball on Windows

I have a series of files named filename.part0.tar, filename.part1.tar, … filename.part8.tar.
I guess tar can create multiple volumes when archiving, but I can't seem to find a way to unarchive them on Windows. I've tried to untar them using 7zip (GUI & commandline), WinRAR, tar114 (which doesn't run on 64-bit Windows), WinZip, and ZenTar (a little utility I found).
All programs run through the part0 file, extracting 3 rar files, then quit reporting an error. None of the other part files are recognized as .tar, .rar, .zip, or .gz.
I've tried concatenating them using the DOS copy command, but that doesn't work, possibly because part0 thru part6 and part8 are each 100Mb, while part7 is 53Mb and therefore likely the last part. I've tried several different logical orders for the files in concatenation, but no joy.
Other than installing Linux, finding a live distro, or tracking down the guy who left these files for me, how can I untar these files?
Install 7-zip. Right click on the first tar. In the context menu, go to "7zip -> Extract Here".
Works like a charm, no command-line kung-fu needed:)
EDIT:
I only now noticed that you mention already having tried 7zip. It might have balked if you tried to "open" the tar by going "open with" -> 7zip - Their command-line for opening files is a little unorthodox, so you have to associate via 7zip instead of via the file association system built-in to windows. If you try the right click -> "7-zip" -> "extract here", though, that should work- I tested the solution myself (albeit on a 32-bit Windows box- Don't have a 64 available)
1) download gzip http://www.gzip.org/ for windows and unpack it
2) gzip -c filename.part0.tar > foo.gz
gzip -c filename.part1.tar >> foo.gz
...
gzip -c filename.part8.tar >> foo.gz
3) unpack foo.gz
worked for me
As above, I had the same issue and ran into this old thread. For me it was a severe case of RTFM when installing a Siebel VM . These instructions were straight from the manual:
cat \
OVM_EL5U3_X86_ORACLE11G_SIEBEL811ENU_SIA21111_PVM.tgz.1of3 \
OVM_EL5U3_X86_ORACLE11G_SIEBEL811ENU_SIA21111_PVM.tgz.2of3 \
OVM_EL5U3_X86_ORACLE11G_SIEBEL811ENU_SIA21111_PVM.tgz.3of3 \
| tar xzf –
Worked for me!
The tar -M switch should it for you on windows (I'm using tar.exe).
tar --help says:
-M, --multi-volume create/list/extract multi-volume archive
I found this thread because I had the same problem with these files. Yes, the same exact files you have. Here's the correct order: 042358617 (i.e. start with part0, then part4, etc.)
Concatenate in that order and you'll get a tarball you can unarchive. (I'm not on Windows, so I can't advise on what app to use.) Note that of the 19 items contained therein, 3 are zip files that some unarchive utilities will report as being corrupted. Other apps will allow you to extract 99% of their contents. Again, I'm not on Windows, so you'll have to experiment for yourself.
Enjoy! ;)
This works well for me with multivolume tar archives (numbered .tar.1, .tar.2 and so on) and even allows to --list or --get specific folders or files in them:
#!/bin/bash
TAR=/usr/bin/tar
ARCHIVE=bkup-01Jun
RPATH=home/user
RDEST=restore/
EXCLUDE=.*
mkdir -p $RDEST
$TAR vf $ARCHIVE.tar.1 -F 'echo '$ARCHIVE'.tar.${TAR_VOLUME} >&${TAR_FD}' -C $RDEST --get $RPATH --exclude "$EXCLUDE"
Copy to a script file, then just change the parameters:
TAR=location of tar binary
ARCHIVE=Archive base name (without .tar.multivolumenumber)
RPATH=path to restore (leave empty for full restore)
RDEST=restore destination folder (relative or absolute path)
EXCLUDE=files to exclude (with pattern matching)
Interesting thing for me is you really DON'T use the -M option, as this would only ask you questions (insert next volume etc.)
Hello perhaps would help.
I had the same problems ...
a save on my web site made automaticaly in Centos at 4 am create multiple file in multivolume tar format (saveblabla.tar, saveblabla.tar1.tar, saveblabla.tar2.tar,etc..)
after downloading this file on my PC (windows) i can't extract them with both windows cmd or 7zip (unknow error).
I thirst binary copy file to reassemble tar files. (above in that thread)
copy /b file1+file2+file3 destination
after that, 7zip worked !!! Thanks for you help

Resources