Writing several canvases to the same PDF file

Hi,
I tried the TCanvas::Print(“file.pdf[”,“pdf”) mechanism but it seems there is a bug because, differently from the postscript case, using a PDF file an empty initial page is produced:

TCanvas *myc = new TCanvas(“myc”,"",500,600);
myc->Print(dir+“plot.pdf[”,“pdf”);
for(i=0;i<Npages;i++){
histo->Draw();
myc->Print(“file.pdf”,“pdf”);
}
myc->Print(“file.pdf]”,“pdf”);

using postscript I correctly get a file with Npages, while using PDF I get Npages+1, the first one being empty.

I’m using last ROOT versiom (5.18)

this one works for me:

{
   TCanvas* canvas = new TCanvas("canvas");

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

   histo->Fill(2.);
   histo->Draw();
   canvas->Print("plots.pdf(","pdf");

   histo->Fill(4.);
   histo->Draw();
   canvas->Print("plots.pdf","pdf");

   histo->Fill(6.);
   histo->Draw();
   canvas->Print("plots.pdf","pdf");

   histo->Fill(8.);
   histo->Draw();
   canvas->Print("plots.pdf)","pdf");
}

yes also for me.
But if you try:

{
TCanvas* canvas = new TCanvas(“canvas”);

TH1F* histo = new TH1F(“histo”,“test 1”,10,0.,10.);

canvas->Print(“plots.pdf[”,“pdf”);
for(int i=1; i<=4; i++){
histo->Fill((float)i);
histo->Draw();
canvas->Print(“plots.pdf”,“pdf”);
}
canvas->Print(“plots.pdf]”,“pdf”);
}

you will see that the first page is empty.

{
   TCanvas* canvas = new TCanvas("canvas");
   TH1F* histo = new TH1F("histo","test 1",10,0.,10.);
   for(int i=1; i<=4; i++){
      histo->Fill((float)i);
      histo->Draw();
      if (i==1) {
         canvas->Print("plots.pdf(","pdf");
      } elseif (i==4) {
         canvas->Print("plots.pdf)","pdf");
      } else {
         canvas->Print("plots.pdf","pdf");
      }
   }
}

sure with that code it works I know. But it was only to stress that the “[” mechanism seems not to work properly because instead of simply opening the file (without any print) it opens the file but also print the current (empty) cnavas…

In fact if you look at the documentation this mechanism is described for PS. It is the same pdf.

I see! I expected it should work also for PDF. Ok thanks a lot!