using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace ExtractText
{
    public partial class Form1 : Form
    {
        // This sample uses the ActiveX edition of PDF Library.
        // So you will need to register the ActiveX component via the command line
        // and add it as a reference to this project before you can proceed.
        // regsvr32 PDFlibAX.dll

        // Initiate an instance of the library
        PDFlibAX.PDFlibrary pdf = new PDFlibAX.PDFlibrary();

        public Form1()
        {
            InitializeComponent();
        }

        private void btnDAExtractPageText_Click(object sender, EventArgs e)
        {

            // Declare the variables necessary for the DAOpenFile function
            string InputFileName = @"..\..\..\Sample1.pdf";
            string Password = null;
            int FileHandle;
            int Page = 1;
            int PageRef;
            
            // Declare the variables necessary for the DAFindPage function
            FileHandle = pdf.DAOpenFile(InputFileName, Password);
            PageRef = pdf.DAFindPage(FileHandle, Page);

            // Declare the variables necessary for the DAExtractPageText function
            int Options = 2; // Review the function reference for available options
            string txtOutput = "";

            txtOutput = pdf.DAExtractPageText(FileHandle, PageRef, Options);
            
            // Display the text output in a message box
            MessageBox.Show(txtOutput);

            // Write the text output to a text file on the hard disk
            File.WriteAllText(@"DAExtractPageText.txt", txtOutput);

            // Close the file so that it can be access by other processes on the machine
            pdf.DACloseFile(FileHandle);
        }

        private void btnExtractFilePageText_Click(object sender, EventArgs e)
        {

            // Declare the variables necessary for the ExtractFilePageContent function
            string InputFileName = @"..\..\..\Sample1.pdf";
            string Password = "";
            int Page = 1;
            int Options = 2; // Review the function reference for available options
            string txtOutput = "";

            txtOutput = pdf.ExtractFilePageText(InputFileName, Password, Page, Options);

            // Display the text output in a message box
            MessageBox.Show(txtOutput);

            // Write the text output to a text file on the hard disk
            File.WriteAllText(@"ExtractFilePageText.txt", txtOutput);
        }

        private void btnGetPageText_Click(object sender, EventArgs e)
        {

            // Declare variables for the LoadFromFile and SelectPage functions
            string InputFileName = @"..\..\..\Sample1.pdf";
            string Password = "";
            int Page = 1;

            pdf.LoadFromFile(InputFileName, Password);
            pdf.SelectPage(Page);

            // Declare the variables necessary for the GetPageText function
            int ExtractionOptions = 0; // Review the function reference for available options
            string txtOutput = "";

            txtOutput = pdf.GetPageText(ExtractionOptions);

            // Display the text output in a message box
            MessageBox.Show(txtOutput);

            // Write the text output to a text file on the hard disk
            File.WriteAllText(@"GetPageText.txt", txtOutput);
        }
    }
}