Bug 703147 - ps2pdf does not take into account the "%%PageOrder: Descend" or "%%Pages: 18 -1"
Summary: ps2pdf does not take into account the "%%PageOrder: Descend" or "%%Pages: 18 -1"
Status: RESOLVED WONTFIX
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 9.53.3
Hardware: PC Linux
: P4 enhancement
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-16 04:02 UTC by lockywolf
Modified: 2021-10-31 10:01 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
example ps file (254.28 KB, application/postscript)
2020-11-16 04:02 UTC, lockywolf
Details
Adobe_Distiller_result.pdf (240.03 KB, application/pdf)
2020-12-23 19:21 UTC, Ray Johnston
Details

Note You need to log in before you can comment on or make changes to this bug.
Description lockywolf 2020-11-16 04:02:01 UTC
Created attachment 20189 [details]
example ps file

Hello, honourable ghostscript developers.

I have several ps documents, created circa 1993 by "%%Creator: dvips 5.518 Copyright 1986, 1993 Radical Eye Software".

They have in common the fact that pages are ordered inversely in them, which is indicated by the following header:

%!PS-Adobe-2.0
%%Creator: dvips 5.518 Copyright 1986, 1993 Radical Eye Software
%%Title: /home/eyalk/COMM_COMP/FKNN/FKNN.dvi
%%Pages: 18 -1
%%PageOrder: Descend
%%BoundingBox: 0 0 596 842
%%EndComments
%DVIPSCommandLine: dvips /home/eyalk/COMM_COMP/FKNN/FKNN.dvi
%DVIPSSource:  TeX output 1995.08.02:0332
%%BeginProcSet: tex.pro


GV interprets this header correctly and renders the document pages in the correct order.
ps2pdf and ghostscript, however, do not do that, and, for example, 
gs -q -sDEVICE=ps2write -sOutputFile=pag%02d.ps FKNN.ps , where FKNN.ps is the file in question, generates a pdf file with reversed pages.
Can suport for such kind of ps files be added?
Comment 1 Ray Johnston 2020-11-16 05:40:45 UTC
Postscript, unlike PDF cannot be processed in any order except forward.

GV may be re-interpreting the PostScript from the last page to the first, but
Ghostscript doesn't deal with that since the input may come from a source that
cannot be positioned (seeked).

Converting the input to PDF first will yield a file that is page-independent
and can be processed in arbitrary order (to ps2write or any device). There
is an enhancement bug (IIRC) for processing PDF file pages in other than
increasing order that is not yet complete.

For raster image devices, the --saved-pages= option can be used to process all
of the pages from any source (including PostScript) and then can be emitted
from the collected command list files (clist) in arbitrary order, including
reverse.

I did confirm that --saved-pages= option works on this file with:

gs --saved-pages=begin -sDEVICE=ppmraw -o x-%d.ppm  Bug703147.ps \
   --saved-pages="print reverse"
Comment 2 lockywolf 2020-11-16 05:48:58 UTC
Is this a "wontfix" resolution, or a question?

I was thinking that ps2pdf was intended to be a "high-level" command, a front-end to a more low-level gs engine, and is such, can possibly buffer the whole input (if it is standard input), and is even more likely to be launched with two file names as arguments.

If the typical use-case is to convert streams of data, this request is probably out of place.
Comment 3 Ray Johnston 2020-12-23 19:21:40 UTC
Created attachment 20389 [details]
Adobe_Distiller_result.pdf
Comment 4 Peter Cherepanov 2020-12-25 01:44:24 UTC
Since Acrobat Distiller does not honor these comments, implementing them in Ghostscript would deviate from industry practice. The PDF can be post-processed with a separate tool to change the page order if truly necessary; I recommend closing this bug.
Comment 5 Ray Johnston 2020-12-25 17:31:05 UTC
I tend to concur with Peter, that we should close this, but passing it along
to one of the pdfwrite developers to see if they want to implement this
(possible since pdfwrite collects all of the pages before emitting the actual
PDF).

I also marked it as enhancement.