后记:具有不同页面大小的水印 [英] Postscript: watermark with varying page sizes

查看:96
本文介绍了后记:具有不同页面大小的水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用附签为附签文件添加水印。我正在使用setpagedevice来执行此操作,例如:

I am trying to use postscript to watermark postscript files. I am doing this with setpagedevice like so:

    <<
       /EndPage {
       exch pop 2 lt {
          /Times-Roman 40 selectfont
          .6 setgray 300 300 moveto 30 rotate (Watermark) show
          true}
          {false} ifelse
       } bind
    >> setpagedevice

    (file_to_watermark.ps) run

这很好,但是我不管页面大小如何,都希望水印位于页面的中心(此代码需要适用于file_to_watermark.ps的各种大小)。我现在的代码是根据特定的坐标定位水印,如果将不同的file_to_watermark.ps用于不同的页面大小(例如法律,字母等),显然水印不会居中。是否有某种方法可以检索当前file_to_watermark.ps的页面大小,并根据该页面而不是预定义的坐标将页面置于水印中心?

This works great, but I would like the watermark to be centered on the page, regardless of page size (this code needs to work for varying sizes of file_to_watermark.ps). My code right now is positioning the watermark based on specific coordinates, which obviously doesn't center the mark if a different file_to_watermark.ps is used with a different page size (i.e. legal, letter, etc.). Is there someway to retrieve the page size of the current file_to_watermark.ps and center-on-page the watermark based on that rather than predefined coordinates?

推荐答案

您可以从pagedevice词典中提取当前媒体大小:

You could extract the current media size from the pagedevice dictionary:

currentpagedevice /PageSize get

返回宽度和高度(以磅为单位)。然后,您可以使用 stringwidth 运算符来计算给定字符串在打印时所占用的空间量。没有简单的方法来获取垂直高度,但对于拉丁字体,pointsize可以作为任何指南。

which returns the width and height (in points) on the stack. You can then use the stringwidth operator to calculate the amount of space occupied by the given string when printed. There's no simple way to get the vertical height, but the pointsize is as good a guide as anything for Latin fonts.

从页面宽度中减去字符串宽度并除以

Subtracting the string width from the page width and dividing by two should be good enough, similarly for the y co-ordinate.

对于真正的打印机,不要使用 MediaSize 有时最好使用初始剪辑:

For real printers, instead of using the MediaSize the initial clip is sometimes a better bet:

initclip clippath flattenpath pathbbox

这篇关于后记:具有不同页面大小的水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆