PDF issue

Hi

I am wirting a small program with MS Visual Studio 2012 using the root-libraries. This works quite well until I want to print my canvas to a pdf. When I use the fCanvas->Print(filename,"Title: MyPlot"); I get the following exception from Visual Studio:

Unhandled exception at 0x5D7194F5 (libGpad.dll) in avail.exe: 0xC0000005: Access violation writing location 0x009C27F8.

I tried this with CINT/ROOT, too, and the pdf can be opened and everything is fine.
Furthermore, I tried an example I found here which also works with CINT but not as a compiled code in VS2012 (see code below). Also here, if I dont’t remove “Title:” I get an exception.
If I remove the keyword “Title:” in the above command at least a filename.pdf is created. Unfortunately, this pdf cannot be openend with AdobeReader or Acrobat because I get the error message the file would be corrupt.
I attached the pdf I created and it seems to be an ASCII-file. If I open a pdf that is fine, it seems to be a binary file.
Does anyone have the same issues?

Best regards,
delos

TCanvas* canvas = new TCanvas("canvas"); TH1F* histo = new TH1F("histo","test 1",10,0.,10.); histo->SetFillColor(2); histo->Fill(2.); histo->Draw(); canvas->Print("plots.pdf(","Title:page1"); histo->Fill(4.); histo->Draw(); canvas->Print("plots.pdf","Title:page2"); histo->Fill(6.); histo->Draw(); canvas->Print("plots.pdf","Title:page2"); histo->Fill(8.); histo->Draw(); canvas->Print("plots.pdf","Title:page3"); histo->Fill(8.); histo->Draw(); canvas->Print("plots.pdf)","Titel:page4");
plots.pdf (30.2 KB)

Hi delos,

not an expert opinion, but did you try fixing the typo on the last line of the code:

–>

?

Hi Yus

Yes, thank you. The typo is there because I changed the code here. In the program it’s correct and the issues are the same.

Thanks,
delos

I dunno what you are doing but your “pdf” file is in fact a PS file… it starts with:

%!PS-Adobe-2.0
%%Title: plots.pdf ( A 4)
%%Pages: (atend)
%%Creator: ROOT Version 5.34/19
%%CreationDate: Wed Aug 26 18:20:37 2015
%%Orientation: Landscape
%%EndComments

Hi

I just figured out that the “pdf” I attached is obviously a postscript file tough I use ->Print(“Test.pdf”)!
Actually, I can convert it to a pdf file but then my graphs suddenly contain markers and different fonts (the font problem I could understand).

Why is that?

Cheers,
delos

have you tried with a more recent version of ROOT ?

I have 5.34/19 of the 9th of July 2014. I can try the newest patch.
6.04 is not available for windows, is it?

plots.C:

{
   TCanvas* canvas = new TCanvas("canvas");
   TH1F* histo = new TH1F("histo","test 1",10,0.,10.);
   histo->SetFillColor(2);
   histo->Fill(2.);
   histo->Draw();
   canvas->Print("plots.pdf(","Title:page1");
   histo->Fill(4.);
   histo->Draw();
   canvas->Print("plots.pdf","Title:page2");
   histo->Fill(6.);
   histo->Draw();
   canvas->Print("plots.pdf","Title:page2");
   histo->Fill(8.);
   histo->Draw();
   canvas->Print("plots.pdf","Title:page3");
   histo->Fill(8.);
   histo->Draw();
   canvas->Print("plots.pdf)","Titel:page4");
}

Executed on mac (note the ROOT version)

$ root plots.C 
  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.34/33      23 June 2015   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *          http://root.cern.ch            *
  *                                         *
  *******************************************

ROOT 5.34/33 (heads/v5-34-00-patches@v5-34-32-51-g83c3322, Aug 14 2015, 14:13:16 on macosx64)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] 
Processing plot1s.C...
Info in <TCanvas::Print>: pdf file plots.pdf has been created
Info in <TCanvas::Print>: Current canvas added to pdf file plots.pdf
Info in <TCanvas::Print>: Current canvas added to pdf file plots.pdf
Info in <TCanvas::Print>: Current canvas added to pdf file plots.pdf
Info in <TCanvas::Print>: Current canvas added to Titel:page4 file plots.pdf

Gives the attached real pdf file.
plots.pdf (20.5 KB)

Thanks, and ok, I upgraded to this version and the pdf works. Though, now my plot looks like the one I attached and the compiler complains that it cannot include libEGPythia6.lib. Just to test I copied this file from the last root version.
I got this grid and the axis labels moved somewhere else. Everything else seems to work.
I’ll have to go through my code which got longer and longer.

Cheers,
delos

PS: this is what I include

[code]#pragma warning(disable: 4800)
#include <TQObject.h>
#include <RQ_OBJECT.h>
//#include “availLinkDef.h”
#include <TF1.h>
#include <TH1F.h>
#include <TGClient.h>
#include <TCanvas.h>
#include <TPDF.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>
#include <RQ_OBJECT.h>
#include <TGTextEntry.h>
#include <TGTextEdit.h>
#include <TGFileDialog.h>
#include <TGNumberEntry.h>
#include <TGButtonGroup.h>
#include <TGLabel.h>
#include <TGComboBox.h>
#include <TApplication.h>
#include <TPaveText.h>
#include <TGMsgBox.h>
#include <TGraph.h>
#include <TMultiGraph.h>
#include <TDatime.h>
#include <TLatex.h>
#include <TAxis.h>
#include <TBuffer.h>
#include <TStreamer.h>
#include <TStreamerInfoActions.h>
#include <TStreamerInfo.h>
#include <TMemberInspector.h>
#include <TROOT.h>
#include <TStyle.h>

#include
#include
using namespace std;
[/code]


For reference and as a possible workaround for those unable to use newer ROOT, the crash with “Title” in compiled build only seems like the one reported in bug ROOT-6302

this grid seems to be very long axis tick marks.

Hi

What tc3t wrote explains why “Titel:” lead to a crash, thank you. The grid is gone after I changed the offset of the labels by two orders of magnitude form 0.00001 to 0.001.
What’s left is the library libEGPythia6.lib that cannot be found. There is a libEGPythia8.lib in the folder though which probably should be loaded instead of the old version.

Thanks to all of you.

Cheers,
delos

May be make an other post with that… it is not a “PDF Issue” anymore.

By the way: the problem I described in my first post still persists. When I use “Title:” the program crashes.

Cheers,
delos

You mean this one: ?

{
   TCanvas* canvas = new TCanvas("canvas");
   TH1F* histo = new TH1F("histo","test 1",10,0.,10.);
   histo->SetFillColor(2);
   histo->Fill(2.);
   histo->Draw();
   canvas->Print("plots.pdf(","Title:page1");
   histo->Fill(4.);
   histo->Draw();
   canvas->Print("plots.pdf","Title:page2");
   histo->Fill(6.);
   histo->Draw();
   canvas->Print("plots.pdf","Title:page2");
   histo->Fill(8.);
   histo->Draw();
   canvas->Print("plots.pdf","Title:page3");
   histo->Fill(8.);
   histo->Draw();
   canvas->Print("plots.pdf)","Titel:page4");
}

The fix has been applied only to v6 branch.

Yes it was a bug fix applied on the head at that time.
Should it go also in 5.34 ?

Quite turkish to me, had never had any output like this. But to be frank I’m far from being a huge fan of using some code in order to work with pdf. I barely can say that I use them frequently as well, but when I do, it goes in quite rapid fashion, so I have no chance to use some slow software. And for purposes like this one, I usually rewrite old pdf with a new one and then merge them via tool provided by this website https://www.altomerge.com/ I know, it seems like not that dead simple solution as well, but nevertheless, it’s kicking in 100% of cases

I am not sure I understand what you are trying to say here. This post was about a bug which has been fixed … I do not think it needs more comments.