public String findText(String doc, String page, String searchterm, int numPages = -1)
        {
            try
            {
                String output = "";
                String swfFilePath = configManager.getConfig("path.swf") + doc + page + ".swf";
                String command = configManager.getConfig("cmd.searching.extracttext"); ;
                int pagecount = -1;

                if(numPages == -1){
                    pagecount = Directory.GetFiles(configManager.getConfig("path.swf"), doc+"*").Count();
                }else{
                    pagecount = numPages;
                }

                if(!Common.validSwfParams(swfFilePath,doc,page))
                    return "[Invalid Parameters]";

                command = command.Replace("{path.swf}",configManager.getConfig("path.swf"));
                command = command.Replace("{swffile}", doc + page + ".swf");

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = command.Substring(0, command.IndexOf(".exe") + 5);
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.Arguments = command.Substring(command.IndexOf(".exe") + 5);

                if (proc.Start())
                {
                    output = proc.StandardOutput.ReadToEnd();
                    int strpos = output.ToLower().IndexOf(searchterm.ToLower());
                    if(strpos > 0){
                        return "[{\"page\":" + page + ", \"position\":" + strpos + "}]";
                    }else{
                        int npage = Convert.ToInt32(page);

                        if(npage < pagecount){
                            return this.findText(doc,(npage+1).ToString(),searchterm,pagecount);
                        }else{
                            return "[{\"page\":-1, \"position\":-1}]";
                        }
                    }
                }
                else
                    return "[Error Extracting]";
            }
            catch (Exception ex)
            {
                return "[Error Extracting]";
            }
        }
Ejemplo n.º 2
0
        public String convert(string pdfdoc, string jsondoc, string page)
        {
            try
            {
                String output  = "";
                String command = "";

                if (configManager.getConfig("splitmode") == "true")
                {
                    command = configManager.getConfig("cmd.conversion.splitjsonfile");
                }
                else
                {
                    command = configManager.getConfig("cmd.conversion.jsonfile");
                }

                command = command.Replace("{path.pdf}", configManager.getConfig("path.pdf"));
                command = command.Replace("{path.swf}", configManager.getConfig("path.swf"));
                command = command.Replace("{pdffile}", pdfdoc);
                command = command.Replace("{jsonfile}", jsondoc);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName        = command.Substring(0, command.IndexOf(".exe") + 5);
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow  = true;
                //proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.Arguments = command.Substring(command.IndexOf(".exe") + 5);

                if (proc.Start())
                {
                    proc.WaitForExit();
                    proc.Close();
                    return("[OK]");
                }
                else
                {
                    return("[Error converting PDF to JSON, please check your directory permissions and configuration]");
                }
            }
            catch (Exception ex)
            {
                return("[" + ex.Message + "]");
            }
        }
Ejemplo n.º 3
0
        public String getSize(string doc, string page, string mode)
        {
            try
            {
                String swfdoc = doc + ".swf";

                if (configManager.getConfig("splitmode") == "true")
                {
                    swfdoc = doc + page + ".swf";
                }

                String output  = "";
                String command = configManager.getConfig("cmd.query.swfwidth");

                if (mode == "height")
                {
                    command = configManager.getConfig("cmd.query.swfheight");
                }

                command = command.Replace("{path.swf}", configManager.getConfig("path.swf"));
                command = command.Replace("{swffile}", swfdoc);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName               = command.Substring(0, command.IndexOf(".exe") + 5);
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.Arguments              = command.Substring(command.IndexOf(".exe") + 5);

                if (proc.Start())
                {
                    output = proc.StandardOutput.ReadToEnd();
                    return(GetNumbers(output));
                }
                else
                {
                    return("[Error converting PDF to PNG, please check your configuration]");
                }
            }
            catch (Exception ex)
            {
                return("[" + ex.Message + "]");
            }
        }
Ejemplo n.º 4
0
        public String extractText(String doc, String page)
        {
            try
            {
                String output      = "";
                String swfFilePath = configManager.getConfig("path.swf") + doc + page + ".swf";
                String command     = configManager.getConfig("cmd.searching.extracttext");;

                if (!Common.validSwfParams(swfFilePath, doc, page))
                {
                    return("[Invalid Parameters]");
                }

                command = command.Replace("{path.swf}", configManager.getConfig("path.swf"));
                command = command.Replace("{swffile}", doc + page + ".swf");

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName               = command.Substring(0, command.IndexOf(".exe") + 5);
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.Arguments              = command.Substring(command.IndexOf(".exe") + 5);

                if (proc.Start())
                {
                    output = proc.StandardOutput.ReadToEnd();
                    return(output);
                }
                else
                {
                    return("[Error Extracting]");
                }
            }
            catch (Exception ex)
            {
                return("[Error Extracting]");
            }
        }
Ejemplo n.º 5
0
        public String renderPage(string pdfdoc, string swfdoc, string page)
        {
            try
            {
                String output  = "";
                String command = configManager.getConfig("cmd.conversion.mudraw");

                command = command.Replace("{path.pdf}", configManager.getConfig("path.pdf"));
                command = command.Replace("{path.swf}", configManager.getConfig("path.swf"));
                command = command.Replace("{swffile}", swfdoc);
                command = command.Replace("{pdffile}", pdfdoc);
                command = command.Replace("{page}", page);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName               = command.Substring(0, command.IndexOf(".exe") + 5);
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.Arguments              = command.Substring(command.IndexOf(".exe") + 5);

                if (proc.Start())
                {
                    output = proc.StandardOutput.ReadToEnd();
                    return(output);
                }
                else
                {
                    return("[Error converting PDF to PNG, please check your configuration]");
                }

                return(command);
            }
            catch (Exception ex)
            {
                return("[" + ex.Message + "]");
            }
        }
Ejemplo n.º 6
0
        public String convert(string doc, String page)
        {
            try
            {
                String output      = "";
                String pdfFilePath = configManager.getConfig("path.pdf") + doc;
                String swfFilePath = configManager.getConfig("path.swf") + doc + page + ".swf";
                String command     = "";

                if (page != null && page.Length > 0)
                {
                    command = configManager.getConfig("cmd.conversion.splitpages");
                }
                else
                {
                    command = configManager.getConfig("cmd.conversion.singledoc");
                }

                command = command.Replace("{path.pdf}", this.configManager.getConfig("path.pdf"));
                command = command.Replace("{path.swf}", this.configManager.getConfig("path.swf"));
                command = command.Replace("{pdffile}", doc);

                try
                {
                    if (!this.isNotConverted(pdfFilePath, swfFilePath))
                    {
                        return("[Converted]");
                    }
                }
                catch (Exception ex)
                {
                    return("[" + ex.Message + "]");
                }

                int    return_var  = 0;
                String pagecommand = "";

                if (page != null && page.Length > 0)
                {
                    pagecommand  = command.Replace("%", page);
                    pagecommand += " -p " + page;
                }

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = command.Substring(0, command.IndexOf(".exe") + 5);
                command = command.Substring(command.IndexOf(".exe") + 5);

                if (page != null && page.Length > 0)
                {
                    proc.StartInfo.Arguments = pagecommand.Substring(pagecommand.IndexOf(".exe") + 5);
                }
                else
                {
                    proc.StartInfo.Arguments = command;
                }

                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.RedirectStandardOutput = true;

                if (proc.Start())
                {
                    output = proc.StandardOutput.ReadToEnd();
                    proc.WaitForExit();
                    proc.Close();
                    return_var = 0;

                    if (page != null && page.Length > 0)
                    {
                        System.Diagnostics.Process proc2 = new System.Diagnostics.Process();
                        proc2.StartInfo.FileName        = proc.StartInfo.FileName;
                        proc2.StartInfo.Arguments       = command;
                        proc2.StartInfo.UseShellExecute = true;
                        proc2.StartInfo.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                        proc2.StartInfo.CreateNoWindow  = true;
                        proc2.Start();
                    }
                }
                else
                {
                    return_var = -1;
                }

                if (return_var == 0)
                {
                    return("[Converted]");
                }
                else
                {
                    return("Error converting document, make sure the conversion tool is installed and that correct user permissions are applied to the SWF Path directory");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return("");
        }
Ejemplo n.º 7
0
        public String convert(string doc, String page, HttpApplicationState application)
        {
            try
            {
                String output      = "";
                String pdfFilePath = configManager.getConfig("path.pdf") + doc;
                String swfFilePath = configManager.getConfig("path.swf") + doc + page + ".swf";
                String command     = "";

                if (configManager.getConfig("splitmode") == "true")
                {
                    command = configManager.getConfig("cmd.conversion.splitpages");
                }
                else
                {
                    command = configManager.getConfig("cmd.conversion.singledoc");
                }

                command = command.Replace("{path.pdf}", this.configManager.getConfig("path.pdf"));
                command = command.Replace("{path.swf}", this.configManager.getConfig("path.swf"));
                command = command.Replace("{pdffile}", doc);

                try
                {
                    if (!this.isNotConverted(pdfFilePath, swfFilePath))
                    {
                        return("[Converted]");
                    }
                }
                catch (Exception ex)
                {
                    return("[" + ex.Message + "]");
                }

                int    return_var  = 0;
                String pagecommand = "";

                if (configManager.getConfig("splitmode") == "true")
                {
                    pagecommand  = command.Replace("%", page);
                    pagecommand += " -p " + page;
                }

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = command.Substring(0, command.IndexOf(".exe") + 5);
                command = command.Substring(command.IndexOf(".exe") + 5);

                if (configManager.getConfig("splitmode") == "true")
                {
                    proc.StartInfo.Arguments = pagecommand.Substring(pagecommand.IndexOf(".exe") + 5);
                }
                else
                {
                    proc.StartInfo.Arguments = command;
                }

                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.RedirectStandardOutput = true;

                if (proc.Start())
                {
                    output = proc.StandardOutput.ReadToEnd();
                    proc.WaitForExit();
                    proc.Close();
                    return_var = 0;

                    if (configManager.getConfig("splitmode") == "true")
                    {
                        if (application["runningExecutions"] == null)
                        {
                            application["runningExecutions"] = new Hashtable();
                        }

                        bool forkExecution = true;

                        if ((application["runningExecutions"] as Hashtable)[command] != null)
                        {
                            TimeSpan duration = DateTime.Now - (DateTime)(application["runningExecutions"] as Hashtable)[command];
                            forkExecution = duration.Minutes > 1;
                        }

                        if (forkExecution)
                        {
                            System.Diagnostics.Process proc2 = new System.Diagnostics.Process();
                            proc2.StartInfo.FileName        = proc.StartInfo.FileName;
                            proc2.StartInfo.Arguments       = command;
                            proc2.StartInfo.UseShellExecute = true;
                            proc2.StartInfo.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                            proc2.StartInfo.CreateNoWindow  = true;

                            // save the executing command to avoid multiple split mode executions
                            (application["runningExecutions"] as Hashtable)[command] = DateTime.Now;

                            proc2.Start();
                        }
                    }
                }
                else
                {
                    return_var = -1;
                }

                if (return_var == 0)
                {
                    return("[Converted]");
                }
                else
                {
                    return("[Error converting document, make sure the conversion tool is installed and that correct user permissions are applied to the SWF Path directory]");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return("");
        }