How to use the PostScript interface


To generate a Postscript (or encapsulated ps) file corresponding to a single image in a canvas, you can:

Special characters

The following characters have a special action on the Postscript file:
       `   : go to greek
       '   : go to special
       ~   : go to ZapfDingbats
       ?   : go to subscript
       ^   : go to superscript
       !   : go to normal level of script
       &   : backspace one character
       #   : end of greek or of ZapfDingbats

These special characters are printed as such on the screen. To generate one of these characters on the Postscript file, you must escape it with the escape character "@".

The use of these special characters is illustrated in several macros referenced by the TPostScript constructor.

Making several pictures in the same Postscript file: case 1

The following macro is an example illustrating how to open a Postscript file and draw several pictures. The generation of a new Postscript page is automatic when TCanvas::Clear is called by object->Draw().

{
   TFile f("hsimple.root");
   TCanvas c1("c1","canvas",800,600);

     //select postscript output type
   Int_t type = 111;   //portrait  ps
// Int_t type = 112;   //landscape ps
// Int_t type = 113;   //eps

    //create a postscript file and set the paper size
   TPostScript ps("test.ps",type);
   ps.Range(16,24);  //set x,y of printed page

    //draw 3 histograms from file hsimple.root on separate pages
   hpx->Draw();
   c1.Update();      //force drawing in a macro
   hprof->Draw();
   c1.Update();
   hpx->Draw("lego1");
   c1.Update();
   ps.Close();
}

Making several pictures in the same Postscript file: case 2

This example shows 2 pages. The canvas is divided. TPostScript::NewPage must be called before starting a new picture. object->Draw does not clear the canvas in this case because we clear only the pads and not the main canvas. Note that c1->Update must be called at the end of the first picture

{
   TFile *f1 = new TFile("hsimple.root");
   TCanvas *c1 = new TCanvas("c1");
   TPostScript *ps = new TPostScript("file.ps",112);
   c1->Divide(2,1);
// picture 1
   ps->NewPage();
   c1->cd(1);
   hpx->Draw();
   c1->cd(2);
   hprof->Draw();
   c1->Update();

// picture 2
   ps->NewPage();
   c1->cd(1);
   hpxpy->Draw();
   c1->cd(2);
   ntuple->Draw("px");
   c1->Update();
   ps->Close();

// invoke Postscript viewer
   gSystem->Exec("gs file.ps");
}   

Rene Brun, Fons Rademakers
Last update 12/01/97 by Rene Brun