2013-10-24 37 views
0

如何使用C语言创建PS(PostScript)文件?C语言 - 如何创建PostScript文件

例如,我要创建文件myfile.ps和成PostScript验证码:

%! 
newpath 
0 0 moveto 
120 120 lineto 
144 120 lineto 
200 122 lineto 
0 0 lineto 
stroke 
showpage 
+1

你试过pslib吗? http://pslib.sourceforge.net/ –

+0

不,我是初学者,我会尝试一下,谢谢。 –

+1

这个例子不需要任何库,你可以在c中使用相当简单的文件操作 - 所以你试过了什么? – agentp

回答

3

通常后记仅仅是ASCII文本,所以标准文本的输出设备将工作得很好。

#include <stdio.h> 

int main(void) { 
    FILE *outfile; 
    outfile = fopen("myfile.ps", "w"); 
    fprintf(outfile, 
     "%%!\n" 
     "%d %d moveto\n" 
     "%d %d lineto\n" 
     "%d %d lineto\n" 
     "%d %d lineto\n" 
     "%d %d lineto\n" 
     "stroke\n" 
     "showpage\n", 
     0, 0, 
     120, 120, 
     144, 120, 
     200, 122, 
     0, 0 
    ); 
    return 0; 
}