exportgraphics seems to embed fonts incorrectly

68 次查看(过去 30 天)
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

回答(2 个)

Daniel
Daniel 2022-5-12
Unfortunately correct exporting (embedding) of fonts is still not fixed in 2022a, which is a bit disappointing. Unclear what fonts are supported for export, and why Matlab has this limitation, while other softwares seem to handle/export/embedd these fonts without issues.
The same issue applies for saving pdfs with "saveas" and "print" and has been around for several releases, but used to work in the past.
Saving to .svg and then run a Matlab "system" command to automatically execute the svg-to-pdf conversion by calling Inkscape works but it takes time and is annoying.

Kiran Felix Robert
Kiran Felix Robert 2021-6-21
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 个评论
Lars Bielak
Lars Bielak 2021-6-21
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by