Example #1
0
    static void Main(string[] args)
    {
        // TODO: Specify the URL of your PDF document here.
        string pdfUrl = "https://www.harvesthousepublishers.com/data/files/excerpts/9780736948487_exc.pdf";

        PdfTextExtractor pdfTextExtractor = new PdfTextExtractor();

        try {
            // Step 1: Submit a conversion job with the URL of your PDF file.
            string jobId = pdfTextExtractor.submitJob(pdfUrl);
            Console.WriteLine("The following job has been submitted:");
            Console.WriteLine(jobId);
            Console.WriteLine();

            Boolean doneProcessing = false;
            while (!doneProcessing)
            {
                Console.WriteLine("Sleeping for 60 seconds");
                Thread.Sleep(60 * 1000);

                // Step 2: Check the status of the job every 60 seconds or so
                string status = pdfTextExtractor.checkJobStatus(jobId);
                if (status.Equals("Completed"))
                {
                    doneProcessing = true;
                }
                else if (status.StartsWith("Failed"))
                {
                    doneProcessing = true;
                    Console.WriteLine("Something went wrong! Status was: " + status);
                    Console.WriteLine("Exiting ...");
                    Environment.Exit(2);
                    // IF you are using a Windows Forms based application:
                    // Application.Exit();
                }
            }

            // Step 3: Retrieve the text when the job is Completed
            string pdfText = pdfTextExtractor.retrieveText(jobId);
            Console.WriteLine("THE TEXT OF THE PDF FILE IS AS FOLLOWS:");
            Console.WriteLine(pdfText);
        }
        catch (Exception ex) {
            Console.WriteLine("OMG. Something weng wrong. The following exception was thrown: ");
            Console.WriteLine(ex);
        }

        Console.WriteLine("===============================");
        Console.WriteLine("Press Enter to exit.");
        Console.WriteLine("===============================");
        Console.ReadLine();
    }