Click or drag to resize

PdfToTextClient Class

Pdf To Text Conversion with SelectPdf Online API.
Inheritance Hierarchy

Namespace:  SelectPdf.Api
Assembly:  SelectPdf.Api (in SelectPdf.Api.dll) Version: 1.4.0
Syntax
public class PdfToTextClient : ApiClient

The PdfToTextClient type exposes the following members.

Constructors
  NameDescription
Public methodPdfToTextClient
Construct the Pdf To Text Client.
Top
Methods
  NameDescription
Public methodgetNumberOfPages
Get the number of pages processed from the PDF document.
Public methodgetTextFromFile
Get the text from the specified pdf.
Public methodgetTextFromFileAsync
Get the text from the specified pdf with an asynchronous call.
Public methodgetTextFromFileToFile
Get the text from the specified pdf and write it to the specified text file.
Public methodgetTextFromFileToFileAsync
Get the text from the specified pdf with an asynchronous call and write it to the specified text file.
Public methodgetTextFromFileToStream
Get the text from the specified pdf and write it to the specified stream.
Public methodgetTextFromFileToStreamAsync
Get the text from the specified pdf with an asynchronous call and write it to the specified stream.
Public methodgetTextFromUrl
Get the text from the specified pdf.
Public methodgetTextFromUrlAsync
Get the text from the specified pdf with an asynchronous call.
Public methodgetTextFromUrlToFile
Get the text from the specified pdf and write it to the specified text file.
Public methodgetTextFromUrlToFileAsync
Get the text from the specified pdf with an asynchronous call and write it to the specified text file.
Public methodgetTextFromUrlToStream
Get the text from the specified pdf and write it to the specified stream.
Public methodgetTextFromUrlToStreamAsync
Get the text from the specified pdf with an asynchronous call and write it to the specified stream.
Public methodsearchFile(String, String)
Search for a specific text in a PDF document. The search is case insensitive and returns partial words also.
Public methodsearchFile(String, String, Boolean, Boolean)
Search for a specific text in a PDF document.
Public methodsearchFileAsync(String, String)
Search for a specific text in a PDF document with an asynchronous call. The search is case insensitive and returns partial words also.
Public methodsearchFileAsync(String, String, Boolean, Boolean)
Search for a specific text in a PDF document with an asynchronous call.
Public methodsearchUrl(String, String)
Search for a specific text in a PDF document. The search is case insensitive and returns partial words also.
Public methodsearchUrl(String, String, Boolean, Boolean)
Search for a specific text in a PDF document.
Public methodsearchUrlAsync(String, String)
Search for a specific text in a PDF document with an asynchronous call. The search is case insensitive and returns partial words also.
Public methodsearchUrlAsync(String, String, Boolean, Boolean)
Search for a specific text in a PDF document with an asynchronous call.
Public methodsetCustomParameter
Set a custom parameter. Do not use this method unless advised by SelectPdf.
Public methodsetEndPage
Set End Page number. Default value is 0 (process till the last page of the document).
Public methodsetOutputFormat
Set the output format. The default value is OutputFormat.Text.
Public methodsetStartPage
Set Start Page number. Default value is 1 (first page of the document).
Public methodsetTextLayout
Set the text layout. The default value is TextLayout.Original.
Public methodsetTimeout
Set the maximum amount of time (in seconds) for this job.
Public methodsetUserPassword
Set PDF user password.
Top
Examples
Sample Code - Pdf To Text:
using System;
using SelectPdf.Api;

namespace SelectPdf.Api.Tests
{
    class Program
    {
        static void Main(string[] args)
        {
            string testUrl = "https://selectpdf.com/demo/files/selectpdf.pdf";
            string testPdf = "Input.pdf";
            string localFile = "Result.txt";
            string apiKey = "Your API key here";

            Console.WriteLine("This is SelectPdf-{0}.", ApiClient.CLIENT_VERSION);

            try
            {
                PdfToTextClient client = new PdfToTextClient(apiKey);

                // set parameters - see full list at https://selectpdf.com/pdf-to-text-api/
                client
                    .setStartPage(1) // start page (processing starts from here)
                    .setEndPage(0) // end page (set 0 to process file til the end)
                    .setOutputFormat(OutputFormat.Text) // set output format (0-Text or 1-HTML)
                ;

                Console.WriteLine("Starting pdf to text ...");

                // convert local pdf to local text file
                client.getTextFromFileToFile(testPdf, localFile);

                // extract text from local pdf to memory
                // string text = client.getTextFromFile(testPdf);
                // print text
                // Console.WriteLine(text);

                // convert pdf from public url to local text file
                // client.getTextFromUrlToFile(testUrl, localFile);

                // extract text from pdf from public url to memory
                // string text = client.getTextFromUrl(testUrl);
                // print text
                // Console.WriteLine(text);

                Console.WriteLine("Finished! Number of pages processed: {0}.", client.getNumberOfPages());

                // get API usage
                UsageClient usageClient = new UsageClient(apiKey);
                UsageInformation usage = usageClient.getUsage(false);
                Console.WriteLine("Conversions remained this month: {0}.", usage.Available);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: " + ex.Message);
            }
        }
    }
}
Sample Code - Search Pdf:
using System;
using SelectPdf.Api;

namespace SelectPdf.Api.Tests
{
    class Program
    {
        static void Main(string[] args)
        {
            string testUrl = "https://selectpdf.com/demo/files/selectpdf.pdf";
            string testPdf = "Input.pdf";
            string apiKey = "Your API key here";

            Console.WriteLine("This is SelectPdf-{0}.", ApiClient.CLIENT_VERSION);

            try
            {
                PdfToTextClient client = new PdfToTextClient(apiKey);

                // set parameters - see full list at https://selectpdf.com/pdf-to-text-api/
                client
                    .setStartPage(1) // start page (processing starts from here)
                    .setEndPage(0) // end page (set 0 to process file til the end)
                    .setOutputFormat(OutputFormat.Text) // set output format (0-Text or 1-HTML)
                ;

                Console.WriteLine("Starting search pdf ...");

                // search local pdf
                IList&TextPosition> results = client.searchFile(testPdf, "pdf");

                // search pdf from public url
                // IList&TextPosition> results = client.searchUrl(testUrl, "pdf");

                Console.WriteLine("Search results:\n{0}\nSearch results count: {1}.", string.Join("\n", results), results.Count);

                Console.WriteLine("Finished! Number of pages processed: {0}.", client.getNumberOfPages());

                // get API usage
                UsageClient usageClient = new UsageClient(apiKey);
                UsageInformation usage = usageClient.getUsage(false);
                Console.WriteLine("Conversions remained this month: {0}.", usage.Available);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: " + ex.Message);
            }
        }
    }
}
See Also