To generate a Postscript (or encapsulated ps) file corresponding to a single image in a canvas, you can:
c1->Print("xxx.ps") or c1->Print("xxx.eps")
This will generate a file corresponding to the picture in the canvas pointed by c1.
pad1->Print("xxx.ps")
prints only the picture in the pad pointed by pad1. The size of the Postcript picture, by default, is computed to keep the aspect ratio of the picture on the screen, where the size along x is always 20cm. You can set the size of the PostScript picture before generating the picture with a command such as:
TPostScript myps("myfile.ps",111) myps.Range(xsize,ysize); object->Draw(); myps.Close();
You can set the default paper size with:
gStyle->SetPaperSize(xsize,ysize);
You can resume writing again in this file with myps.Open();. Note that you may have several Postscript files opened simultaneously.
` : 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.
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(); }
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"); }