3

I have a postscript file of a poster made in latex, and want to convert this to a pdf (I'm using ubuntu)

I am using ps2pdf but if possible I would like to remove the first, blank page, and keep only the second page.

Is there a command that allows this? Been trying to find one for longer than would seem sensible!

Thanks!

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
anthr
  • 1,026
  • 4
  • 17
  • 34

3 Answers3

4

First convert to PDF the complete file with whatever tool you prefer. (For quality output I would not use ps2pdf which is only a shortcut to run a fully fledged Ghostscript commandline. I would use the appropriate Ghostscript commandline directly, because it gives greater and direct control over all the parameters used. But it needs some GS expertise to use...).

Then, to extract the second page only, you have two options:

  1. pdftk (PDF ToolKit from here)
  2. gs (Ghostscript from here)

pdftk commandline:

pdftk \
  A=/path/to/input.pdf \
  cat A2 \
  output /path/to/page2-from-input.pdf

gs commandline:

gs \
  -o /path/to/output.pdf \
  -sDEVICE=pdfwrite \
  -dFirstPage=2 \
  -dLastPage=2 \
  /path/to/input.pdf
maxjakob
  • 1,895
  • 1
  • 12
  • 7
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • Thanks very much to both of you for your responses! – anthr Sep 09 '10 at 21:27
  • @anthr: are you aware that you can "upvote"/"downvote" useful/false answers by clicking on the up/down arrows at the top left of each answer? – Kurt Pfeifle Sep 09 '10 at 22:42
  • Hi pipitas, I did try, but you need a reputation of 15 in order to do this.. almost there! – anthr Sep 15 '10 at 14:31
  • Is it possible with the gs command line to do the initial conversion from ps to pdf on just the desired page range? Do you really need to convert to pdf first and rerun gs again? – A. Webb Nov 07 '12 at 21:24
  • @A.Webb: PostScript is a programming language which requires the interpreter (in most cases of \*.ps files) to run through the complete PostScript code sequentially from the very start, before it can determine what's going to be rendered on a certain page; also, you normally cannot go backward to render the previous page. (The few cases where this does not need to be done are files conforming to the *'DSC'* requirements [Document Structuring Convention], which allows random access to pages. -- Hence, convert first to PDF, which always allows random access to pages.... – Kurt Pfeifle Nov 07 '12 at 21:42
  • @Kurt Right, I know PostScript is Turing complete, so you can't determine pages without running anymore than you can determine the halting problem. However, GS could just send some pages to the nulldevice rather than the pdfwrite based on the number of times showpage has been called. This could surely be done in a ps configuration file that redefines showpage, so I don't see why you couldn't do it on the command line. You still have to process the whole PS input of course. But, this way you wouldn't have to process the PDF file afterwards. – A. Webb Nov 07 '12 at 21:51
  • @A.Webb: the effort to implement your wish is much higher than what I proposed. After implementing your wish, the effort (measured in CPU cycles) to run the resulting commmandline is probably not much different. Your welcome to write a PS program that does what you propose, I'll happily verify or falsify my guess about the CPU cycles then :-) – Kurt Pfeifle Nov 07 '12 at 21:58
  • @Kurt Fair enough, I trust your knowledge, just wondering. Thanks for answering my follow-up questions. – A. Webb Nov 07 '12 at 22:03
0

You could use the Pdftk command line tool as a second process using the 'cat' option to only write out page 2.

http://www.pdflabs.com/docs/pdftk-man-page/

Andrew Cash
  • 2,321
  • 1
  • 17
  • 11
0

Several Linux distributions have psselect which does this. I guess it's from the psutils package.

lhf
  • 70,581
  • 9
  • 108
  • 149