Print canvases into the same ps file

I have a root file including some canvases. Here I attached a code to print these canvas into a ps file according to the instruction of root web page. But a problem I met is: last canvas cannot be printed correctly into the file (just print one part of the canvas). I check the root file, it seems no problem for the last canvas. So I am wondering what’s up for my code here. I also attach my root file here (test.root). My root version is v04.04.

Thanks,
Zhiyi

{ TFile *f; f = new TFile("test.root","READ"); f->cd(); TList *objlist = gDirectory->GetListOfKeys(); TIterator *can_itr = objlist->MakeIterator(); TKey *k2; TCanvas *can; while ( (k2 = static_cast<TKey*>(can_itr->Next())) !=0 ) { can = (TCanvas*)k2->ReadObj(); can->Print("test.ps("); } can->Print("test.ps]"); f->Close(); }
test.root (71.1 KB)

Your file contain TCanvas objects, but also other classes.
You should protect your loop to get only the TCanvas objects

{ TFile *f; f = new TFile("test.root","READ"); f->cd(); TList *objlist = gDirectory->GetListOfKeys(); TIterator *can_itr = objlist->MakeIterator(); TKey *k2; TCanvas *can; while ( (k2 = static_cast<TKey*>(can_itr->Next())) !=0 ) { if (strcmp(k2->GetClassName(),"TCanvas")) continue; can = (TCanvas*)k2->ReadObj(); can->Print("test.ps("); } can->Print("test.ps]"); f->Close(); }

Rene