Psview

An example how to display PS, EPS, PDF files in canvas. To load a PS file in a TCanvas, the ghostscript program needs to be install.

  • On most unix systems it is installed by default.
  • On Windows it has to be installed from http://pages.cs.wisc.edu/~ghost/ also the place where gswin32c.exe sits should be added in the PATH. One way to do it is:
    1. Start the Control Panel
    2. Double click on System 3, Open the "Advanced" tab
    3. Click on the "Environment Variables" button
    4. Find "Path" in "System variable list", click on it.
    5. Click on the "Edit" button.
    6. In the "Variable value" field add the path of gswin32c (after a ";") it should be something like: "C:\Program Files\gs\gs8.13\bin"
    7. click "OK" as much as needed.

Author: Valeriy Onoutchin
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Sunday, July 05, 2020 at 07:35 AM.

In [1]:
%%cpp -d
#include "TROOT.h"
#include "TCanvas.h"
#include "TImage.h"

Set to batch mode -> do not display graphics

In [2]:
gROOT->SetBatch(1);

Create a postscript file

In [3]:
TString dir = gROOT->GetTutorialDir();
dir.Append("/graphics/feynman.C");
gROOT->Macro(dir);
gPad->Print("feynman.eps");
Info in <TCanvas::Print>: eps file feynman.eps has been created

Back to graphics mode

In [4]:
gROOT->SetBatch(0);

Create an image from ps file

In [5]:
TImage *ps = TImage::Open("feynman.eps");

if (!ps) {
   printf("GhostScript (gs) program must be installed\n");
   return;
}

new TCanvas("psexam", "Example how to display PS file in canvas", 600, 400);
TLatex *tex = new TLatex(0.06,0.9,"The picture below has been loaded from a PS file:");
tex->Draw();

TPad *eps = new TPad("eps", "eps", 0., 0., 1., 0.75);
eps->Draw();
eps->cd();
ps->Draw("xxx");
Error in <ROOT::Internal::TCheckHashRecursiveRemoveConsistency::CheckRecursiveRemove>: The class TImagePlugin overrides TObject::Hash but does not call TROOT::RecursiveRemove in its destructor (seen while checking TASPluginGS).
libpng error: invalid screen gamma in png_set_gamma
Error in <TUnixSystem::SetDisplay>: Can't figure out DISPLAY, set it manually
In case you run a remote ssh session, restart your ssh session with:
=========>  ssh -Y
Error in <TUnixSystem::SetDisplay>: Can't figure out DISPLAY, set it manually
In case you run a remote ssh session, restart your ssh session with:
=========>  ssh -Y
Error in <TGClient::TGClient>: can't open display "", switching to batch mode...
 In case you run from a remote ssh session, reconnect with ssh -Y
Error in <TASImage::Draw>: no image set

Draw all canvases

In [6]:
gROOT->GetListOfCanvases()->Draw()