Using ghostscript as an x11 viewer (gs x11 viewport positioning)?

I already know about Ghostscript front end viewers; but I was wondering how gs can be used to view PDF documents?

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

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

... which leads to something like:

ghostscript-viewing.png

... that, in fact, everything is good - in addition, it starts in the lower left corner; and there are no shortcuts (as far as I can see) here to move the viewport or perform some scaling.

I know that ghostscipt probably has no mouse and keyboard interaction to navigate the x11 output window, given that something like this is reserved for external users like gv . So, the closest to this (for me) in ghostscript will be - how to display a specific region of a page? Through -d and -r most important parameters are already indicated - I just want, say, to specify a different point than 0x0 (say, x = 100 y = 100), as the lower left corner when viewing.

(In other words, I would like to say ghostscript : show page 3 of document.pdf, rasterized to 150x150, in a window 500x500 in size, starting from the bottom left corner x, y = 100,100).

How can this be done in ghostscript ? Are there any command line keys for this - or will I need to use postscript language commands in the terminal as soon as ghostscript loads?

Thanks a lot in advance for any answers,
Hurrah!

+2
source share
2 answers

No, AFAIK, Ghostscript itself does not provide what you want ("view"). This is exactly what the ghostview and gv GUIs are for.

Ghostscript treats the x11 device (almost) as a print page output device, and the print pages have fixed sizes, and you also cannot move the "viewport" of the page image onto them - unless you retype them with a different setting: and then another comes into play option -c "<</PageOffset [-150 133]>> setpagedevice" ...

+1
source

OK, thanks (# 277826) ghostscript - How can I move page images in PDF files more left or right? , I see there the opportunity to use the postscript PageOffset to shift / move the viewport; thus, you can use the following command line:

 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: Error: /undefined in fontspec.pdf .

Otherwise, the output is as follows:

ghostscript-view-offset.png

So, it's nice to know, but I'm still curious if ghostscript doesn’t yet have any standard switches, which would allow this shift / movement of the viewport ...

Hope this helps someone
Hurrah!

+2
source

Source: https://habr.com/ru/post/918427/


All Articles