You could also save directly the canvases as PDF at the same time that you write the ROOT file, rather than doing that in a separate script later on.
To save all open canvases in a ROOT session, just type the following in a terminal:
TIter next(gROOT->GetListOfCanvases());
TCanvas* c = nullptr;
while((c = (TCanvas*)next()))
{
const TString canvName = c->GetName();
c->SaveAs(canvName+".pdf");
}
You could do something similar if the canvases are not open, but rather inside a TFile.
Just iterate over all keys in the TFile and only call SaveAs if the key->ClassName()=="TCanvas"
.