Today tutorial it’s about Ghostscript under Windows 10 OS.
Ghostscript was originally written by L. Peter Deutsch for the GNU Project, and released under the GNU General Public License in 1986. This means it has been under active development for over 20 years. Also, the Ghostscript has been ported to many different systems during this time.
Download it from here and install it.
I used this version:gs918w64.
You can use the tree windows command to see the folders of this installation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | C:. ├───bin ├───doc │ └───pclxps ├───examples │ └───cjk ├───lib ├───libpng │ └───contrib │ └───examples ├───openjpeg │ └───src │ └───lib │ └───openjp2 └───zlib └───doc |
Under bin folder, you can see some files.
Add also under Windows system variable, this will help deal with Ghostscript and GIMP application.
The most important files come with:
GSWIN64C.EXE – this is usually the preferred executable Ghostscript as a 64-bit Windows command line program;
GSWIN64.EXE – this is a 64-bit Ghostscript using its own window for commands;
GSDLL64.DLL – the 64-bit dynamic link library containing most of Ghostscript’s functionality;
1 2 3 4 5 | C:\gs9.18\bin>gswin64c.exe GPL Ghostscript 9.18 (2015-10-05) Copyright (C) 2015 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. GS> |
Also, you can use and will see two windows for you.
One will help you to write your ghostscripts and another to see the result.
If you want to use the Ghostscript you need to go to the bin folder and use like commands.
For example:
1 | C:\gs9.18\bin>gswin64.exe -h |
I used LibreOffice to make one test pdf file and I named: my_test_forest.pdf.
I save this pdf file under bin folder and I make first tests.
1. using Ghostscript to convert file formats from PDF to JPEGs.
1 | C:\gs9.18\bin>gswin64.exe -sDEVICE=jpeg -sOutputFile=test-%d.jpeg my_test_forest.pdf |
– this will convert your pdf file like multiple images: -sOutputFile=test-%d.jpeg;
– the input file is my pdf test file: my_test_forest.pdf;
2. see a brief help message with -h or -? ;
1 | C:\gs9.18\bin>gswin64.exe -? |
– this will open one window to see the brief message
3. select b3 paper size
1 | C:\gs9.18\bin>gswin64.exe -sDEVICE=jpeg -sOutputFile=b3-%d.jpeg -sPAPERSIZE=b3 my_test_forest.pdf |
– Ghostscript is configured to use U.S. letter paper as default page size, so you can change it with -sPAPERSIZE=b3;
– if you want to use a4 the just put this command-line argument: -sPAPERSIZE=a4;
4. How to get a list of available printer devices using gswin64c.exe and devicenames ==
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | C:\gs9.18\bin>gswin64c.exe GPL Ghostscript 9.18 (2015-10-05) Copyright (C) 2015 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. GS>devicenames == [/pnggray /tiffsep1 /bmpgray /bmp32b /pgmraw /pnmraw /t4693d8 /pj /cdj550 /plibc /eps9mid /eps2write /png16 /tiffscaled /bmp16 /psdcmyk /pgnm /ppm /tek4696 /pjx l /uniprint /plibk /epsonc /txtwrite /png256 /tiffscaled8 /bmp256 /psdrgb /pgnmr aw /ppmraw /pcxmono /pjxl300 /djet500c /plan /ibmpro /pxlmono /png16m /tiffscale d24 /bmp16m /cp50 /pkmraw /pamcmyk32 /pcxgray /jetp3852 /declj250 /plang /deskje t /pxlcolor /pngalpha /tiffscaled32 /tiff12nc /gprf /tiffcrle /pamcmyk4 /pcx16 / r4081 /lj250 /planm /djet500 /xpswrite /fpng /tiffscaled4 /tiff24nc /nullpage /t iffg3 /pnmcmyk /pcx256 /lbp8 /st800 /planc /laserjet /inkcov /display /psdcmykog /bit /tiff48nc /tiffg32d /pam /pcx24b /m8510 /stcolor /plank /ljetplus /ink_cov /mswinpr2 /jpeg /bitrgb /tiffgray /tiffg4 /spotcmyk /pcxcmyk /necp6 /bj10e /lje t3 /ljet2p /bbox /ijs /jpeggray /bitcmyk /tiff32nc /tifflzw /devicen /pbm /bjc60 0 /bj200 /ljet3d /cdeskjet /plib /mswindll /jpegcmyk /pngmono /tiff64nc /tiffpac k /bmpsep1 /pbmraw /bjc800 /t4693d2 /ljet4 /cdjcolor /plibg /epson /pdfwrite /pn gmonod /tiffsep /bmpmono /bmpsep8 /pgm /pnm /t4693d4 /ljet4d /cdjmono /plibm /ep s9high /ps2write] GS> |
– this output can be used with -sDEVICE= argument;
5. make and run one script with Ghostscript
– create one file and named test.ps then add this:
1 2 3 4 5 6 | %! /Helvetica findfont 32 scalefont setfont 10 700 moveto (Hello, world from http://free-tutorials.org!) show showpage |
– run this command:
1 | gswin64c.exe test.ps |
– the output will be like this:
– this %! will start the script;
– the next line: the … 32 scalefont setfont will find and set the Helvetica font;
– the next step moves the current point from the left and bottom edges of the page;
– the fourth line draws the text into the page bitmap at the current point;
– the last line of script display the result;
6. another way to run your scripts
– just use your name script and run the command like this:
1 | GS>(test.ps) run |
– the test.ps it’s the name of my script I make it;
7. make a shape with
– this will make one triangle;
1 2 3 4 5 6 7 8 9 10 | C:\gs9.18\bin>gswin64c.exe GPL Ghostscript 9.18 (2015-10-05) Copyright (C) 2015 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. GS>newpath GS>10 10 moveto GS>100 10 lineto GS>50 100 lineto GS>closepath stroke GS> |
– create a path , make lines close path and show outline;
– you can also use: showpage to print everything;
8. difficulties of learning stack can be solved with this simple example:
– I start gswin64c and then I type this: 2 7 8 stack = = = stack
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | C:\gs9.18\bin>gswin64c.exe GPL Ghostscript 9.18 (2015-10-05) Copyright (C) 2015 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. GS>2 GS7 GS8 GSstack 8 7 2 GS= 8 GS= 7 GS= 2 GS>stack GS> |
– you can see how the stack is upload with numbers the show us with stack and =
9. combine pdf files into one
– just add your pdf files on input;
– set the output pdf, in this case, all.pdf
1 2 | C:\gs9.18\bin>gswin64c.exe -sDEVICE=pdfwrite -sOutputFile=all.pdf first.pdf seco nd.pdf third.pdf |
– you can use any type of your file: .pdf, .eps, .ps;
10. quit closing Ghostscript.
– just type quit, like this:
1 | GS>quit |
I will come with examples and tutorials about Ghostscript under Windows 10 and Linux OS.