milahu / nixpkgs

Nix Packages collection
MIT License
1 stars 0 forks source link

ghostscript with setpdfwrite setdistillerparams: Error: /undefined in .setpdfwrite #9

Open milahu opened 1 year ago

milahu commented 1 year ago

im trying to use ghostscript to compress a PDF file but when i add the option -c ".setpdfwrite <</AlwaysEmbed [ ]>> setdistillerparams" then ghostscript throws Error: /undefined in .setpdfwrite

so either a compile-time feature of ghostscript is missing or a runtime dependency is missing

based on https://stackoverflow.com/questions/10450120/optimize-pdf-files

$ gs -sDEVICE=pdfwrite -o output.pdf -c ".setpdfwrite <</AlwaysEmbed [ ]>> setdistillerparams" -f input.pdf

GPL Ghostscript 10.01.1 (2023-03-27)
Copyright (C) 2023 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.
Error: /undefined in .setpdfwrite
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:768/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 10.01.1: Unrecoverable error, exit code 1

what causes the No such file or directory error?

strace

strace -f gs -sDEVICE=pdfwrite -o output.pdf -c ".setpdfwrite <</AlwaysEmbed [ ]>> setdistillerparams" -f input.pdf 2>&1 | less -S 

many "no such file" errors for the file Decoding/Unicode, which is provided by ghostscriptX in nixpkgs

$ nix-locate Decoding/Unicode
ghostscriptX.out                                137,541 r /nix/store/gczfw2iqzp95b4dlggvj87d03mciia0z-ghostscript-9.53.3/share/ghostscript/9.53.3/Resource/Decoding/Unicode

but ghostscriptX fails too

Error: /undefined in .setpdfwrite
Last OS error: Resource temporarily unavailable