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

Free Support Forum - aspose.com

Text file to pdf


Is there an easy way to create a pdf-file from an existing txt-file ?

I'm using aspose.pdf for java.


Goddeau Hendrik


Thank you for considering Aspose.

The only way I think is to read the txt file in string and add it using the Text class object and assign that object to paragraph.


Sorry, We did not provide a convenient method to create a pdf-file from an existing txt-file.

I think you can get a file stream from the txt-file, and then construct a loop in which you can read from the stream, construct a Text, and add to the document. Then you can transform the txt-file to a pdf-file.

can you provide a code sample of something like this in c#?


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());