使用python, aspose.pdf=25.5.0文档转换为pdf格式后,中文编程乱码,英文正常。容器里只有arial字体
Cause
The issue of Chinese characters appearing as garbled text after converting a Word document to PDF is often related to font compatibility. If the only font available in the container is Arial, it may not support Chinese characters properly, leading to this problem.
Solution
To resolve this issue, ensure that the fonts used in the Word document support Chinese characters. Here are the steps you should take:
-
Use a Compatible Font: Select a font that supports Chinese characters, such as SimSun, Microsoft YaHei, or Arial Unicode MS.
-
Embed Fonts in the PDF: When converting the document to PDF, ensure that the fonts are embedded. This will help preserve the appearance of the text in the PDF.
-
Set PDF Save Options: Use the appropriate save options when converting to PDF to ensure that the document structure and fonts are handled correctly.
Code
Here’s a sample code snippet to convert a Word document to PDF while ensuring that fonts are embedded:
using Aspose.Words;
using Aspose.Words.Saving;
Document doc = new Document("input.docx");
PdfSaveOptions saveOptions = new PdfSaveOptions
{
Compliance = PdfCompliance.PdfA1, // Choose the appropriate compliance level
EmbedFullFonts = true // Ensure fonts are embedded
};
doc.Save("output.pdf", saveOptions);
Next Steps
- Update your Word document to use a font that supports Chinese characters.
- Use the provided code snippet to convert your document to PDF, ensuring that fonts are embedded.
- Test the output PDF to verify that the Chinese characters are displayed correctly.
If you have any further questions or need additional assistance, please let me know!