MATLAB Answers

exportgraphics seems to embed fonts incorrectly

6 views (last 30 days)
Lars Bielak
Lars Bielak on 18 Jun 2021
Commented: Lars Bielak on 21 Jun 2021
Hi,
I am trying to make a PDF figure using exportgraphics, with the Neo Euler font. When I export the graphics, some PDF viewers correctly show the graphics (Sumatra PDF, Foxit viewer), and some dont (Adobe Acrobat, PDF import to Inkscape). Specifically, some characters are exchanged (here: a space becomes an 8 in Adobe). This is not consistent, as for the actual figure (not the minimal example) different characters are replaced (T by e).
Here is a minimal example of the figure:
% Make a figure
f1 = figure('DefaultTextFontName', 'Palatino Linotype');
% create axes
ax1 = axes();
ax1.FontName = 'Neo Euler';
% add text
annotation('textbox',[0.3 0.5 0.4 0.1],'String','M_0 e^{-t/T_2^\ast}','FontName','Palatino Linotype');
annotation('textbox',[0.3 0.3 0.4 0.1],'String','M_0 e^{-t/T_2^\ast}','FontName','Neo Euler');
% export
exportgraphics(f1,'FontTest.pdf','ContentType','vector','Resolution',800)
I'm using Matlab 9.8.0.1323502 (R2020a), and Windows 10 version 1909 64 Bit.
Any help is greatly appreciated!
LB
Screenshot Sumatra PDF
and a screenshot from Acrobat

Answers (1)

Kiran Felix Robert
Kiran Felix Robert on 21 Jun 2021
Hi Lars,
I was not able to exactly reproduce your issue, but this behavior has been observed on all platforms.
The reason for font substitution is for legacy print compatibility because not every font is supported for graphics export.
If you do not require vector graphics, use the following workaround:
% Make a figure
f1 = figure('DefaultTextFontName', 'Palatino Linotype');
% create axes
ax1 = axes();
ax1.FontName = 'Neo Euler';
% add text
annotation('textbox',[0.3 0.5 0.4 0.1],'String','M_0 e^{-t/T_2^\ast}','FontName','Palatino Linotype');
annotation('textbox',[0.3 0.3 0.4 0.1],'String','M_0 e^{-t/T_2^\ast}','FontName','Neo Euler');
% export
print -dpdf -opengl FontTest.pdf
exportgraphics(f1,'FontTest.pdf','ContentType','vector','Resolution',800)
  1 Comment
Lars Bielak
Lars Bielak on 21 Jun 2021
Hi Kiran,
thanks for the explanation. Unfortunately, I need the vector graphics format, and I'd also like to keep the figure size (page size) when I export.
So I guess I found a workaround: instead of exporting directly, I use
saveas(f1,'FontTest.svg')
and then use inkscape to convert the svg to a pdf.
From what I can see in my figure, the issue is resolved and all requirements are met.

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by