Appending canvas of different size is not working

I have stumbled upon a bug in ROOT’s multi-page pdf output [v. 5.34.18]: It seems that appending a page that is larger than the previous page (or the first page?) does not work as expected. You can find the test code below. Note that executing this code will produce a file named test.pdf (and overwrite if it exists).

[Bug Description]: Notice that [quote]c1[/quote] and [quote]c2[/quote] have significantly differing dimensions. If you check the output pdf you will notice that the sizing of the second page is wrong. It does not correspond to the specified size (aspect ratio of 1:3).
This seems to happen whenever the new size in one of the dimensions is large/significantly larger (?) than the old size.
Note that changing the order of the instructions (first printing the large canvas, then the small one) results in the correct pdf.

[Example Code]:

{
    TCanvas * c1 = new TCanvas( "c1", "", 500, 500 );
    c1->Print( "test.pdf[" );

    TH1F * h1 = new TH1F( "", "", 10, -5, 5 );
    h1->FillRandom( "gaus" );
    h1->Draw();
    c1->Print( "test.pdf" );

    TCanvas * c2 = new TCanvas( "c2", "", 500, 1500 );

    TH1F * h2 = new TH1F( "", "", 10, -5, 5 );
    h2->FillRandom( "landau" );
    h2->Draw();
    c2->Print( "test.pdf" );

    c2->Print( "test.pdf]" );
}

Yes, it was implemented that way, having in mind that books usually have the same size for all pages.

So this is considered a feature rather than a bug? Is there any workaround?

Neither a bug or a feature. It is implemented that way. All the pages have the same size. Like in a book. The workaround would be to generate you pdf file separately and group them with some external tool if you need to.

However, a pdf is not a book. And in any case, usually a book is not made from just plots :wink:.

Might I suggest that root print some error message if the user tries to append a canvas of different size to an existing pdf document? And/or add this information to the documentation of TPad::Print.

I think the documentation is clear already because the example in TPad::Print used to demonstrate the multiple pages output uses one canvas only. Nowhere it says that one can use different canvases.

May be the title “Writing several canvases to the same Postscript or PDF file” can let think so … well yes we can change that… but the example is not ambiguous.