Landscape mode when printing to pdf

hi,
In an application, I save the canvas plots as a pdf document using the method:
C->Print(“C.pdf”);
The output file is in portrait mode. Does someone know how to get the output file in landscape mode or seascape, etc…

Thanks for your help, Nabil.

If your canvas on the screen is portrait, it will be in portrait mode
on pdf. Same if the canvas is landscape, it will be landscape on pdf.

Rene

Hi there, I’m having the same problem, and can’t really find the answer in the ROOT user manual (I’m sure there’s a way to do it of course) All of my pdfs seem to come out rotated. For example:

{
TCanvas *c = new TCanvas();
TH1F *h1 = new TH1F(“h1”,“h1”,10,0,10);
h1->Fill(5.);
h1->Draw();
c->SaveAs(“c.pdf”)
}

It’s simple to open up the file afterwards and rotate it, but I’d rather just have some way to do it in code. Even if I set the canvas to be rectangular,

TCanvas *c = new TCanvas(“c”,“c”,620,440)

I get the same rotated PDF. I was browsing the TCanvas class, but couldn’t find any setters for the orientation. Perhaps in a future version of ROOT there could be an orientation switch in the SaveAs function? I know this exists for printing to eps.

Jesse Wodin

Your canvas has a landscape layout (x size > y size) make it portrait (y size > x size) and it will fine.

I’m working with ROOT 5.14 on OS X (10.4.10), and I’m experience similar problems. When canvas height > canvas width, the pdf is in portrait mode, as it should be. When canvas height > canvas width, the pdf is still in portrait mode, whereas I was expecting landscape. I’ve tried viewing with both Preview and Reader (7), and get the same results.

For me the PDF files are landscape or portrait (when I visualize the file using gv or print it) according to the rules I explained earlier. I am using the latest root version (5.17) on linux.

When I try to save a canvas as a .pdf (width>heigth) from the Canvas main menu via File->SaveAs-> (chose .pdf in “File of type”) and give name, the results is in portrait mode although it should be landscape. How can I choose the “landscape” mode.?
(I am using root 5.18 )

Thanks

When W > H a landscape file is generated. I guess you are visualizing it using gv. gv is not able to detect that the file in landscape mode. You can see that “Portrait” is displayed on the top bar of gv. Change to “Seascape” and it will be ok.

If you print the file it will be landscape ie the width will be aligned on the greater paper side.

Thanks for your answer.
Actually I have Mac OS 10.5.4 and I use preview. If I save the plot as .eps preview convert it to .pdf and it looks fine (landscape), but if I save the same plot as pdf it shows as a portrait. Also when I include then in Latex I have to use the angle=90 in \includegraphics and if I insert then in power point I have to rotate them…
Is there something that I can set in the rootlogon.C or something of the kind so that the pdfs look landscape as default, or is it beyond root and it has to do with my programs?

Again, thanks for your help.

Berta

Preview should be the same as gv … when you print it, is it ok ?

Well, it depends on what you define as ok. When I print it the figure is aligned with the page in the landscape mode, which I guess is what you mean by ok. If I look at the paper in portrait mode (as I would look if there were text written) is rotated again. Anyhow, I (as most of my fellows) hardly never print my plots, instead I preview then in the screen and then I include then in pdflatex or in power point, which means that most of the times I have to rotate them, so the pritning feature is not of much help. And I have checked that this not only a feature of Preview, Acrobat also shows then rotated (attached plot)

So I would suggest adding a flag to the “SaveAs” buttom in the Main menu of a Canvas so that one can choose in which direction one wants to save the plot.

Thanks again

Berta
test.pdf (18.2 KB)

The only problem I see if that the ROOT pdf files are seascape oriented instead of landscape. I tried some simple mod in the code but that does not fix it. So it requires more time to fix.

Hi,
I agree with the suggestion from B.Beltran, that one should be able to specify “portrait/landscape” as an option in TCanvas::Print().

I too produce .pdf files from ROOT and then include them in latex documents using \includegraphics{}. It is tiresome that whenever I adjust ROOT’s canvas size to produce a low-wide figure, and then print it using TCanvas::Print(“fun.pdf”), it rotates it in the .pdf file, so I am then forced to then unrotate it in latex.

                            Thanks,
                               Ian Tomalin

ok. That’s not really the problem. I still have not find the way (and time) to produce landscape. It is seascape now. So an option will not help.

Hi,

I just spent two hours trying to get a landscape pdf until luckily or rather unfortunately I found this discussion thread. It would be great to have pdf also implemented as landscape mode. Now I have to rotate all my plots before I can use them (and there are hundreds of them …).

Cheers,
Antje

Ok, I guess I should finally dedicate some time on that. Note that you can use PS meanwhile.

This problem of PDF lanscape orientation is now fixed in the SVN trunk.

Even after installing the newest version of ROOT (v23_04) and recompiling my code, the PDFs still seem to be rotated from landscape to portrait.

The figures I tested this with are similar to the one presented in this discussion earlier. The size of these figures is about 600 pixels wide and 400 pixels high. The paper size is set with SetPaperSize() to about 18 cm wide and 12 cm high.

Depending on the format used, the created files have the following layout:
gPad->Print(“name.eps”) --> perfect: landscape rotation and correct paper size
gPad->Print(“name.ps”) --> landscape rotation, but in A4 format
gPad->Print(“name.pdf”) --> paper size correct, but still rotated to portrait :frowning:

The results are the same using the following code:
TPostScript ps(“name”,112);
ps.Close() --> landscape rotation, but in A4 format
TPDF pdf(“name”,112);
pdf.Close() -->paper size correct, but still rotated to portrait :frowning:

Unfortunately (E)PS is not very well supported on the MAC but PDF is. Luckily I found a work-around by doubling the canvas size, splitting it into two pads, and then just saving the top pad:
canvas = new TCanvas(name_canvas,name_canvas,canvas_width,2*canvas_height);
canvas->Divide(1,2);
canvas->cd(1);
gPad->Print(“name.pdf”) --> perfect: landscape rotation and correct paper size :wink:

It takes up a lot of empty space on the screen but at least the saved pads have the correct paper size and the desired rotation.

Cheers, Antje

Oops, sorry, the response that it is fixed was so close in time with the new development release that I thought it would have been included.

Now after searching through the SVN trunk and installing the newest postscript/src files, it actually works just fine now and landscape PDFs don’t get rotated to portrait anymore!!! :smiley:

Thanks Olivier for fixing it!

You’re welcome :slight_smile: