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

房东的猫 提交于 2019-12-06 12:35:51

问题


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:

... 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!


回答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...




回答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:

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!



来源:https://stackoverflow.com/questions/11092065/using-ghostscript-as-x11-viewer-gs-x11-viewport-positioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!