This PR fixes the bug that Unicode characters can't be rendered in vscode-pdfviewer by setting the right cMapUrl option of the PDF viewer.
cmaps are short for "character maps" and it's required by the core when rendering Unicode characters in PDF. By default, the option's value is ../web/cmaps (code). This will work if we are using the default web/viewer.html packaged in the dist of pdf.js. But because the PDF viewer is rendered inside an iframe in VS Code, ../web/cmaps isn't the right relative path for the cmaps. To fix the bug, we need to set the right cmap URL before rendering the PDF.
The PDF viewer has an option cMapUrl which tells it where to find the cmap files (ref). We can get the URL of the cmaps in pdfPreview.ts and set the option on load.
Because pdf.js expects the option to have trailing slash, the trailing slash after cmaps when generating the URL is required.
Tested with a few PDFs with Chinese characters and they are rendered without problems.
This PR fixes the bug that Unicode characters can't be rendered in vscode-pdfviewer by setting the right
cMapUrl
option of the PDF viewer.cmaps
are short for "character maps" and it's required by the core when rendering Unicode characters in PDF. By default, the option's value is../web/cmaps
(code). This will work if we are using the defaultweb/viewer.html
packaged in the dist of pdf.js. But because the PDF viewer is rendered inside an iframe in VS Code,../web/cmaps
isn't the right relative path for the cmaps. To fix the bug, we need to set the right cmap URL before rendering the PDF.The PDF viewer has an option
cMapUrl
which tells it where to find the cmap files (ref). We can get the URL of the cmaps inpdfPreview.ts
and set the option on load.Because pdf.js expects the option to have trailing slash, the trailing slash after
cmaps
when generating the URL is required.Tested with a few PDFs with Chinese characters and they are rendered without problems.