2

I already know about Ghostscript front end viewers; but I was wondering how gs itself could be used for viewing PDF documents?

The closest I could get to, is to specify explicitly x11 window as output device, specify width and height of the window via -g, and specify rasterization resolution via -r; or, a command line like this:

gs -sDevice=x11 -g500x500 -r150x150 -dFirstPage=3 fontspec.pdf

... which results with something like:

ghostscript-viewing.png

... which is, in fact, all good - except, it starts at lower left corner; and there are no keyboard shortcuts (as far as I can see) here to move the viewport, or to perform some zooming.

I'm aware that ghostscipt probably doesn't have mouse/keyboard interaction for navigating a x11 window output, given that something like that is reserved for front-end viewers like gv. So, the closest thing to that (for me) in ghostscript would be - how to render a specific region of a page? Via -d and -r the most important parameters are already specified - I'd just want to, say, specify a different point than 0x0 (say, x=100 y=100) as a lower left corner when viewing.

(In other words, I'd like to say to ghostscript: show page 3 of document.pdf, rasterized at 150x150, in a window of 500x500, starting from lower-left corner x,y=100,100).

How can this be done in ghostscript? Are there command line switches for that - or would one have to use postscript language commands in terminal, once ghostscript has loaded?

Many thanks in advance for any answers,
Cheers!

sdaau
  • 36,975
  • 46
  • 198
  • 278
  • 1
    Not sure this is a programming question, at all ... – unwind Jun 19 '12 at 14:39
  • Thanks for the comment, @unwind - I think it has aspects of a programming question, in that one cannot understand why `gs` isn't really a viewer, unless one understands it as a PostScript language interpreter (which I often forget); but otherwise I wouldn't have a problem with the post being moved to say SuperUser... Cheers! (PS: edited title too) – sdaau Jun 19 '12 at 14:41
  • @sdaau postscript is a programming language and the question: "What is the post-script command to move the text when printing." is certainly a programming question. That said, I very much like the extra detail about what you're really trying to do and the same question has been bothering me for a while. Good Question. – ebyrob Jun 10 '18 at 12:13

2 Answers2

2

OK, thanks to (#277826) ghostscript - How can I shift page images in PDF files more to the left or to the right?, I can see there is possibility to use postscript's PageOffset command/operator to achieve offset/displacement of the viewport; thus the following command line can be used:

gs -sDevice=x11 -g500x500 -r150x150 -dFirstPage=3 -c '<</PageOffset [-150 133]>> setpagedevice' -f fontspec.pdf

Note that, unlike the command line in OP - here you must use the -f switch to specify the input file here - if not, the command will fail with: Error: /undefined in fontspec.pdf.

Otherwise, the output looks like this:

ghostscript-view-offset.png

So this is nice to know - but I'm still curious if ghostscript doesn't already have some default switches, that would allow this viewport offset/repositioning thing...

Hope this helps someone,
Cheers!

Community
  • 1
  • 1
sdaau
  • 36,975
  • 46
  • 198
  • 278
  • 1
    AFAIK, Ghostscript itself doesn't provide what you want. That's what the `ghostview` and `gv` GUI frontends are for. Ghostscript treats the x11 device (almost) as a print page output device, and print pages do have fixed sizes, and you cannot move a 'viewport' of the page image on them either without re-printing them with a different setting. :-) – Kurt Pfeifle Jun 19 '12 at 09:05
  • Hey @pipitas - many thanks for your comment; that is exactly the kind of confirmation I was looking for! Actually, I think your comment answers the OP question better; so if you feel like it, please make an answer from this comment - I'll accept it (and then this answer posting of mine can remain as supplement, for reference). Thanks again - cheers! – sdaau Jun 19 '12 at 14:34
1

No, AFAIK, Ghostscript itself doesn't provide what you want (a 'viewport'). That's exactly what the ghostview and gv GUI frontends are for.

Ghostscript treats the x11 device (almost) as a print page output device, and print pages do have fixed sizes, and you cannot move a 'viewport' of the page image on them either -- unless you do re-print them with a different setting: and this is then where a differently valued -c "<</PageOffset [-150 133]>> setpagedevice" parameter comes into play...

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345