Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Chinese display incorrectly

$
0
0
Hello,

I created a program which replace some word to Chinese word. It work fine on my desktop (Win 7). But when it run on another computer (Win Server 2003), PDF will display totally different Chinese word (I view both PDF in Win 7). 

Here is my code snippet:

byte[] byteTemplate = File.ReadAllBytes("test.pdf");
MemoryStream ms = new MemoryStream(byteTemplate);
Aspose.Pdf.Document pdfDoc = null;
pdfDoc = new Aspose.Pdf.Document(ms);

string[,] temp = new string[,] { { "[TEMP_ENG]", "Hello!" }, { "[TEMP_CHI]", "你好!" } };

if (pdfDoc != null)
{
for (int i = 0; i <= temp.GetUpperBound(0); i++)
{
Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber(temp[i, 0]);
pdfDoc.Pages.Accept(textFragmentAbsorber);

Aspose.Pdf.Text.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (Aspose.Pdf.Text.TextFragment textFragment in textFragmentCollection)
{
textFragment.Text = temp[i, 1];
}
}
}

pdfDoc.Flatten();

System.IO.MemoryStream pdfStream = new System.IO.MemoryStream();
pdfDoc.Save(pdfStream);
byte[] resultFile = new byte[pdfStream.Length];

pdfStream.Seek(0, System.IO.SeekOrigin.Begin);
pdfStream.Read(resultFile, 0, (int)pdfStream.Length);
pdfStream.Close();

string fileName = DateTime.Now.ToString("hhmmss") + ".pdf";
File.WriteAllBytes(fileName, resultFile);

ms.Close();

If the program is run on Win 7, correct word ("你好!") shows in PDF. But if the program is run on Win Server 2003, correct word ("你好!") displays as other Chinese word ("㬢圄"). The strange thing is if I select wrong Chinese word ("㬢圄") and copy and paste in Notepad, correct Chinese ("你好!") is shown in Notepad.

Is there something wrong in my program? Or some font is missing in Win Server 2003? 

Thanks!

Viewing all articles
Browse latest Browse all 3131

Trending Articles