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

Free Support Forum - aspose.com

Convert from txt to PDF results in empty PDF

I am able to convert many text files without problems. But the particular below gives me empty PDF.


Code is simple in .NET.

  1. load text into memory stream
  2. convert memorystream to pdf

pdfDocument.Convert(ms, pdfFormat, ConvertErrorAction.None)


Thank you for contacting support.

We have been able to convert mentioned TXT file to a PDF document using below code with Aspose.PDF for .NET 18.12. Generated PDF file has been attached for your kind reference. TexttoPDF_18.12.pdf

// Read the source text file
TextReader tr = new StreamReader(dataDir + "AcademyTESTVisualCron.txt");

// Instantiate a Document object by calling its empty constructor
Document doc = new Document();

// Add a new page in Pages collection of Document
Aspose.Pdf.Page page = doc.Pages.Add();

// Create an instance of TextFragmet and pass the text from reader object to its constructor as argument
TextFragment text = new TextFragment(tr.ReadToEnd());

// Add a new text paragraph in paragraphs collection and pass the TextFragment object

// Save resultant PDF file
doc.Save(dataDir + "TexttoPDF_18.12.pdf"); 

In case the issue persists, please share narrowed down code snippet so that we may reproduce and investigate it in our environment.