Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing pad to pdf is missing endobj in some cases #13560

Closed
1 task done
hpekeler opened this issue Aug 29, 2023 · 20 comments
Closed
1 task done

Printing pad to pdf is missing endobj in some cases #13560

hpekeler opened this issue Aug 29, 2023 · 20 comments
Assignees
Labels

Comments

@hpekeler
Copy link

Check duplicate issues.

  • Checked for duplicates

Description

I played around with printing a canvas to pdf, using the EmbedFonts option or not. During EmbedFonts, where ghostcsript is called, it complaines about missing endobj in the pdf file. As far as i understand it is just a warning and the output still looks correct.

Still, no need for this warning. Why not just print the endobj?

Also: ghostscript option -dUseCIEColor is deprecated for gs > 9.11 One could remove this option in the print.

Changes to the ROOT code:
graf2d/postscript/src/TPDF.cxx:
Add PrintStr("endobj@"); at the end of the "/Title (Page" blocks and the "/Title (Contents" block.

graf2d/gpad/src/TPad.cxx:
remove option -dUseCIEColor from the gs system call.

After this two changes, everything is fine for me again. No more warnings. And output looks still the same.

Reproducer

ROOT macro: (Macro.cpp)

{
TCanvas *c1=new TCanvas("c1","c1");
double *a=new double[3];
a[0]=1;a[1]=2;a[2]=3;
TGraph *g=new TGraph(3,a,a);
g->Draw();
c1->Print("Test.pdf","EmbedFonts");
}

Run with: root -l -b -q Macro.cpp

ROOT version

ROOT version: 6.24/08

Installation method

yum

Operating system

CentOS7

Additional context

No response

@hpekeler hpekeler added the bug label Aug 29, 2023
@couet couet self-assigned this Aug 29, 2023
@couet
Copy link
Member

couet commented Aug 29, 2023

I ran your macro on Mac. The generated file is attached. It can be opened without problem using the Mac utility "Preview".
Test.pdf

@hpekeler
Copy link
Author

Yes opening the pdf is fine. i just get warnings when using ghostscript to convert the pdf with EmbedFonts. These are not critical but also not needed in my opinion. One could just get rid of them by implementing the endobj lines.

Do you not get warnings during the macro from ghostscript on mac?

@couet
Copy link
Member

couet commented Aug 29, 2023

I do not see any warnings with gs:

% gs Test.pdf
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
>>showpage, press <return> to continue<<

@hpekeler
Copy link
Author

I mean the ghostscript which is called inside of c1->Print().
EndObj

@couet
Copy link
Member

couet commented Aug 29, 2023

I get this:

root [0] TCanvas *c1=new TCanvas("c1","c1");
root [1] double *a=new double[3];
root [2] a[0]=1;a[1]=2;a[2]=3;
root [3] TGraph *g=new TGraph(3,a,a);
root [4] g->Draw();
root [5] c1->Print("Test.pdf","EmbedFonts");
Info in <TCanvas::Print>: EmbedFonts file Test.pdf has been created
root [6] 

@hpekeler
Copy link
Author

Ok strange. Maybe it is due to gs version? I am using default centos7 version and i get the warnings.
GPL Ghostscript 9.25 (2018-09-13)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.

@couet
Copy link
Member

couet commented Aug 29, 2023

Let me check if Ghostscript is really called in my case...

@hpekeler
Copy link
Author

I do not see any warnings with gs:

% gs Test.pdf
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
>>showpage, press <return> to continue<<

you version is defnitly different to mine. Maybe they changed something over the years and now these warnings apear.

@couet
Copy link
Member

couet commented Aug 29, 2023

The command executed by root is:

gs -quiet -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dUseCIEColor -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=pdf_temp.pdf -f Test.pdf

I tried on an other Mac with a more recent version of gs and I see also the error message. I am investigating.

root [5] c1->Print("Test.pdf","EmbedFonts");
Info in <TCanvas::Print>: EmbedFonts file Test.pdf has been created
GPL Ghostscript 9.55.0: 

Use of -dUseCIEColor detected!
Since the release of version 9.11 of Ghostscript we recommend you do not set
-dUseCIEColor with the pdfwrite/ps2write device family.

   **** Error: Encountered 'obj' while expecting 'endobj'.
               Treating this as a missing 'endobj', output may be incorrect.
   **** Error: Encountered 'obj' while expecting 'endobj'.
               Treating this as a missing 'endobj', output may be incorrect.
GPL Ghostscript 9.55.0: 

Use of -dUseCIEColor detected!
Since the release of version 9.11 of Ghostscript we recommend you do not set
-dUseCIEColor with the pdfwrite/ps2write device family.

root [6] 

@hpekeler
Copy link
Author

very good. I actually linked a fix to this messages directly in the start of my bug report.

@hpekeler
Copy link
Author

Changes to the ROOT code:
graf2d/postscript/src/TPDF.cxx:
Add PrintStr("endobj@"); at the end of the "/Title (Page" blocks and the "/Title (Contents" block.

graf2d/gpad/src/TPad.cxx:
remove option -dUseCIEColor from the gs system call.

This solves the warnings

@couet
Copy link
Member

couet commented Aug 29, 2023

The PR to fix the problem is ready: #13564
Thanks for the report.

@hpekeler
Copy link
Author

Thanks for fixing so quickly! I had a brief look at the PR and i think you missed one EndObject()
Around line 1500 in the if(fNbPage>1) condition, there is not EndObject at the end of that condition.
It wasnt before the PR and is not present in the PR if i am not mistaken.

@couet
Copy link
Member

couet commented Aug 29, 2023

I'll check

@couet
Copy link
Member

couet commented Aug 29, 2023

Yes you are right, with the follwing example the new mechanism I introduced shows warnings:

{

TFile f("hsimple.root","READ");

c1 = new TCanvas("c1","c1",200,10,700,500);
c2 = new TCanvas("c2","c2",200,300,700,500);

hpx->SetTitle("#alpha");
c1->cd(); hpx->Draw();
c2->cd(); hpx->Draw();

c1->Print("h1.pdf[");
c2->Print("h1.pdf", "Title:aaa");
c2->Print("h1.pdf", "Title:Verrex");
c1->Print("h1.pdf", "Title:bbb");
c1->Print("h1.pdf]");

} 

@couet
Copy link
Member

couet commented Aug 29, 2023

fixed

@hpekeler
Copy link
Author

Thanks!

@couet
Copy link
Member

couet commented Aug 30, 2023

I'll commit it today. There is a few more details to check.

@couet
Copy link
Member

couet commented Aug 30, 2023

The PR is now merged. Thanks for reporting this issue.

@couet couet closed this as completed Aug 30, 2023
@github-actions
Copy link

Hi @couet,

It appears this issue is closed, but wasn't yet added to a project. Please add upcoming versions that will include the fix, or 'not applicable' otherwise.

Sincerely,
🤖

@couet couet added this to Issues in Fixed in 6.30/00 via automation Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

No branches or pull requests

2 participants