Free Support Forum -

Specila Chars in Text file is not Shown in Converted PDF

Hi Aspose Team,
When I convert a text file having some special chars into pdf ,the chars are not displayed. Here I attached the text file.Reproduce the error on your side and provide me a solution.

Thanking You

Hello Surendrababu,

Thanks for using our products.

In order to convert Text file containing special characters, please first save the Text file with Unicode encoding and try using the following code snippet. Please notice that in following code snippet I have used Lucida Console font name as its the default font for NotePad and in order to make the characters properly visible, I have changed the font size to 14. Please take a look over the attached source Text file and resultant PDF document that I have generated with Aspose.Pdf for .NET 5.2.1.


//Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
System.IO.TextReader tr = new StreamReader("d:/pdftest/a1+(1).txt");
//Create a new section in the Pdf object
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
//Create a new text paragraph and pass the text to its constructor as argument

Aspose.Pdf.Text t2 = new Aspose.Pdf.Text(tr.ReadToEnd());
// specify the font face information for text object
t2.TextInfo.FontName = "Lucida Console";
// specify the font size information
t2.TextInfo.FontSize = 14;
// add the text paragraph to paragraphs collection of section object
// use this statement to auto adjust font according to Pdf contents
pdf1.IsAutoFontAdjusted = true;
// save the resultant PDF document

In case you still face any problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

Hi Nayyer Shahbaz,
Thank you for such a quick response.You asked to save the file in unicode encoding.If the user saved the text file in ANSI encoding, then how should we convert that text file?

with Regards

Hello Surendrababu,

In case you need to read text file with ANSI encoding, please try using the following code line to read the contents.

System.IO.TextReader tr = new StreamReader("d:/pdftest/a1+(1).txt",Encoding.GetEncoding(1252));

Besides this, I have used the same code snippet as shared in earlier post. In case you still face any problem or you have any further query, please feel free to contact.