Hi Aspose Team,
We are using Aspose.Pdf to convert Text file to PDF and we encountered this problem: Text file in Korean and Simplified Chinese could not be converted correctly. We installed Chinese and Korean in the system language settings, but still couldn’t.
Here are our txt file and pdf file Txt to Pdf Sample.zip (92.4 KB)
Here is our sample code:
TextReader tr = new StreamReader(TxtName);
Document pdfDocument = new Document();
Page page = pdfDocument.Pages.Add();
TextFragment text = new TextFragment(tr.ReadToEnd());
page.Paragraphs.Add(text);
pdfDocument.Save(Path.GetDirectoryName(TxtName) + "\\" + Path.GetFileNameWithoutExtension(TxtName) + ".pdf");
Please help us. Thank You.
@Glority_Developer
The issue seems related to missing fonts in your system. Please try to install fonts that support used language characters e.g. Arial Unicode MS. We have installed this font and tried to convert your .txt file into PDF. We did not notice any issue in the output file.
output.pdf (212.7 KB)
We installed the Arial Unicode MS font, and now we can successfully convert sample.txt to pdf.
But I still have a question. On our system, there are other fonts that support Chinese and Korean (such as SimSun which supports Chinese). Why are these fonts not used during conversion?
@Glority_Developer
The API uses the fonts among 14 core fonts installed in the system. If you need to use any other font during PDF generation, you have to specify it like in the below code snippet:
TextReader tr = new StreamReader(dataDir + "sample.txt");
Document pdfDocument = new Document();
Page page = pdfDocument.Pages.Add();
TextFragment text = new TextFragment(tr.ReadToEnd());
text.TextState.Font = FontRepository.FindFont("SimSun"); // <= this should not be added if font is installed. It should be automatically picked by the API
page.Paragraphs.Add(text);
pdfDocument.Save(dataDir + "output.pdf");
However, we have logged an investigation ticket as PDFNET-49308 to analyze the feasibility where API should auto-select the supported font from system if installed. We will surely look into details of the ticket and let you know as soon as it is resolved. Please be patient and spare us some time.
We apologize for the inconvenience.
Thanks for your help and looking forward to the new version to solve it.
1 Like