# All generated pdf's into one pdf

**URL:** <https://root-forum.cern.ch/t/all-generated-pdfs-into-one-pdf/51266>\
**Category:** Newbie\
**Created:** [August 21, 2022, 8:43pm UTC](https://root-forum.cern.ch/t/all-generated-pdfs-into-one-pdf/51266 "2022-08-21T20:43:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurmukh\_dhindsa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gurmukh_dhindsa/32/30326_2.png) [@gurmukh\_dhindsa](https://root-forum.cern.ch/u/gurmukh_dhindsa)\
**Post date:** [August 21, 2022, 8:43pm UTC](https://root-forum.cern.ch/t/all-generated-pdfs-into-one-pdf/51266/1 "2022-08-21T20:43:34Z")

</div>

#include \<stdio.h\>  
#include   
#include   
#include “TCanvas.h”  
#include “TF1.h”  
#include “TFile.h”  
#include “TGraphErrors.h”  
#include “TH1.h”  
#include “TH2.h”  
#include “TSpectrum.h”  
using namespace std;  
int histocounter=0;

Double\_t fitpeak (TH1F \*histo)  
{  
TF1 \*fS = new TF1(“fS”,“gaus”,800,1200); //Range change for both  
fS-\>SetParNames(“height”,“mean”,“sigma”);  
fS-\>SetParameter(0,6000);  
fS-\>SetParameter(1,6);  
fS-\>SetParameter(2,0.14);  
histo-\>Fit(fS,“R”);  
histo-\>Draw(“”);  
Double\_t mean00=fS-\>GetParameter(1);

```
    return mean00;
}

```

int Gaus()  
{  
FILE \*out;  
TString outputName = “Sd1r\_adc.txt”;  
out = fopen(outputName.Data(),“w”);  
Double\_t mean;  
TFile \*f = TFile::Open(“tree066330000.root”);  
TTree _Iris = (TTree_)f-\>Get(“Iris”);  
Char\_t histo[50],selection[100];  
TString histogram = “h1”;  
sprintf(histo,“TSd1rADC\>\>h1(%d,%d,%d)”,40,800,1200); // binning should not be high nor less (60)

// std :: string cut = “.x elasag.C”; //S3cut May not be needed, can comment  
// gROOT-\>ProcessLine(cut.data()); // related  
TObjArray Hlist(0); // created an array to store objects like histograms in this case(h2)  
for(Int\_t j=0;j\<24; j++) // here j \< 32 for sectors while j\<24 for rings ,  
{  
//sprintf(selection,“cut && TICEnergy\>450 && TICEnergy\<850 && TSd1sChannel==%d”,j); //For data  
sprintf(selection,“TSd1rChannel==%d && TICEnergy\>194 && TICEnergy\<734”,j);  
//for simIris // TICEnergy\>280 && TICEnergy\<700 // i have to put minimum and max values of TICEnergy depends on 3Sigma values after gaussian fitting

```
    Iris->Draw(histo,selection,"");
    TH1F *h2 = (TH1F*)gDirectory->Get(histogram.Data());
    
    //h2->Draw("");
    h2->SetName(histogram + "_"+j);
     
    mean=fitpeak (h2);
    gPad->Update();
histocounter++;
gPad->SaveAs(Form("hist%d.pdf",histocounter)); // this will create all as many pdf for number of histograms
    cout<<"mean = "<<mean<<" j "<<j<<endl;
    //out<<"mean = "<<mean<<" j "<<j<<endl;
    fprintf(out,"%d\t%f\n",j,mean);
    Hlist.Add(h2);
}

TFile f2("demo.root","recreate");
Hlist.Write();
f2.Close();

fclose(out);
return 0;

```

}

In this program, I am able to generate all histograms and save them as separate pdf’s. But I want one pdf which include all histograms. Thanks

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [August 22, 2022, 4:39am UTC](https://root-forum.cern.ch/t/all-generated-pdfs-into-one-pdf/51266/2 "2022-08-22T04:39:36Z")

</div>

You need to open a multipage PDF in the first SaveAs and close it at the last one. See the example in the TPDF documentation (note the parenthesis just after “pdf”):

```auto
canvas->Print("plots.pdf("...
...
canvas->Print("plots.pdf)"...

```

[https://root.cern/doc/v610/classTPDF.html](https://root.cern/doc/v610/classTPDF.html)

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [August 22, 2022, 12:39pm UTC](https://root-forum.cern.ch/t/all-generated-pdfs-into-one-pdf/51266/3 "2022-08-22T12:39:43Z")

</div>

Or use an external program - e.g. `pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf`
