コード例 #1
0
        // Saving PDF file
        public bool SavePDF(string szPdfPathConst, string sFullPath)
        {
            //Declaring Variables
            bool SaveAs;

            try
            {
                //IAC objects
                CAcroPDDoc pdDoc;
                CAcroAVDoc avDoc;

                //set AVDoc object
                avDoc = new AcroAVDocClass();

                //open the PDF
                if (avDoc.Open(szPdfPathConst, ""))
                {
                    //set the pdDoc object and get some data
                    pdDoc  = (CAcroPDDoc)avDoc.GetPDDoc();
                    SaveAs = pdDoc.Save(1, sFullPath);
                }
                else
                {
                    SaveAs = false;
                }
            }
            catch
            {
                SaveAs = false;
            }

            //Returning output var
            return(SaveAs);
        }
コード例 #2
0
        // test
        public Boolean OCRDocumentAndSave(String szPdfPathConst)
        {
            CAcroAVDoc avDoc;
            CAcroApp   avApp;

            avApp = new AcroAppClass();
            avDoc = new AcroAVDocClass();
            avApp.Show();

            //open the PDF
            if (avDoc.Open(szPdfPathConst, ""))
            {
                //set the pdDoc object and get some data
                CAcroPDDoc pdDoc = (CAcroPDDoc)avDoc.GetPDDoc();
                try
                {
                    avApp.MenuItemExecute("TouchUp:EditDocument");
                    //System.Threading.Thread.Sleep(1000);
                    avApp.MenuItemExecute("Save");
                }catch (Exception e)
                {
                    return(false);
                }
                avApp.CloseAllDocs();
                avApp.Exit();

                return(true);
            }
            avApp.Exit();
            return(false);
        }
コード例 #3
0
ファイル: FillFormCS.cs プロジェクト: dannisliang/VS
        static void Main(string[] args)
        {
            String FORM_NAME = Application.StartupPath + "\\..\\..\\..\\..\\..\\TestFiles\\SampleForm.pdf";
            // Initialize Acrobat by cretaing App object.
            CAcroApp acroApp = new AcroAppClass();

            // Show Acrobat Viewer
            acroApp.Show();

            // Create an AVDoc object
            CAcroAVDoc avDoc = new AcroAVDocClass();

            // Open the pdf
            if (!avDoc.Open(FORM_NAME, ""))
            {
                string szMsg = "Cannot open" + FORM_NAME + ".\n";
                Console.WriteLine(szMsg);
                return;
            }

            // Create a IAFormApp object, so that we can access the form fields in
            // the open document
            IAFormApp formApp = new AFormAppClass();

            // Get the IFields object associated with the form
            IFields myFields = (IFields)formApp.Fields;

            // Get the IEnumerator object for myFields
            IEnumerator myEnumerator = myFields.GetEnumerator();

            bool bFound = false;

            // Fill the "Name" field with value "John Doe"
            while (myEnumerator.MoveNext())
            {
                // Get the IField object
                IField myField = (IField)myEnumerator.Current;

                // If the field is "Name", set it's value to "John Doe"
                if (myField.Name == "Name")
                {
                    bFound        = true;
                    myField.Value = "John Doe";
                    break;
                }
            }

            if (bFound)
            {
                Console.WriteLine("Sucessfully changed the \"Name\" field value to \"John Doe\".");
            }
            else
            {
                Console.WriteLine("Failed to locate the \"Name\" field in the form.");
            }
        }
コード例 #4
0
ファイル: BasicIacCS.cs プロジェクト: dannisliang/VS
        private void StartAcrobatIac()
        {
            //IAC objects
            CAcroPDDoc pdDoc;
            CAcroAVDoc avDoc;

            //constant, hard coding for a pdf to open, it can be changed when needed.
            String szPdfPathConst = Application.StartupPath + "\\..\\..\\..\\..\\..\\TestFiles\\TwoColumnTaggedDoc.pdf";

            //variables
            string szStr;
            string szName;
            int    iNum = 0;

            //Initialize Acrobat by creating App object
            mApp = new AcroAppClass();

            //Show Acrobat
            mApp.Show();

            //set AVDoc object
            avDoc = new AcroAVDocClass();

            //open the PDF
            if (avDoc.Open(szPdfPathConst, ""))
            {
                //set the pdDoc object and get some data
                pdDoc  = (CAcroPDDoc)avDoc.GetPDDoc();
                iNum   = pdDoc.GetNumPages();
                szName = pdDoc.GetFileName();

                //compose a message
                szStr = szName + " has been loaded in Acrobat by the IAC application.\n\n";

                if (iNum > 1)
                {
                    szStr += "The PDF document has " + iNum + " pages.\n";
                }
                else
                {
                    szStr += "The PDF document has " + iNum + " page.\n";
                }

                label2.Text = szStr;
            }
            else
            {
                label2.Text = "Cannot open " + szPdfPathConst + "\n";
            }
        }
コード例 #5
0
        private AcroPDDoc getPDDoc(String szPdfPathConst)
        {
            //Declaring relevant IAC objects
            AcroPDDoc  pdDoc;
            CAcroAVDoc avDoc;
            CAcroApp   avApp;

            avApp = new AcroAppClass();
            avDoc = new AcroAVDocClass();
            if (avDoc.Open(szPdfPathConst, ""))
            {
                pdDoc = (AcroPDDoc)avDoc.GetPDDoc();
                return(pdDoc);
            }
            return(null);
        }
コード例 #6
0
        // Function to Check if Word is present or not, returns true or false
        public bool IsWordPresent(string szPdfPathConst, string searchword)
        {
            //variables
            bool TextCheck;

            try
            {
                //IAC objects
                CAcroPDDoc pdDoc;
                CAcroAVDoc avDoc;
                CAcroApp   avApp;

                //set AVApp Project
                avApp = new AcroAppClass();

                //set AVDoc object
                avDoc = new AcroAVDocClass();

                //Show Acrobat
                avApp.Show();

                //open the PDF if it isn't already open

                if (avDoc.Open(szPdfPathConst, ""))
                {
                    //set the pdDoc object and get some data
                    pdDoc = (CAcroPDDoc)avDoc.GetPDDoc();
                    //Checking if word is present or not
                    TextCheck = avDoc.FindText(searchword, 0, 0, 0);
                }
                else
                {
                    TextCheck = false;
                }
            }

            catch (Exception)
            {
                TextCheck = false;
            }
            return(TextCheck);
        }
コード例 #7
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>

        //Function to open the PDF and get the number of pages
        public int StartAcrobatIac(String szPdfPathConst)
        {
            //variables
            int iNum = 0;

            try
            {
                //IAC objects
                CAcroPDDoc pdDoc;
                CAcroAVDoc avDoc;
                CAcroApp   avApp;


                //set AVApp Project
                avApp = new AcroAppClass();

                //set AVDoc object
                avDoc = new AcroAVDocClass();

                //open the PDF
                if (avDoc.Open(szPdfPathConst, ""))
                {
                    //set the pdDoc object and get some data
                    pdDoc = (CAcroPDDoc)avDoc.GetPDDoc();
                    iNum  = pdDoc.GetNumPages();
                }
                else
                {
                    iNum = 0;
                }
            }
            catch (Exception e)
            {
                iNum = 0;
                Console.Write("Error, Could not open File: " + szPdfPathConst);
                Console.Write("\nMessage: " + e.Message);
            }
            return(iNum);
        }
コード例 #8
0
ファイル: 2.cs プロジェクト: shinysol/rennypark
        public bool PrintPDF(string FilePath)
        {
            bool       result = false;
            CAcroApp   mApp;
            CAcroPDDoc pdDoc;
            CAcroAVDoc avDoc;

            //string szStr;
            //string szName;
            //int iNum = 0;

            //Initialize Acrobat by creating App object
            //Embed Interop T->F
            mApp = new AcroAppClass();

            //Show Acrobat
            //mApp.Show();

            //set AVDoc object
            avDoc = new AcroAVDocClass();
            //open the PDF
            if (avDoc.Open(FilePath, ""))
            {
                //set the pdDoc object and get some data
                pdDoc = (CAcroPDDoc)avDoc.GetPDDoc();
                //compose a message
                if (avDoc.PrintPages(0, pdDoc.GetNumPages() - 1, 0, 0, 0))
                {
                    result = true;
                }
                pdDoc.Close();
                mApp.CloseAllDocs();
                mApp.Exit();
            }
            return(result);
        }
コード例 #9
0
        // Closing PDF File
        public bool ClosePDFNoChanges(string szPdfPathConst)
        {
            //Initializing Variables
            bool CloseCheck;

            try
            {
                //SettingObject
                CAcroApp   avApp;
                CAcroAVDoc avDoc;

                //set AVApp Project
                avApp = new AcroAppClass();
                //set AVDoc object
                avDoc = new AcroAVDocClass();

                if (avDoc.Open(szPdfPathConst, ""))
                {
                    //Checking if word is present or not
                    CloseCheck = avDoc.Close(1);
                }
                else
                {
                    CloseCheck = false;
                }

                avApp.CloseAllDocs();
                avApp.Exit();
            }
            catch
            {
                CloseCheck = false;
            }

            return(CloseCheck);
        }
コード例 #10
0
        public string GetFetchLatestReport(FetchLatestReport Data)
        {
            try
            {
                // int Reporttype = 8; pageText = "6010001"; string shortpath = string.Empty; string Fromdate = string.Empty; string Todate = string.Empty; string[] datecheckarr;
                int   Reporttype = Data.ReportName; pageText = Data.CustomerAccount; string shortpath = string.Empty; string Fromdate = string.Empty; string Todate = string.Empty; string[] datecheckarr;
                Int64 schemeid = 0;
                List <SchemeMasterdata> dataList = new List <SchemeMasterdata>();
                switch (Reporttype)
                {
                case 1:
                    Reportname = "BANK BOOK Client" + ".pdf";
                    break;

                case 2:
                    Reportname = "Current Portfolio Clientwise" + ".pdf";
                    break;

                case 3:
                    Reportname = "Performance Appraisal Clientwise" + ".pdf";
                    break;

                case 4:
                    Reportname = "Portfolio Appraisal Clientwise" + ".pdf";
                    break;

                case 5:
                    Reportname = "Portfolio Fact Sheet" + ".pdf";
                    break;

                case 6:
                    Reportname = "Statement of Capital Gain clientwise" + ".pdf";
                    break;

                case 7:
                    Reportname = "Statement of Dividend Clientwise" + ".pdf";
                    break;

                case 8:
                    Reportname = "Statement of Expenses Clientwise" + ".pdf";
                    break;

                case 9:
                    Reportname = "Transaction Statement Cleintwise" + ".pdf";
                    break;
                }

                string SourceDirectorypath = ""; string[] files; string pdffilename = ""; string DestinationDirectorypath = "";
                SourceDirectorypath      = HttpContext.Current.Server.MapPath("//FAMSIN//");
                DestinationDirectorypath = HttpContext.Current.Server.MapPath("//FAMSOUT//");
                files = Directory.GetFiles(SourceDirectorypath, "*.pdf");
                if (files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        pdffilename = Path.GetFileName(file);
                        if (pdffilename == Reportname && pageText != "")
                        {
                            FORM_NAME = SourceDirectorypath + Reportname;
                            CAcroApp acroApp = new AcroAppClass();
                            acroApp.Show();
                            string datewisedata = string.Empty; string pagefromdate = ""; string pagelastindex = "";
                            string Pagescheme = string.Empty; string DatabasePagescheme = string.Empty;
                            Dictionary <Int64, string> Schemelist = new Dictionary <Int64, string>();
                            FAMSEntities context = new FAMSEntities();
                            try
                            {
                                var results = context.MultipleResults("[dbo].[BindSchememaster]").With <SchemeMasterdata>()
                                              .Execute("@Querytype", "@Cust_code", "BindScheme", pageText);

                                foreach (var schemedatab in results)
                                {
                                    dataList = schemedatab.Cast <SchemeMasterdata>().ToList();
                                    if (dataList.Count > 0)
                                    {
                                        for (int i = 0; i < dataList.Count; i++)
                                        {
                                            Schemelist.Add(Convert.ToInt32(dataList[i].SMDID), Convert.ToString(dataList[i].SchemaNumber.ToString()));
                                        }
                                    }
                                }

                                //   break;
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }

                            CAcroAVDoc avDoc = new AcroAVDocClass();
                            if (!avDoc.Open(FORM_NAME, ""))
                            {
                                //string szMsg = "Cannot open" + FORM_NAME + ".\n";
                                //Console.WriteLine(szMsg);
                                //return;
                            }
                            AcroPDDoc  doc = (AcroPDDoc)avDoc.GetPDDoc();
                            AcroPDPage page; Object newDoc = null; ArrayList kk = new ArrayList();
                            int        pages = doc.GetNumPages();
                            object     jso, jsNumWords, jsWord;
                            jso = doc.GetJSObject();
                            for (int i = 0; i < pages; i++)
                            {
                                page = (AcroPDPage)doc.AcquirePage(i);
                                List <string> words = new List <string>();
                                try
                                {
                                    if (jso != null)
                                    {
                                        object[] argsy = new object[] { i };
                                        jsNumWords = jso.GetType().InvokeMember("getPageNumWords",
                                                                                System.Reflection.BindingFlags.InvokeMethod, null, jso, argsy, null);
                                        int numWords = Int32.Parse(jsNumWords.ToString());
                                        for (int j = 0; j <= numWords; j++)
                                        {
                                            object[] argsj = new object[] { i, j, false };
                                            jsWord = jso.GetType().InvokeMember("getPageNthWord", System.Reflection.BindingFlags.InvokeMethod, null, jso, argsj, null);
                                            words.Add((string)jsWord);
                                        }
                                    }
                                    for (int x = 0; x < words.Count; x++)
                                    {
                                        int result = String.Compare(words[x].ToString().Trim(), pageText.Trim());
                                        if (result == 0)
                                        {
                                            newDoc         = null;
                                            pagelastindex += i + ",";
                                            if (Reporttype == 1 || Reporttype == 6 || Reporttype == 7 || Reporttype == 8 || Reporttype == 9)
                                            {
                                                if (string.IsNullOrEmpty(datewisedata))
                                                {
                                                    pagefromdate = "From";
                                                    for (int m = x; m < words.Count; m++)
                                                    {
                                                        int datecheck = String.Compare(words[m].ToString().Trim(), pagefromdate.Trim());
                                                        if (datecheck == 0)
                                                        {
                                                            for (int y = m + 1; y < m + 8; y++)
                                                            {
                                                                datewisedata += words[y].ToString();
                                                            }
                                                            datecheckarr = datewisedata.Replace("\n", "").Replace("\r", "").Trim().Split('T');
                                                            Fromdate     = datecheckarr[0].ToString().Trim();
                                                            Todate       = datecheckarr[1].ToString().Replace("o", "").Trim();
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            else if (Reporttype == 2)
                                            {
                                                if (string.IsNullOrEmpty(datewisedata))
                                                {
                                                    pagefromdate = "Report";
                                                    for (int m = x; m < words.Count; m++)
                                                    {
                                                        int datecheck = String.Compare(words[m].ToString().Trim(), pagefromdate.Trim());
                                                        if (datecheck == 0)
                                                        {
                                                            for (int y = m + 3; y < m + 6; y++)
                                                            {
                                                                datewisedata += words[y].ToString();
                                                            }
                                                            Fromdate = datewisedata.Replace("\n", "").Replace("\r", "").Trim();
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            else if (Reporttype == 3 || Reporttype == 4)
                                            {
                                                if (string.IsNullOrEmpty(datewisedata))
                                                {
                                                    pagefromdate = "As";
                                                    for (int m = x; m < words.Count; m++)
                                                    {
                                                        int datecheck = String.Compare(words[m].ToString().Trim(), pagefromdate.Trim());
                                                        if (datecheck == 0)
                                                        {
                                                            for (int y = m + 2; y < m + 5; y++)
                                                            {
                                                                datewisedata += words[y].ToString();
                                                            }
                                                            Fromdate = datewisedata.Replace("\n", "").Replace("\r", "").Trim();
                                                            break;
                                                        }
                                                    }
                                                }
                                            }

                                            else if (Reporttype == 5)
                                            {
                                                if (string.IsNullOrEmpty(datewisedata))
                                                {
                                                    pagefromdate = "As";
                                                    for (int m = 0; m < words.Count; m++)
                                                    {
                                                        int datecheck = String.Compare(words[m].ToString().Trim(), pagefromdate.Trim());
                                                        if (datecheck == 0)
                                                        {
                                                            for (int y = m + 2; y < m + 5; y++)
                                                            {
                                                                datewisedata += words[y].ToString();
                                                            }
                                                            Fromdate = datewisedata.Replace("\n", "").Replace("\r", "").Trim();
                                                            break;
                                                        }
                                                    }
                                                }
                                            }

                                            //DMSNEWEntities context = new DMSNEWEntities();
                                            //Dictionary<Int64, string> Partnerid = new Dictionary<Int64, string>();
                                            //Partnerid = context.DMS_Partner().AsEnumerable().Select(x => new { Partid = x.PartnerId, PartCode = x.PartnerCode }).Distinct().ToDictionary(o => o.Partid, o => o.PartCode);
                                            if (string.IsNullOrEmpty(Pagescheme))
                                            {
                                                for (int m = 0; m < words.Count; m++)
                                                {
                                                    if (Schemelist.Count > 0)
                                                    {
                                                        for (int count = 0; count < Schemelist.Count; count++)
                                                        {
                                                            var element = Schemelist.ElementAt(count);
                                                            var Key     = element.Key;
                                                            var Value   = element.Value;
                                                            DatabasePagescheme = Value;
                                                            string kk1         = words[m].ToString();
                                                            int    schemecheck = String.Compare(words[m].ToString().Replace("\n", "").Replace("\r", "").Trim(), DatabasePagescheme.Trim());
                                                            if (schemecheck == 0)
                                                            {
                                                                Pagescheme = words[m].ToString();
                                                                schemeid   = Key;
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    //  }
                                }
                                catch
                                {
                                }
                            }
                            try
                            {
                                if (pagelastindex != "")
                                {
                                    string[] data = pagelastindex.Split(',');
                                    kk.Add(data[0]);
                                    if (data.Length > 2)
                                    {
                                        kk.Add(data[data.Length - 2]);
                                    }
                                }
                                if (kk.Count > 0)
                                {
                                    if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Customerwisedata/" + Reporttype + "/" + pageText)))
                                    {
                                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Customerwisedata/" + Reporttype + "/" + pageText));
                                    }
                                    string filename   = string.Empty;
                                    string targetPath = string.Empty;
                                    filename = pageText + "_" + datewisedata.Replace("\n", "").Replace("\r", "").Trim().Replace(" ", "").Replace("/", "-") + ".pdf";
                                    object[] extractPagesParam = kk.ToArray();
                                    //kk.ToArray();

                                    newDoc = jso.GetType().InvokeMember(
                                        "extractPages",
                                        BindingFlags.InvokeMethod |
                                        BindingFlags.Public |
                                        BindingFlags.Instance,
                                        null, jso, extractPagesParam);

                                    targetPath = HttpContext.Current.Server.MapPath("~/Customerwisedata/" + Reporttype + "/" + pageText + "/" + @"\" + filename);
                                    shortpath  = "Customerwisedata/" + Reporttype + "/" + pageText + "/" + filename;
                                    object[] saveAsParam = { targetPath };
                                    newDoc.GetType().InvokeMember(
                                        "saveAs", System.Reflection.BindingFlags.InvokeMethod, null, newDoc, saveAsParam);


                                    if (pageText != "" && Reporttype != 0 && pageText != "0")
                                    {
                                        FAMSEntities dbcontext = new FAMSEntities();


                                        var results = dbcontext.MultipleResults("[dbo].[BindSchememaster]").With <Responsecls>()
                                                      .Execute("@Querytype", "@Fromdate", "@Todate", "@Cust_code", "@Schemeid", "@Shortpath", "@Reporttype", "@ReportName", "InsertAllReportHistoryData", Fromdate.Trim(), Todate.Trim(), pageText, Convert.ToString(schemeid), shortpath, Convert.ToString(Reporttype), Reportname);
                                    }
                                }
                            }
                            catch { }

                            avDoc.Close(0);
                            avDoc.ClearSelection();
                            acroApp.CloseAllDocs();
                            doc.Close();
                            acroApp.Hide();
                            acroApp.Exit();
                            //string pname = "Acrobat";
                            //string localMachineName = Environment.MachineName;
                            //var runningProcess = Process.GetProcesses(localMachineName);
                            //int c= runningProcess.Count();
                            //foreach (var process in runningProcess)
                            //{
                            //    if (process.ProcessName.Trim() == pname)
                            //    {
                            //        process.Kill();
                            //    }

                            //}
                            //string sourceFile = System.IO.Path.Combine(SourceDirectorypath, pdffilename);
                            //String Todaysdate = DateTime.Now.ToString("yyyy-MM-dd");
                            //if (!Directory.Exists(DestinationDirectorypath + Todaysdate))
                            //{
                            //    var DIR = Directory.CreateDirectory(DestinationDirectorypath + Todaysdate);

                            //}

                            //string destFile = System.IO.Path.Combine(DestinationDirectorypath + Todaysdate, pdffilename);
                            //System.IO.File.Copy(sourceFile, destFile, true);

                            //if (File.Exists(destFile))
                            //{

                            //     System.IO.File.Delete(sourceFile);
                            //}
                        }

                        /////////////Move file from source to destination
                    }
                }
            }
            catch (Exception ex) { }

            return("1");
        }
コード例 #11
0
        // Returns the list of page numbers on which the word or words can be found (separated by commas, ex: 7,8,9,10)
        // bCaseSensitive: 0 = false, 1 = true, bWholeWordsOnly: 0 = false, 1 = true
        public string GetPageNumforWord(string szPdfPathConst, string searchword, int bCaseSensitive, int bWholeWordsOnly)
        {
            //Initializing variables
            int           iNum = 0;
            bool          TextCheck;
            int           PageNum;
            bool          GoToStatus;
            string        PageNumConsol = "";
            int           ScanPage;
            List <int>    PageList       = new List <int>();
            List <string> PageListString = new List <string>();

            try
            {
                //Declaring relevant IAC objects
                CAcroPDDoc      pdDoc;
                CAcroAVDoc      avDoc;
                CAcroApp        avApp;
                CAcroAVPageView avPage;

                //set AVApp Project
                avApp = new AcroAppClass();

                //set AVDoc object
                avDoc = new AcroAVDocClass();

                //open the PDF if it isn't already open

                if (avDoc.Open(szPdfPathConst, ""))
                {
                    //set the pdDoc object and get some data
                    pdDoc = (CAcroPDDoc)avDoc.GetPDDoc();

                    //Getting Total Number of Pages in the PDF
                    iNum = pdDoc.GetNumPages();

                    //set AVPage View object
                    avPage = (CAcroAVPageView)avDoc.GetAVPageView();

                    //Navigating to Page 1 to initiate search
                    ScanPage   = 0;
                    GoToStatus = avPage.GoTo(ScanPage);

                    //Checking if word is present or not
                    TextCheck = avDoc.FindText(searchword, bCaseSensitive, bWholeWordsOnly, 0);

                    //Declaring variable for storing the previous page number
                    int PageNumPrev = 0;

                    if (TextCheck == true)
                    {
                        PageNum = avPage.GetPageNum();
                        //First Page is 0 and thus offset is being taken care of
                        PageNum = PageNum + 1;
                        PageList.Add(PageNum);

                        //Incrementing Page numbers and searching for more instances
                        while (TextCheck == true)
                        {
                            //Going to the page next to the previous search result - Not incremented by 1 since PageNum was already incremented for recording.
                            ScanPage = PageNum;
                            if (ScanPage == iNum)
                            {
                                TextCheck = false;
                                break;
                            }
                            GoToStatus = avPage.GoTo(ScanPage);
                            TextCheck  = avDoc.FindText(searchword, bCaseSensitive, bWholeWordsOnly, 0);
                            PageNum    = avPage.GetPageNum();

                            //Exit loop in case the previous page number is bigger than the current
                            if (PageNumPrev > PageNum)
                            {
                                break;
                            }
                            //Assigning the page number for this search iteration to a previous variable
                            PageNumPrev = PageNum;

                            //First Page is 0 and thus offset is being taken care of
                            PageNum = PageNum + 1;
                            PageList.Add(PageNum);
                        }
                    }
                    else
                    {
                        PageNum = 0;
                        PageList.Add(PageNum);
                    }
                }
                else
                {
                    PageNum = 0;
                    PageList.Add(PageNum);
                }

                //Removing Duplicates in the list due to multiple occurences of word on the same page
                List <int> PageListFilter = new List <int>();
                foreach (int i in PageList)
                {
                    if (!PageListFilter.Contains(i))
                    {
                        PageListFilter.Add(i);
                    }
                }

                //Converting Integer List for Page List to String List
                PageListString = PageListFilter.ConvertAll <string>(delegate(int i)
                {
                    return(i.ToString());
                });

                //Converting String List to Comma Delimited List
                PageNumConsol = string.Join(",", PageListString.ToArray());
            }
            catch (Exception)
            {
                PageNumConsol = "Unknown Exception";
            }

            return(PageNumConsol);
        }
コード例 #12
0
        public String getPageRangeBetweenStrings(String szPdfPathConst, String HeaderStr, String FooterStr, Boolean includeFirstPageInRange, Boolean includeLastPageInRange)
        {
            CAcroApp        avApp;
            CAcroAVDoc      avDoc;
            CAcroAVPageView avPage;

            avApp = new AcroAppClass();
            avDoc = new AcroAVDocClass();
            avDoc.Open(szPdfPathConst, "");
            CAcroPDDoc pdDoc          = (CAcroPDDoc)avDoc.GetPDDoc();
            List <int> PageListHeader = new List <int>();
            List <int> PageListFooter = new List <int>();
            //AcroPDDoc pdDoc = getPDDoc(szPdfPathConst);
            int        TotalNumberOfPages = pdDoc.GetNumPages();
            AcroPDPage page;

            //set AVPage View object
            avPage = (CAcroAVPageView)avDoc.GetAVPageView();
            avApp.Show();
            for (int i = 0; i < TotalNumberOfPages; i++)
            {
                page = (AcroPDPage)pdDoc.AcquirePage(i);
                Boolean TextCheck = avDoc.FindText(HeaderStr, 1, 1, 0);
                if (TextCheck == true)
                {
                    int PageNum = avPage.GetPageNum();
                    PageListHeader.Add(PageNum);
                }
            }


            List <int> PagesWithHeaderWords = DeDuplicateArray(PageListHeader);



            for (int i = 0; i < TotalNumberOfPages; i++)
            {
                page = (AcroPDPage)pdDoc.AcquirePage(i);
                Boolean TextCheck = avDoc.FindText(FooterStr, 1, 1, 0);
                if (TextCheck == true)
                {
                    int PageNum = avPage.GetPageNum();
                    PageListFooter.Add(PageNum);
                }
            }
            List <int> PagesWithFooterWords = DeDuplicateArray(PageListFooter);
            int        MinimumFooterRange   = 0;
            int        MinimumHeaderRange   = 0;

            if (PagesWithFooterWords.Count == 0 || PagesWithHeaderWords.Count == 0)
            {
                return("No Range Found");
            }

            MinimumFooterRange = PagesWithFooterWords.Min();
            MinimumHeaderRange = PagesWithFooterWords.Min();



            int HeaderFinalPageNumber = MinimumHeaderRange + 1;
            int FooterFinalPageNumber = MinimumFooterRange + 1;

            if (!includeFirstPageInRange)
            {
                HeaderFinalPageNumber++;
            }
            if (!includeLastPageInRange)
            {
                FooterFinalPageNumber--;
            }

            return(HeaderFinalPageNumber + "-" + FooterFinalPageNumber);
        }