How to print canvas directly to the printer ( hardware)?

[size=134]I work with the GUI and the constructor fCanvas = new TRootEmbeddedCanvs(); gives a canvas without widget which can make it possible to print the contents of the canvas with a printer (hardware).

Can somebody tell me which command I can use in my program to print the canvas on a printer (hardware)? I tested without success all the “Draw” and the “Print” method.[/size]

In $ROOTSYS/etc/system.rootrc got to the section:

# Printer settings.

there you will find something like:

Unix.*.Print.Command:       lpr -P %p %f
Print.Printer:              32-rb20-hp
Print.Directory:            .
Print.FileType:             ps

These are my own settings change them to what you need. Then from any TCanvas you will be able to use the File/Print menu entry. It will send the contain of the canvas to the printer.

[size=125]Thank you for your answer.
perhaps that I was not made understand, I created my one canvas with the GUI, like you can see it in attachement. there is not the toolbar. I dont know if there is a possibility to add toolbar. But what I want is how to introduce in my program , a command which can enable me to print my histogramm on a printer.
I’m using ROOT V.5.17/02 on windows. and this is my stting $ROOTSYS/etc/system.rootrc [/size]

# Printer settings. #WinNT.*.Print.Command: AcroRd32.exe #Unix.*.Print.Command: a2ps -P%p --landscape --columns=2 --margin=30 -rf8.0 %f #Print.Printer: 32-rb20-hp #Print.Directory: . #Print.FileType: pdf
canvas.doc (56.5 KB)

Hi,

Here is a piece of code showing how to add a toolbar to your main frame:

// definition of the toolbar items:

ToolBarData_t fTbData[] = {
  { "open.png",      "Open File",        kFALSE, kM_FILE_OPEN,        0 },
  { "save.png",      "Save File",        kFALSE, kM_FILE_SAVE,        0 },
  { "",              0,                  0,      -1,                  0 },
  { "print.png",     "Print",            kFALSE, kM_FILE_PRINT,       0 },
  {  0,              0,                  0,      0,                   0 }
};

// To be added in your main frame constructor:

   Int_t i,spacing = 8;
   fToolBar = new TGToolBar(this, 60, 20, kHorizontalFrame);
   for (i = 0; fTbData[i].fPixmap; i++) {
      if (strlen(fTbData[i].fPixmap) == 0) {
         spacing = 8;
         continue;
      }
      fToolBar->AddButton(this, &fTbData[i], spacing);
      spacing = 0;
   }
   AddFrame(fToolBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
            0, 0, 0, 0));

You can also look at the examples in $ROOTSYS/test/RootIDE and $ROOTSYS/test/RootShower

Cheers,
Bertrand.

I want to know how to print canvas directly to the printer? I have a printer Epson WF-3640 and I want to print canvas directly. If anyone shares with me the process of printing I became very helpful.

Welcome to the ROOT forum! Sorry, but this question is not related to ROOT and it depends on the OS you’re working on…