tags:

views:

176

answers:

1
$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

A: 

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.

bth
I have some of these at the end of apache's error.log:[Wed Nov 25 11:20:42 2009] [notice] child pid 18600 exit signal Segmentation fault (11)Note: the .ps file shouldn't be sent to the browser, I'll be including it in LaTeX later, and outputting a separate .pdf
Emyr
Is the code you posted complete or there is more? I assumed the script is generating and serving the .ps over the http basing on your mention of Firefox. How is it requested then?
bth
My script returns a pdf generated by writing LaTeX to a .tex file, using exec("cd $path What this block of code is meant to do is generate a postscript diagram which will be embedded in the pdf.The only parts missing from the code above are the bits which set $filename and $size.I'm guessing that php is sending back the wrong headers with no content because of the segfaults.
Emyr
I want my linebreaks back!
Emyr
Yes, that was my guess - you have to get the actual error output from the script / ps_setfont function, as I doubt it is this segfault.
bth
Running the code using the php CLI tool (php -f file.php) seems to indicate it's definitely the ps_setfont() line causing the segfault... Is there some tool I can use to find out if it's actually the postscript extension causing it?
Emyr