我如何在一个postscript文件上制作一个覆盖文本的程序? [英] How can I make a program overlay text on a postscript file?
问题描述
我有一些由postscript格式的图形,由gnuplot生成。我需要在图表上放置一些识别信息。我怎样编写一些指令来做到这一点?我想在图的右上角编写一个数字(.ps文件)。
好的,例子您链接的文件行为良好(并且未重新定义 showpage
运算符)。
所以我现在假设如下:
- 所有.ps文件与您的示例文件类似。
- 所有的.ps文件只有1页(如.eps文件)。
- 所有文件名都是像构建为
gnp-NNN.ps
(如 gnp-544.ps 是)。 - 您想要出现在右上角的号码是
NNN
。
我也假设你已经安装了Ghostscript,它是 最新版本 ,8.71。我现在在Windows上 - 如果你在Linux / Unix上,只需用 gs
替换 gswin32c.exe
和所有行结尾 ^
由 \
。
测试PDF输出
现在先试试这个命令:
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
是否看起来像你想要的。
$ b
使用 -c...
将PostScript片段传递给Ghostscript并使它们一起处理与主要的.ps文件,然后作为下一个参数,与 -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
使用的默认720dpi分辨率。
- 或将要打印的字符串设置为
(文件号码544)显示
或任何您想要的内容。
- 或改变位置:
您还可以添加很多参数来调整输出文件的质量(分辨率,字体嵌入等),但这些参数现在就可以实现了。
更改为PostScript输出
如果您因为某些原因而不是PDF需要PostScript输出,请更改命令,如下所示:
gswin32c.exe ^
-o gnp-with-number-544.ps ^
-sDEVICE = ps2write ^
-g5030x5320 ^
-c/ Helvetica-Italic findfont 15比例font setfont 453 482 moveto(544)show^
-f gnp-544.ps
批量转换大量文件
现在,如何批量转换这个?对于最后一步,我假设:
- 您的
NNN
编号方案是不使用前导0
s。 - 要转换的文件范围为gnp-1.ps..gnp-1000.ps。
- 添加,而不是PS。
在Windows上,创建 addnumbers-make- pdf.bat
包含此内容的文件:
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
现在在 console:
for / l%i in(1,1,100 )do(addnumbers-make-pdfvim.bat%i)
在Linux上,用这个内容创建一个 addnumbers-make-pdf.sh
Bash shell脚本:
#!/ 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中运行这个命令:
for i in $(seq 1 1000); do addnumbers-make-pdf.sh $ {i};完成
更新:
哈!它甚至可以工作;-)我只是在Windows上测试它。以下是原始文件和覆盖文件的截图(以PDF格式):
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).
Ok, the example file you linked to is well behaving (and has not re-defined the showpage
operator).
So I'm now assuming the following:
- 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.
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 \
.
Test PDF Output
Now try this command first:
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
and see if the resulting gnp-with-number-544.pdf
looks like you want it.
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 ...
.
You can modify parameters:
- 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.
Change to PostScript Output
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:
- 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.
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
Now run this command in a cmd.exe
console:
for /l %i in (1,1,100) do (addnumbers-make-pdfvim.bat %i)
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
Now run this command in a shell:
for i in $(seq 1 1000); do addnumbers-make-pdf.sh ${i} ; done
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屋!