Hi all,

from what I understand the "psselect" command is used by the groff html
preprocessor to extract *a single page* from a multi-page Postscript
document. I think the same could be achieved using ghostscript,
which groff already depends on and uses.
Note that I know little about psutils, ghostscript, and Postscript,
so please take the following with a block rather than a grain of salt.

> If someone knows of a replacement for psselect, possibly in a more
> widely deployed and used package, we could conceivably transition to it.
> This would require some testing.

First tests (see minimal working example (MWE) below) suggest that
psselect can be replaced with ghostscript's ps2ps or gs command.

Would replacing the following in src/preproc/html/pre-html.cpp
  s = make_string("psselect -q -p%d %s %s\n",
       pageno, psFileName, psPageName);

with
  s = make_string("ps2ps -dFirstPage=%1$d -dLastPage=%1$d %s %s\n",
       pageno, psFileName, psPageName);

or
  s = make_string("echo showpage | "
      "%s%s -q -dBATCH -dSAFER "
      "-dFirstPage=%3$d -dLastPage=%3$d "
      "-sDEVICE=ps2write "
      "-sOutputFile=%s %s\n",
      image_gen,
      EXE_EXT,
      pageno,
      psPageName,
      psFileName);

seem feasible for a medium or even short term transition if the
suggested commands are a worthy equivalent for how psselect is used
in groff?

Please find attached a Makefile as a MWE that:
  - generates a multi-page Postscript document using groff
  - extracts a page using psselect writing it to psselect-psPageName.ps
  - extracts a page using ps2ps writing it to ps2ps-psPageName.ps
  - extracts a page using gs writing it to psPageName.ps

The MWE requires make, seq, groff, ghostscript, and psselect.
The support for pdf conversion is added for those who have the
(mis)fortune of working on macOS, which sadly has removed support
for PostScript.

Best
Alexis
PAGENO := 3

TOTAL_PAGES := 9

all: psPageName.pdf

# Extract page PAGENO from the multi-page example document psFileName.ps
psPageName.ps: psFileName.ps
        @# This command is currently used in groff's html preprocessor (see 
pre-html.cpp).
        psselect -q -p${PAGENO} $< psselect-$@
        
        @# This command is a psselect replacement using ghostscript's ps2ps.
        ps2ps -dFirstPage=${PAGENO} -dLastPage=${PAGENO} $< ps2ps-$@
        
        @# This command is a psselect replacement using a ghostscript based
        @# pipeline similar to what is already being used in groff's html
        @# preprocessor.
        echo showpage \
                | gs -q -dBATCH -dSAFER -dFirstPage=${PAGENO} 
-dLastPage=${PAGENO} \
                  -sDEVICE=ps2write -sOutputFile=$@ $<

# Generate an multi-page example document
# to extract a single page from.
psFileName.ps:
        seq ${TOTAL_PAGES} \
                | awk '\
                        BEGIN {print ".ce 99\n.ps 24\n.vs 32"} \
                        {print "Page", NR "\n.bp"} \
                        END {print "Page", NR+1 "\n.ex"}' \
                | groff -Tps - > $@

# Convert Postscript to PDF
%.pdf: %.ps
        ps2pdf $< $@

Reply via email to