Explorar el Código

Merge pull request #430 from mydreamworldpolly/mydreamworldpolly-patch-1-Fix-issues-UnicodeDecodeError-'utf-8'-codec

Update converter.py
Byaidu hace 1 año
padre
commit
03c5cd45ab
Se han modificado 1 ficheros con 4 adiciones y 1 borrados
  1. 4 1
      pdf2zh/converter.py

+ 4 - 1
pdf2zh/converter.py

@@ -188,7 +188,10 @@ class TranslateConverter(PDFConverterEx):
 
         def vflag(font: str, char: str):    # 匹配公式(和角标)字体
             if isinstance(font, bytes):     # 不一定能 decode,直接转 str
-                font = str(font)
+                try:
+                    font = font.decode('utf-8')  # 尝试使用 UTF-8 解码
+                except UnicodeDecodeError:
+                    font = ""
             font = font.split("+")[-1]      # 字体名截断
             if re.match(r"\(cid:", char):
                 return True