ho-tex / pdfcrop

pdfcrop perl utility
LaTeX Project Public License v1.3c
25 stars 6 forks source link

Improving ghostscript detection (windows) #2

Open pablgonz opened 4 years ago

pablgonz commented 4 years ago

To do the tests I used

perl pdfcrop.pl --debug tests/version-test.pdf

The output under msys without having gs in PATH:

PDFCROP 1.40, 2020/06/06 - Copyright (c) 2002-2020 by Heiko Oberdiek, Oberdiek Package Support Group.
* Restricted mode: disabled
* Option `pdfversion': auto
* Perl executable: perl
* Perl version: v5.30.2
* Pointer size: 8
* Pipe support: yes
* Fork support: yes
* OS name: msys
* Arch name: x86_64-msys-thread-multi
* System: msys
* Not found (gswin32c): /c/Users/pablo/bin/gswin32c.exe
* Not found (gswin32c): /mingw64/bin/gswin32c.exe
* Not found (gswin32c): /usr/local/bin/gswin32c.exe
* Not found (gswin32c): /usr/bin/gswin32c.exe
* Not found (gswin32c): /bin/gswin32c.exe
* Not found (gswin32c): /mingw64/bin/gswin32c.exe
* Not found (gswin32c): /usr/bin/gswin32c.exe
* Not found (gswin32c): /c/Users/pablo/bin/gswin32c.exe
* Not found (gswin32c): /c/Windows/system32/gswin32c.exe
* Not found (gswin32c): /c/Windows/gswin32c.exe
* Not found (gswin32c): /c/Windows/System32/Wbem/gswin32c.exe
* Not found (gswin32c): /c/Windows/System32/WindowsPowerShell/v1.0/gswin32c.exe
* Not found (gswin32c): /c/Windows/System32/OpenSSH/gswin32c.exe
* Not found (gswin32c): /c/ProgramData/chocolatey/bin/gswin32c.exe
* Not found (gswin32c): /c/Strawberry/c/bin/gswin32c.exe
* Not found (gswin32c): /c/Strawberry/perl/site/bin/gswin32c.exe
* Not found (gswin32c): /c/Strawberry/perl/bin/gswin32c.exe
* Not found (gswin32c): /cmd/gswin32c.exe
* Not found (gswin32c): /c/tools/BCURRAN3/gswin32c.exe
* Not found (gswin32c): /c/Users/pablo/AppData/Local/Microsoft/WindowsApps/gswin32c.exe
* Not found (gswin32c): /c/texlive/2020/bin/win32/gswin32c.exe
* Not found (gswin32c): /d/jdk/bin/gswin32c.exe
* Not found (gswin32c): /usr/bin/vendor_perl/gswin32c.exe
* Not found (gswin32c): /usr/bin/core_perl/gswin32c.exe
* Not found (gswin64c): /c/Users/pablo/bin/gswin64c.exe
* Not found (gswin64c): /mingw64/bin/gswin64c.exe
* Not found (gswin64c): /usr/local/bin/gswin64c.exe
* Not found (gswin64c): /usr/bin/gswin64c.exe
* Not found (gswin64c): /bin/gswin64c.exe
* Not found (gswin64c): /mingw64/bin/gswin64c.exe
* Not found (gswin64c): /usr/bin/gswin64c.exe
* Not found (gswin64c): /c/Users/pablo/bin/gswin64c.exe
* Not found (gswin64c): /c/Windows/system32/gswin64c.exe
* Not found (gswin64c): /c/Windows/gswin64c.exe
* Not found (gswin64c): /c/Windows/System32/Wbem/gswin64c.exe
* Not found (gswin64c): /c/Windows/System32/WindowsPowerShell/v1.0/gswin64c.exe
* Not found (gswin64c): /c/Windows/System32/OpenSSH/gswin64c.exe
* Not found (gswin64c): /c/ProgramData/chocolatey/bin/gswin64c.exe
* Not found (gswin64c): /c/Strawberry/c/bin/gswin64c.exe
* Not found (gswin64c): /c/Strawberry/perl/site/bin/gswin64c.exe
* Not found (gswin64c): /c/Strawberry/perl/bin/gswin64c.exe
* Not found (gswin64c): /cmd/gswin64c.exe
* Not found (gswin64c): /c/tools/BCURRAN3/gswin64c.exe
* Not found (gswin64c): /c/Users/pablo/AppData/Local/Microsoft/WindowsApps/gswin64c.exe
* Not found (gswin64c): /c/texlive/2020/bin/win32/gswin64c.exe
* Not found (gswin64c): /d/jdk/bin/gswin64c.exe
* Not found (gswin64c): /usr/bin/vendor_perl/gswin64c.exe
* Not found (gswin64c): /usr/bin/core_perl/gswin64c.exe
* Search Ghostscript in Windows registry under msys:
* Registry entry found for GS_DLL (64 bits version)
* Add /c/Program Files/gs/gs9.52/bin to PATH for current session
* Found (via reg query): gswin64c
* Autodetected ghostscript command: gswin64c
* Input file: tests/version-test.pdf
* Output file: tests/version-test-crop.pdf
* Margins: 0 0 0 0
* PDF header: %PDF-2.0
* Using PDF version: 2.0
* Running ghostscript for BoundingBox calculation ...
* Ghostscript call: gswin64c -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f tests/version-test.pdf
GPL Ghostscript 9.52 (2020-03-19)
Copyright (C) 2020 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.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 149 139 308 715
* Page 1: 149 139 308 715
%%HiResBoundingBox: 149.003995 139.247996 307.295991 714.023978
* Running pdfTeX ...
* pdfTeX call: pdftex -no-shell-escape -interaction=nonstopmode tmp-pdfcrop-1229
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=pdftex)
entering extended mode
(./tmp-pdfcrop-1229.tex [1 <./tests/version-test.pdf>] )
Output written on tmp-pdfcrop-1229.pdf (1 page, 11071 bytes).
Transcript written on tmp-pdfcrop-1229.log.
==> 1 page written on `tests/version-test-crop.pdf'.
* Cleanup
* Temporary files: tmp-pdfcrop-1229.tex tmp-pdfcrop-1229.log

The output under msys having gs in PATH:

PDFCROP 1.40, 2020/06/06 - Copyright (c) 2002-2020 by Heiko Oberdiek, Oberdiek Package Support Group.
* Restricted mode: disabled
* Option `pdfversion': auto
* Perl executable: perl
* Perl version: v5.30.2
* Pointer size: 8
* Pipe support: yes
* Fork support: yes
* OS name: msys
* Arch name: x86_64-msys-thread-multi
* System: msys
* Not found (gswin32c): /c/Users/pablo/bin/gswin32c.exe
* Not found (gswin32c): /mingw64/bin/gswin32c.exe
* Not found (gswin32c): /usr/local/bin/gswin32c.exe
* Not found (gswin32c): /usr/bin/gswin32c.exe
* Not found (gswin32c): /bin/gswin32c.exe
* Not found (gswin32c): /mingw64/bin/gswin32c.exe
* Not found (gswin32c): /usr/bin/gswin32c.exe
* Not found (gswin32c): /c/Users/pablo/bin/gswin32c.exe
* Not found (gswin32c): /c/Windows/system32/gswin32c.exe
* Not found (gswin32c): /c/Windows/gswin32c.exe
* Not found (gswin32c): /c/Windows/System32/Wbem/gswin32c.exe
* Not found (gswin32c): /c/Windows/System32/WindowsPowerShell/v1.0/gswin32c.exe
* Not found (gswin32c): /c/Windows/System32/OpenSSH/gswin32c.exe
* Not found (gswin32c): /c/ProgramData/chocolatey/bin/gswin32c.exe
* Not found (gswin32c): /c/Strawberry/c/bin/gswin32c.exe
* Not found (gswin32c): /c/Strawberry/perl/site/bin/gswin32c.exe
* Not found (gswin32c): /c/Strawberry/perl/bin/gswin32c.exe
* Not found (gswin32c): /cmd/gswin32c.exe
* Not found (gswin32c): /c/tools/BCURRAN3/gswin32c.exe
* Not found (gswin32c): /c/Users/pablo/AppData/Local/Microsoft/WindowsApps/gswin32c.exe
* Not found (gswin32c): /c/texlive/2020/bin/win32/gswin32c.exe
* Not found (gswin32c): /d/jdk/bin/gswin32c.exe
* Not found (gswin32c): /c/Program Files/gs/gs9.52/bin/gswin32c.exe
* Not found (gswin32c): /usr/bin/vendor_perl/gswin32c.exe
* Not found (gswin32c): /usr/bin/core_perl/gswin32c.exe
* Not found (gswin64c): /c/Users/pablo/bin/gswin64c.exe
* Not found (gswin64c): /mingw64/bin/gswin64c.exe
* Not found (gswin64c): /usr/local/bin/gswin64c.exe
* Not found (gswin64c): /usr/bin/gswin64c.exe
* Not found (gswin64c): /bin/gswin64c.exe
* Not found (gswin64c): /mingw64/bin/gswin64c.exe
* Not found (gswin64c): /usr/bin/gswin64c.exe
* Not found (gswin64c): /c/Users/pablo/bin/gswin64c.exe
* Not found (gswin64c): /c/Windows/system32/gswin64c.exe
* Not found (gswin64c): /c/Windows/gswin64c.exe
* Not found (gswin64c): /c/Windows/System32/Wbem/gswin64c.exe
* Not found (gswin64c): /c/Windows/System32/WindowsPowerShell/v1.0/gswin64c.exe
* Not found (gswin64c): /c/Windows/System32/OpenSSH/gswin64c.exe
* Not found (gswin64c): /c/ProgramData/chocolatey/bin/gswin64c.exe
* Not found (gswin64c): /c/Strawberry/c/bin/gswin64c.exe
* Not found (gswin64c): /c/Strawberry/perl/site/bin/gswin64c.exe
* Not found (gswin64c): /c/Strawberry/perl/bin/gswin64c.exe
* Not found (gswin64c): /cmd/gswin64c.exe
* Not found (gswin64c): /c/tools/BCURRAN3/gswin64c.exe
* Not found (gswin64c): /c/Users/pablo/AppData/Local/Microsoft/WindowsApps/gswin64c.exe
* Not found (gswin64c): /c/texlive/2020/bin/win32/gswin64c.exe
* Not found (gswin64c): /d/jdk/bin/gswin64c.exe
* Found (gswin64c): /c/Program Files/gs/gs9.52/bin/gswin64c.exe
* Autodetected ghostscript command: gswin64c
* Input file: tests/version-test.pdf
* Output file: tests/version-test-crop.pdf
* Margins: 0 0 0 0
* PDF header: %PDF-2.0
* Using PDF version: 2.0
* Running ghostscript for BoundingBox calculation ...
* Ghostscript call: gswin64c -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f tests/version-test.pdf
GPL Ghostscript 9.52 (2020-03-19)
Copyright (C) 2020 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.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 149 139 308 715
* Page 1: 149 139 308 715
%%HiResBoundingBox: 149.003995 139.247996 307.295991 714.023978
* Running pdfTeX ...
* pdfTeX call: pdftex -no-shell-escape -interaction=nonstopmode tmp-pdfcrop-831
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=pdftex)
entering extended mode
(./tmp-pdfcrop-831.tex [1 <./tests/version-test.pdf>] )
Output written on tmp-pdfcrop-831.pdf (1 page, 11071 bytes).
Transcript written on tmp-pdfcrop-831.log.
==> 1 page written on `tests/version-test-crop.pdf'.
* Cleanup
* Temporary files: tmp-pdfcrop-831.tex tmp-pdfcrop-831.log

The output under cygwin:

PDFCROP 1.40, 2020/06/06 - Copyright (c) 2002-2020 by Heiko Oberdiek, Oberdiek Package Support Group.
* Restricted mode: disabled
* Option `pdfversion': auto
* Perl executable: /usr/bin/perl
* Perl version: v5.30.3
* Pointer size: 8
* Pipe support: yes
* Fork support: yes
* OS name: cygwin
* Arch name: x86_64-cygwin-threads-multi
* System: cygwin
* Not found (gs): /usr/local/bin/gs.exe
* Found (gs): /usr/bin/gs.exe
* Autodetected ghostscript command: gs
* Input file: tests/version-test.pdf
* Output file: tests/version-test-crop.pdf
* Margins: 0 0 0 0
* PDF header: %PDF-2.0
* Using PDF version: 2.0
* Running ghostscript for BoundingBox calculation ...
* Ghostscript call: gs -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f tests/version-test.pdf
GPL Ghostscript 9.52 (2020-03-19)
Copyright (C) 2020 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.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 149 139 308 715
* Page 1: 149 139 308 715
%%HiResBoundingBox: 149.003995 139.247996 307.295991 714.023978
* Running pdfTeX ...
* pdfTeX call: pdftex -no-shell-escape -interaction=nonstopmode tmp-pdfcrop-759
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=pdftex)
entering extended mode
(./tmp-pdfcrop-759.tex [1 <./tests/version-test.pdf>] )
Output written on tmp-pdfcrop-759.pdf (1 page, 11071 bytes).
Transcript written on tmp-pdfcrop-759.log.
==> 1 page written on `tests/version-test-crop.pdf'.
* Cleanup
* Temporary files: tmp-pdfcrop-759.tex tmp-pdfcrop-759.log

I have left in comments the changes I have added, the changes only affect users who use perl pdfcrop and not those who use the direct version provided in TeXLive.

You can remove the detection of some old architectures (dos, os2) and some executable names for gs (gsc, gs386, gsos2), but, I don't know what level of backwards compatibility you want to have.

One thing I didn't manage to test was to remove gs from the list of ghostscript executable names for miktex (and windows), if anyone has miktex they might be able to do the test.

pablgonz commented 4 years ago

Now the idea is complete, the detection proposed under git win is to be able to make some tests on the script using l3build, I put a quite simple example (just to understand the idea). (I tried to create a temporary directory, but, it behaved differently in win/linux and didn't allow me to use run)