如何在 postscript 文件上制作程序覆盖文本? [英] How can I make a program overlay text on a postscript file?
问题描述
我有一些 postscript 格式的图表,由 gnuplot 生成.我需要在图表上放置一些识别信息.我如何编写一些指令来做到这一点?我想在图表的右上角写一个数字(一个 .ps 文件).
I have some graphs in postscript format, generated by gnuplot. I need to place some identifying information on the graph. How can I script some instructions to do that? I want to write a number at the top right corner of the graph (a .ps file).
推荐答案
好的,您链接到的示例文件运行良好(并且没有重新定义 showpage
运算符).
Ok, the example file you linked to is well behaving (and has not re-defined the showpage
operator).
所以我现在假设如下:
- 您所有的 .ps 文件都类似于您的示例文件.
- 您所有的 .ps 文件都只有一页(如 .eps 文件).
- 您所有的文件名都类似于
gnp-NNN.ps
(就像 gnp-544.ps 一样). - 您希望出现在右上角的数字是来自文件名的
NNN
.
- All your .ps files are similar to your example file.
- All your .ps files are 1 page only (like .eps files).
- All your filenames are like constructed as
gnp-NNN.ps
(like gnp-544.ps is). - The number you want to appear in the top right corner is
NNN
from the filename.
我还假设您安装了 Ghostscript,它是 最新版本,8.71.我目前使用的是 Windows -- 如果您使用的是 Linux/Unix,只需将 gswin32c.exe
替换为 gs
和所有行结尾 ^
通过 .
I also assume you have Ghostscript installed, and it is the most recent version, 8.71. I'm currently on Windows -- if you're on Linux/Unix, just replace gswin32c.exe
by gs
and all line endings ^
by .
现在先试试这个命令:
gswin32c.exe ^
-o gnp-with-number-544.pdf ^
-sDEVICE=pdfwrite ^
-g5030x5320 ^
-c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (544) show" ^
-f gnp-544.ps
并查看结果 gnp-with-number-544.pdf
是否符合您的要求.
and see if the resulting gnp-with-number-544.pdf
looks like you want it.
-c "..."
用于将 PostScript 片段传递给 Ghostscript 并使其与主 .ps 文件一起处理这些文件,然后将其作为下一个参数,使用 -f ...
.
The -c "..."
is used to pass PostScript snippets to Ghostscript and make it process these together with the main .ps file which has then to follow as next parameter, with -f ...
.
可以修改参数:
- 将
/Helvetica-Italic
字体名替换为/Helvetica
、/Courier
、/Times
、Helvetica-Bold
或任何你可用和喜欢的. - 或修改字体大小:
15
此处表示 15 点(在 PDF 中 72 点 == 1 英寸). - 或者改变位置:
453 482
将PostScript当前点移动到向左453点,向上482点"(与oringin 0,0 设置为左下角). - 或调整媒体大小:
-g5030x5320
为您提供 503x532 点(由于-sDEVICE=pdfwrite
使用的默认分辨率为 720 dpi. - 或者将要打印的字符串设置为
(File No. 544) show
或任何你想要的.
- Replace the
/Helvetica-Italic
fontname by/Helvetica
,/Courier
,/Times
,Helvetica-Bold
or whatever you've available and prefer. - Or modify the fontsize:
15
here means 15 points (in PDF 72 points == 1 inch). - Or change the position:
453 482
moves the PostScript currentpoint to "453 points to the left, 482 points to the top" (with the oringin 0,0 set to the bottom left corner). - Or tweak the media size:
-g5030x5320
gives you 503x532 points (due to the default resolution of 720 dpi used by-sDEVICE=pdfwrite
. - Or set the string being printed to
(File No. 544) show
or whatever you want.
您还可以添加相当多的参数来调整输出文件的质量(分辨率、字体嵌入等),但现在就这些.
You could also add quite a few parameters to tweak the quality of the output file (resolution, font embedding etc.), but these ones will do for now.
如果您出于某种原因需要 PostScript 输出而不是 PDF,请像这样更改命令:
Should you need PostScript output for some reason instead of PDF, change the command like this:
gswin32c.exe ^
-o gnp-with-number-544.ps ^
-sDEVICE=ps2write ^
-g5030x5320 ^
-c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (544) show" ^
-f gnp-544.ps
批量转换大量文件
现在,如何批量转换这个?对于最后一步,我假设:
Batch-convert Lots of Files
Now, how to batch-convert this? For this last step, I'm assuming:
- 您的
NNN
编号方案未使用前导0
. - 您要转换的文件范围是 gnp-1.ps..gnp-1000.ps.
- 您想要添加数字的 PDF 输出,而不是 PS.
- your
NNN
numbering scheme is not using leading0
s. - your range of files to be converted is gnp-1.ps..gnp-1000.ps.
- you want PDF output with the numbers added, not PS.
在 Windows 上,使用以下内容创建一个 addnumbers-make-pdf.bat
文件:
On Windows, create an addnumbers-make-pdf.bat
file with this content:
gswin32c.exe ^
-o gnp-with-number-%1.pdf ^
-sDEVICE=pdfwrite ^
-g5030x5320 ^
-c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (%1) show" ^
-f gnp-%1.ps
现在在 cmd.exe
控制台中运行这个命令:
Now run this command in a cmd.exe
console:
for /l %i in (1,1,100) do (addnumbers-make-pdfvim.bat %i)
在 Linux 上,使用以下内容创建一个 addnumbers-make-pdf.sh
Bash shell 脚本:
On Linux, create an addnumbers-make-pdf.sh
Bash shell script with this content:
#!/bin/bash
gs
-o gnp-with-number-${1}.pdf
-sDEVICE=pdfwrite
-g5030x5320
-c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (${1}) show"
-f gnp-${1}.ps
现在在 shell 中运行这个命令:
Now run this command in a shell:
for i in $(seq 1 1000); do addnumbers-make-pdf.sh ${i} ; done
<小时>
更新:
哈!,它甚至可以工作 ;-) 我刚刚在 Windows 上测试了它.这是原始文件和覆盖文件(PDF 格式)的屏幕截图:
Update:
Hah!, it even works ;-) I just tested it on Windows. Here is a screenshot with the original and the overlayed file (as PDFs):
这篇关于如何在 postscript 文件上制作程序覆盖文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!