We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to convert txt and rtf to pdf?

1. i want to convert txt files to pdf , but i just cannot find the code sample.

2.i convert rtf files to pdf the exactly same way with the way i convert MS Word files. i tested , and succeeded. but when my colleagues tried to use my executable to do convert rtf files , they failed.

the code is as follow:

MemoryStream docStream = new MemoryStream();
// New a Doc object.
doc = new Document(source);
// Save the doc in a xml fille that can be handled by Aspose.Pdf.
doc.Save(docStream, SaveFormat.AsposePdf);
// New a pdf object.
pdf = new Pdf();
// Bind content from the named xml file.
pdf.BindXML(docStream, null);
// Save the result
//close stream

3.By the way , when i came to your forum , i wanted to search my questions myself , but you just do not enable me to do so .

this is the file i mensioned


Thank you for considering Aspose.

1. Here is the code:

System.IO.TextReader tr = new StreamReader("C:/Test.txt");

//Instantiate Pdf pbject by calling its empty constructor

Pdf pdf1 = new Pdf();

//Create a new section in the Pdf object

Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

//Set the left margin of the section

sec1.PageInfo.Margin.Left = 110;

//Set the right margin of the section

sec1.PageInfo.Margin.Right = 120;

//Create a new text paragraph and pass the text to its constructor as argument

Text t2 = new Text(tr.ReadToEnd());



2. We didn't support SimSun font hence you are having problem converting this file to PDF. As a workaround just SelectAll text and set their font to "Times New Roman" and then run the same code again.

3. About the third problem I am able to search, what kind of problem you are having. Can you please elaborate.


can not convert txt file that is more than 1kb, it says:

Length cannot be less than zero.
Parameter name: length


Can you please provide the txt file that you are having problems with.