Title: Characters doesn't display correctly when figure saved as pdf with a custom font · Issue #12636 · matplotlib/matplotlib · GitHub
Open Graph Title: Characters doesn't display correctly when figure saved as pdf with a custom font · Issue #12636 · matplotlib/matplotlib
X Title: Characters doesn't display correctly when figure saved as pdf with a custom font · Issue #12636 · matplotlib/matplotlib
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...
Open Graph 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 displ...
X 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 d...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/12636
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Characters doesn't display correctly when figure saved as pdf with a custom font","articleBody":"# Problem description:\r\n\r\nWhen using [a custom font](https://github.com/adobe-fonts/source-han-serif/blob/release/SubsetOTF/CN/SourceHanSerifCN-Regular.otf), saving the figure as pdf format, and then opening the pdf with adobe reader (or many other pdf readers except [SumatraPDF](https://www.sumatrapdfreader.org/free-pdf-reader.html)), some characters don't display correctly.\r\n\r\nI use windows 10 operating system. The font is for the Chinese language, and already install into `C:\\windows\\fonts`\r\n\r\n## Check the font\r\n\r\n```\r\nfrom matplotlib.font_manager import fontManager\r\nfor f in fontManager.ttflist:\r\n if 'Source Han Serif' in f.name:\r\n print(f.name, ' : ', f.fname)\r\n```\r\n\r\n**Output:**\r\n\r\n```\r\nSource Han Serif CN : C:\\Windows\\Fonts\\SourceHanSerifCN-Regular.otf\r\nSource Han Serif CN : C:\\Windows\\Fonts\\SourceHanSerifCN-Bold.otf\r\n```\r\n\r\n## Generate the figure\r\n\r\n**Code** (a minimal and fully example)\r\n```\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.font_manager import FontProperties\r\nplt.text(0.5, 0.5, '图像', ha='center', va='center', \r\n fontdict={'family': 'Source Han Serif CN', 'size': 18})\r\nplt.savefig('figure_with_font.pdf')\r\nplt.savefig('figure_with_font.png')\r\n```\r\n\r\nThere will be a warning message:\r\n```\r\n'SourceHanSerifCN-Regular.otf' cannot be subsetted into a Type 3 font. The entire font will be embedded in the output.\r\n```\r\n\r\nAnd the output in the notebook and the png format both displays correctly:\r\n\r\n\r\nBut when open `figure_with_font.pdf` with \"adobe reader\", it displays like:\r\n\r\n\r\nWhen I check the document properties, it seems like the font is already embedded in the pdf:\r\n\r\n\r\nI've tried some other readers, only [Sumatra PDF](https://www.sumatrapdfreader.org/free-pdf-reader.html) works.\r\n\r\n**I'm using: **\r\n\r\n1. Windows 10\r\n2. matplotlib: 3.0.0\r\n\r\n**And The output pdf file:**\r\n\r\n[figure_with_font.pdf](https://github.com/matplotlib/matplotlib/files/2518262/figure_with_font.pdf)\r\n\r\n## Question:\r\n\r\n* 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.\r\n* What's wrong with the pdf not displaying correctly?\r\n\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/gepcel","@type":"Person","name":"gepcel"},"datePublished":"2018-10-26T07:56:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/12636/matplotlib/issues/12636"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:33ca4616-5e5a-cc7a-db87-99c58357c20c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B02E:240794:2B887C:38C244:6A52F57A |
| html-safe-nonce | 8ae33923922f387f0001bf5bc276dc18fbb53cbdcefea0cdbf85550c5a7537c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDJFOjI0MDc5NDoyQjg4N0M6MzhDMjQ0OjZBNTJGNTdBIiwidmlzaXRvcl9pZCI6IjExODI1NzQ0NTQ1MjM0OTE3MDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5f8b8515bd224c3fec194cc74f0b8db8aaf42925df2d84cbbc328696a0cf6d93 |
| hovercard-subject-tag | issue:374268527 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/12636/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2b21a6630d1db0540f6762112a5fb5fb3659bcff517b5b14952004fc166accdb/matplotlib/matplotlib/issues/12636 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2b21a6630d1db0540f6762112a5fb5fb3659bcff517b5b14952004fc166accdb/matplotlib/matplotlib/issues/12636 |
| og:image:alt | 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 displ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gepcel |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width