Search code examples
phppostscript

Generating Postscript using PHP: browser offers to save file


$ps = ps_new();
ps_open_file($ps,$filename);
ps_begin_page($ps,$size,$size);
ps_set_parameter($ps, 'SearchPath' , '/usr/share/texmf-texlive/fonts/afm/bluesky/cm');
$psfont = ps_findfont($ps, "cmr10", "", 0);  

ps_setfont($ps, $psfont, 12.0);

ps_circle($ps,$size/2,$size/2,$size/10);
ps_circle($ps,$size/4,$size/2,1);
ps_circle($ps,$size/2,$size/4,1);
ps_circle($ps,$size/4,$size/4,1);    
ps_fill($ps);


//ps_show_xy($ps, 'test',$size/8,$size/8);
//ps_stroke($ps);

ps_end_page($ps);
ps_close($ps);
ps_delete($ps);

If I comment out the ps_setfont line, it correctly saves a .ps file containing some filled circles.

With the ps_setfont line not commented out, firefox offers to save something with my .php filename, but what gets saved is 0 bytes long.

I don't understand why this "download" is being offered :-S


Solution

  • Probably it's a matter of some error output happening in ps_setfont() calling line. Try to set:

    error_reporting(E_ALL);
    

    and check error messages in logs or before you send it as an output to the browser. Once you eliminate the error output, the script should be working fine.