Closed
Description
Problem description:
When using a custom font, saving the figure as pdf format, and then opening the pdf with adobe reader (or many other pdf readers except SumatraPDF), some characters don't display correctly.
I use windows 10 operating system. The font is for the Chinese language, and already install into C:\windows\fonts
Check the font
from matplotlib.font_manager import fontManager
for f in fontManager.ttflist:
if 'Source Han Serif' in f.name:
print(f.name, ' : ', f.fname)
Output:
Source Han Serif CN : C:\Windows\Fonts\SourceHanSerifCN-Regular.otf
Source Han Serif CN : C:\Windows\Fonts\SourceHanSerifCN-Bold.otf
Generate the figure
Code (a minimal and fully example)
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
plt.text(0.5, 0.5, '图像', ha='center', va='center',
fontdict={'family': 'Source Han Serif CN', 'size': 18})
plt.savefig('figure_with_font.pdf')
plt.savefig('figure_with_font.png')
There will be a warning message:
'SourceHanSerifCN-Regular.otf' cannot be subsetted into a Type 3 font. The entire font will be embedded in the output.
And the output in the notebook and the png format both displays correctly:
But when open figure_with_font.pdf
with "adobe reader", it displays like:
When I check the document properties, it seems like the font is already embedded in the pdf:
I've tried some other readers, only Sumatra PDF works.
**I'm using: **
- Windows 10
- matplotlib: 3.0.0
And The output pdf file:
Question:
- Can matplotlib save a figure to pdf without embedding the font? Sometimes when saving thousands of figures, it will help to reduce the file size.
- What's wrong with the pdf not displaying correctly?