# Saving histograms into a pdf / png format directly from ROOT

**URL:** <https://root-forum.cern.ch/t/saving-histograms-into-a-pdf-png-format-directly-from-root/51131>\
**Category:** ROOT\
**Tags:** python, hist, root\
**Created:** [August 10, 2022, 10:19am UTC](https://root-forum.cern.ch/t/saving-histograms-into-a-pdf-png-format-directly-from-root/51131 "2022-08-10T10:19:19Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [August 11, 2022, 10:45am UTC](https://root-forum.cern.ch/t/saving-histograms-into-a-pdf-png-format-directly-from-root/51131/13 "2022-08-11T10:45:18Z")

</div>

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:

```cpp
        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](https://root-forum.cern.ch/t/loop-over-all-objects-in-a-root-file/10807) in the TFile and only call SaveAs if the `key->ClassName()=="TCanvas"`.

---

_[View the full topic](https://root-forum.cern.ch/t/saving-histograms-into-a-pdf-png-format-directly-from-root/51131)._
