PDF printing using title

Hi !

I do have some issue writing PDF files including pages with title !
I am getting a TEX file instead of PDF file using the following code, although I mentioned .pdf in the extension :

{
   TCanvas* canvas = new TCanvas("canvas");
   TH1F* histo = new TH1F("histo","test 1",10,0.,10.);
   histo->SetFillColor(2);
   histo->Fill(2.);
   histo->Draw();
   canvas->Print("plots.pdf(","Title:My vertex distribution");
   histo->Fill(4.);
   histo->Draw();
   canvas->Print("plots.pdf(","Title:My vertex distribution");
   histo->Fill(6.);
   histo->Draw();
   canvas->Print("plots.pdf(","Title:My vertex distribution");
   histo->Fill(8.);
   histo->Draw();
   canvas->Print("plots.pdf(","Title:My vertex distribution");
   histo->Fill(8.);
   histo->Draw();
   canvas->Print("plots.pdf(","Title:My vertex distribution");
}

My guess is that this title : “My verTEX distribution” is the faulty guy ! :frowning:

Hi,

first, if you really want a multi-page pdf, use TCanvas::SaveAs, not TCanvas::Print. Second, you don’t need ( after plots.pdf everywhere: you need it only for the first page, then you need nothing for the intermediate pages, and finally you need ) for the last page.

Hi Thank you !
The parenthesis were a typo issue !

I took the example from :
https://root.cern.ch/doc/master/classTPDF.html
One might change it then :slight_smile:

Nevertheless using SaveAs, it seems that the Title in the bookmark of the PDF is not working anymore. Therefore I am still looking for a solution

I investigated a bit by looking though TPad, and I found a working solution :slight_smile:
This is doing the job !

{
    TCanvas* canvas = new TCanvas("canvas");
    TH1F* histo = new TH1F("histo","test 1",10,0.,10.);

    histo->SetFillColor(2);
    histo->Fill(2.);
    histo->Draw();

    TPDF *pdf = new TPDF("plots.pdf");
    pdf->On();

    pdf->NewPage();
    pdf->SetTitle("My Vertex Distribution");
    canvas->Paint();

    pdf->NewPage();
    pdf->SetTitle("My Vertex Distribution");
    canvas->Paint();

    pdf->NewPage();
    pdf->SetTitle("My Vertex Distribution");
    canvas->Paint();

    gROOT->GetListOfSpecials()->Remove(gVirtualPS);
    delete gVirtualPS;
    gVirtualPS = 0;
}

I ran the example you referred to. It works perfectly for me.
plots.pdf (20.5 KB)