Pregunta

How can I create a PS (PostScript) file in C language?

For example, I want create file myfile.ps and draw to PostScript this code:

%!
newpath
0 0 moveto
120 120 lineto
144 120 lineto
200 122 lineto
0 0 lineto
stroke 
showpage
¿Fue útil?

Solución

Normally postscript is just ascii text, so the standard text-output facilities will work just fine.

#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;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top