Convert PDF to text

Aspose.PDF for .NET support converting whole PDF document and single page to a Text file.

Convert whole PDF document to Text file

You can convert PDF document to TXT file using Visit method of TextAbsorber class.

The following code snippet explains how to extract the texts from the all pages.

public static void ConvertPDFDocToTXT()
{
    // Open document
    Document pdfDocument = new Document(_dataDir + "demo.pdf");
    TextAbsorber ta = new TextAbsorber();
    ta.Visit(pdfDocument);
    // Save the extracted text in text file
    File.WriteAllText(_dataDir + "input_Text_Extracted_out.txt",ta.Text);
}

Convert PDF page to text file

You can convert PDF document to TXT file with Aspose.PDF for .NET. You should use Visit method of TextAbsorber class for resolve this task.

The following code snippet explains how to extract the texts from the particular pages.

public static void ConvertPDFPagestoTXT()
{
    Document pdfDocument = new Document(System.IO.Path.Combine(_dataDir, "demo.pdf"));
    TextAbsorber ta = new TextAbsorber();
    var pages = new [] {1, 3, 4};
    foreach (var page in pages)
    {
        ta.Visit(pdfDocument.Pages[page]);
    }
    
    // Save the extracted text in text file
    File.WriteAllText(System.IO.Path.Combine(_dataDir, "input_Text_Extracted_out.txt"), ta.Text);
}