Jump to content

whitepj

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

whitepj's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. OK. This is obviously the crux of the matter. When I call PS_new(), it returns a pointer to the postscript document (http://pslib.sourceforge.net/documentation.php?manpage=PS_new). This pointer is then used in all subsequent 'document write' actions. If at all possible, I am looking to use this pointer anywhere in my code, not just inside the class code. Yes, I did Effectively, it condenses down to: echo PS_get_buffer($this->ps); Where $this->ps is the aforementioned document pointer. (http://pslib.sourceforge.net/documentation.php?manpage=PS_get_buffer) Of course it doesn't - it is complete crap. I apologise - I'm not sure what I was thinking at the time... What I meant (to illustrate the idea of using the pointer outside the class, was: PS_lineto($this->ps, 100,100); Am I explaining myself OK? Thanks.
  2. Hi all. Apologies. This is hopefully a stupid and easily answered Q. However, I'm lost, and need a bit of guidance... I have pecl-ps installed. The following code woks fine, and produces a very simple PS page: <?php $doc = PS_new(); if (!PS_open_file($doc, '-')) { die; } PS_set_parameter($doc, 'warning', 'true'); PS_set_info($doc, 'boundingbox', '0 0 596 842'); PS_set_info($doc,'Title', 'A Hello World Example'); PS_set_parameter($doc, 'SearchPath', '/usr/share/fonts/default/ghostscript'); PS_begin_page($doc, 596, 842); $font = PS_findfont($doc,'n021023l', '', 0); PS_setfont($doc, $font, 58.0); PS_set_value($doc,'charspacing', 2); PS_set_text_pos($doc, 10,10); PS_show_xy($doc, 'Hello World', 50,50); PS_setlinewidth($doc, 2); PS_moveto($doc, 50, 50); PS_lineto($doc, 100,100); PS_stroke($doc); ps_end_page($doc); ?> Now, what I want to do is get most of this into a class. Thus, my code would become: <?php class PS { var $ps; public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false){ $this->ps = PS_new(); if (!PS_open_file($this->ps, '-')) { die; } // Construct PS file as above... } public function Output($name='doc.ps', $dest='I') { echo $this->getBuffer(); } protected function getBuffer() { return ps_get_buffer($this->ps); } } $doc = new PS('P', 'mm', 'A4', true, 'UTF-8', false); // do stuff $doc->Output('example.ps', 'I'); ?> Which again, works OK. However, obviously, what I want is the actual document writing code in a mass of other functions, and this is where I am failing - miserably! Any attempt to shift the 'construct PS' code elsewhere results in an error: <?php require_once('above-class.inc'); $ps = new PS('P', 'mm', 'A5', true, 'UTF-8', false); PS_begin_page($ps->ps, 596, 842); // or, perhaps $ps->WriteText($ps->ps, 'Hello World', 100, 100); ... more of the same ... $ps->Output('example_010.ps', 'I'); ?> Warning: ps_get_buffer(): 3 is not a valid ps document resource ... As you can probably tell, this is my first attempt at building a class, so a pointer on where I am going wrong, and how I can fix it, would be very much appreciated. Many thanks. Phil.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.