Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to set page orientation to landscape using ps2pdf on Windows?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

See Setting page orientation, where this rather convoluted text seems to say that this is impossible:

By default Ghostscript determines viewing page orientation based on the dominant text orientation on the page. Sometimes, when the page has text in several orientations or has no text at all, wrong orientation can be selected.

Acrobat Distiller parameter AutoRotatePages controls the automatic orientation selection algorithm. On Ghostscript, besides input stream, Distiller parameters can be given as command line arguments. For instance: -dAutoRotatePages=/None or /All or /PageByPage.

When there is no text on the page or automatic page rotation is set to /None an orientation value from setpagedevice is used. Valid values are: 0 (portrait), 3 (landscape), 2 (upside down), and 1 (seascape). The orientation can be set from the command line as -c "<> setpagedevice" using Ghostscript directly but cannot be set in ps2pdf. See Limitations below.

Ghostscript passes the orientation values from DSC comments to pdfwrite driver but they are effectively ignored there. This appears to be consistent with Distiller 5 behavior.

share|improve this answer

ps2pdf is a rather limited utility. It is merely a small batch file (on Unix/Linux: a shell script) which constructs and calls the rather complex Ghostscript commandline while itself using a very simple commandline syntax.

If you need the full power of Ghostscript, you'd be better off calling gswin32c.exe directly.

OK, here is how to rotate pages with Ghostscript. However, this may not work for your intentions, because you cannot force a certain orientation for an individual page only. It relies on an internal Ghostscript algorithm that tries to rotate pages automatically, depending on the flow of text inside the PDFs:
* -dAutoRotatePages=/None -- retains orientation of each page;
* -dAutoRotatePages=/All -- rotates all pages (or none) depending on a kind of "majority decision";
* -dAutoRotatePages=/PageByPage -- auto-rotates pages individually.

Add one of these to the Ghostscript commandline you're using.

If there is no text on a page (or if there is an automatic page rotation set to /None), then Ghostscript uses the setpagedevice settings. You can pass such setpagedevice parameters on the Ghostscript commandline using the -c switch like this:
* -c "<</Orientation 3>> setpagedevice" -- sets landscape orientation;
* -c "<</Orientation 0>> setpagedevice" -- sets portrait orientation;
* -c "<</Orientation 2>> setpagedevice" -- sets upside down orientation;
* -c "<</Orientation 1>> setpagedevice" -- sets seascape orientation.

Do you require usage of pstopdf or Ghostscript? Would it be acceptable to use another Free, Open Source Software tool running on the commandline, such as pdftk.exe?

In any case, I'd recommend to look at pdftk too (which is also available for Windows). It is a commandline tool that can rotate pages from PDFs, and much more. Easier to use than Ghostscript for your stated purpose, and much faster as well. Especially, it can rotate individual pages inside a PDF document, leaving the other pages untouched. See here for details: http://www.accesspdf.com/pdftk/ .

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.