TWebCanvas save as pdf


ROOT Version: 6.30/04
Platform: windows11
Compiler: MSVC 19.29.30154.0


I try to use TCanvas and TWebCanvas to draw TGraph2D, and it can be drawn normally. However, when I save the pdf with TCanvas, the pdf generated is just a picture inserted into the pdf file. What I want is an object-editable pdf file. Is there any solution?

How are you trying to edit the pdf? For me, with the same ROOT version (6.300/04, but on linux), I can edit the pdf with Inkscape, for instance (I moved the titles and parts of the graph):

If you try to edit in code, Emacs shows the code, but I’m not sure if all is editable (I don’t know if the “stream” parts are images or code).
Another option: save to .ps instead of .pdf (you can always convert ps to pdf later); the ps file also shows the code.

void webc() {
  TCanvas *c = new TCanvas("c");
  Double_t x, y, z, P = 6.;
  Int_t np = 200;
  auto dt = new TGraph2D();
  dt->SetTitle("Graph title; X axis title; Y axis title; Z axis title");
  auto r = new TRandom();
  for (Int_t N=0; N<np; N++) {
    x = 2*P*(r->Rndm(N))-P;
    y = 2*P*(r->Rndm(N))-P;
    z = (sin(x)/x)*(sin(y)/y)+0.2;
    dt->SetPoint(N,x,y,z);
  }
  gStyle->SetPalette(1);
  dt->Draw("surf1");
  TWebCanvas *wc = new TWebCanvas(c,"wc",10,10,500,500);
  wc->Show();
}

The code above, displaying on Firefox, results in these files:
Canvas.pdf (109.7 KB)
Canvas.ps (383.6 KB)

In case of TWebCanvas all 3D drawings performed with WebGL.
And produced image inserted as single element into SVG or PDF document.

That do you mean by object-editable pdf file?

I tested my code. The following code cannot be saved into an editable pdf. and The saved pdf is not the graph I displayed.

fCanvas = new TCanvas(kFALSE);
TWebCanvas *web = new TWebCanvas(fCanvas, "title", 0, 0, 800, 600, read_only);
fCanvas->SetCanvasImp(web);

Does fCanvas->SetCanvasImp(web); mean that it is rendered by jsroot? If there is no such line of code, is it server-side rendering?


save.pdf (47.3 KB)

Hi,

Here you are using “surf1” draw option for TGraph2D.
It was implemented after ROOT 6.30 release and works only with ROOT master branch.

Here is my output: webpdf.pdf (115.5 KB)

Also to use web canvas in normal ROOT scripts I recommend to use --web=chrome option.
Direct creation and configuring of TWebCanvas only needed for special applications like qtweb.

Regards,
Sergey

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.