I am trying to convert a text file to pdf using the code lines below…
I tried with the latest and still the same issue.
loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Text;
Document doc = new Document(@"C:\Temp\test1.txt", loadOptions);
doc.FirstSection.PageSetup.TopMargin = 0;
doc.FirstSection.PageSetup.LeftMargin = 0;
Kulsum:Is there any other component from Aspose that is recommended for txt to pdf conversion.
kulsum.arif:Is there any other component from Aspose that is recommended for txt to pdf conversion.
Adding more to Awais’s comments, we also have a component named Aspose.Pdf for .NET which supports the feature to create as well as manipulate existing PDF files. It also offers the feature to convert text files to PDF format. Please note that during the conversion process, you can specify the formatting of text and also specify the Top, Left, Right, Bottom margin information. Please try using the following code snippet to accomplish your requirements.
For your reference, I have also attached the resultant PDF file which is generated over my end.
// read source text file System.IO.TextReader tr = new StreamReader("c:/pdftest/Test1.txt"); //Instantiate Pdf pbject by calling its empty constructor Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(); //Create a new section in the Pdf object Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add(); // set left and top margin for page sec1.PageInfo.Margin.Left = sec1.PageInfo.Margin.Top = 5; //Create a new text paragraph and pass the text to its constructor as argument Aspose.Pdf.Generator.Text t2 = new Aspose.Pdf.Generator.Text(tr.ReadToEnd()); // set the font size for text inside PDF file t2.TextInfo.FontSize = 12; // add text to paragraphs collection of section object sec1.Paragraphs.Add(t2); // save the PDF file pdf1.Save(“c:/pdftest/Test1.txt.Pdf”);
For further information, please visit How to Convert a text file to PDF.