Esempio n. 1
0
        public void CopyZAS()
        {
            conf Config = new conf();

            try
            {
                File.Copy(pdfName, Config.inPath + "\\!do_przetworzenia_recznego\\" + docName + ".pdf");
                StreamWriter ZAS;
                ZAS = File.AppendText(fileLog);
                ZAS.WriteLine(Config.inPath + "\\!do_przetworzenia_recznego\\" + docName + ".pdf");
                ZAS.Close();
            }
            catch (IOException)
            {
                FileInfo infoFirst  = new FileInfo(Config.inPath + "\\!do_przetworzenia_recznego\\" + docName + ".pdf");
                long     byteFirst  = infoFirst.Length;
                FileInfo infoSecond = new FileInfo(pdfName);
                long     byteSecond = infoSecond.Length;
                if (byteFirst != byteSecond)
                {
                    File.Copy(pdfName, Config.inPath + "\\!do_przetworzenia_recznego\\duplikaty\\" + docName + ".pdf");
                    StreamWriter ZAS2;
                    ZAS2 = File.AppendText(fileLog);
                    ZAS2.WriteLine("!! DUPLIKAT !!    " + Config.inPath + "\\!do_przetworzenia_recznego\\duplikaty\\" + docName + ".pdf" + "    !! DUPLIKAT !!");
                    ZAS2.Close();
                }
                else
                {
                    StreamWriter ZAS3;
                    ZAS3 = File.AppendText(fileLog);
                    ZAS3.WriteLine("!! Identyczny plik istnieje !!    " + Config.inPath + "\\!do_przetworzenia_recznego\\" + docName + ".pdf" + "    !! Identyczny plik istnieje !!");
                    ZAS3.Close();
                }
            }
        }
Esempio n. 2
0
        public void CopyWWdeliveryDoc()
        {
            conf Config = new conf();

            try
            {
                File.Copy(pdfName, Config.outPath + "Rok_20" + year + "\\WW\\" + docName + "_DD.pdf");
                StreamWriter WW;
                WW = File.AppendText(fileLog);
                WW.WriteLine(Config.outPath + "Rok_20" + year + "\\WW\\" + docName + "_DD.pdf");
                WW.Close();
            }
            catch (IOException)
            {
                FileInfo infoFirst  = new FileInfo(Config.outPath + "Rok_20" + year + "\\WW\\" + docName + "_DD.pdf");
                long     byteFirst  = infoFirst.Length;
                FileInfo infoSecond = new FileInfo(pdfName);
                long     byteSecond = infoSecond.Length;
                if (byteFirst != byteSecond)
                {
                    File.Copy(pdfName, Config.outPath + "Rok_20" + year + "\\duplikaty\\" + docName + "_DD.pdf");
                    StreamWriter WW2;
                    WW2 = File.AppendText(fileLog);
                    WW2.WriteLine("!! DUPLIKAT !!    " + Config.outPath + "Rok_20" + year + "\\do_polaczenia\\" + docName + "_DD.pdf" + "    !! DUPLIKAT !!");
                    WW2.Close();
                }
                else
                {
                    StreamWriter WW3;
                    WW3 = File.AppendText(fileLog);
                    WW3.WriteLine("!! Identyczny plik istnieje !!    " + Config.outPath + "Rok_20" + year + "\\" + docName + "_DD.pdf" + "    !! Identyczny plik istnieje !!");
                    WW3.Close();
                }
            }
        }
Esempio n. 3
0
        public void CopyWZ()
        {
            conf Config = new conf();

            try
            {
                File.Copy(pdfName, Config.outPath + "Rok_20" + year + "\\" + docName + ".pdf");
                StreamWriter WZ;
                WZ = File.AppendText(fileLog);
                WZ.WriteLine(Config.outPath + "Rok_20" + year + "\\" + docName + ".pdf");
                WZ.Close();
            }
            catch (IOException)
            {
                FileInfo infoFirst  = new FileInfo(Config.outPath + "Rok_20" + year + "\\" + docName + ".pdf");
                long     byteFirst  = infoFirst.Length;
                FileInfo infoSecond = new FileInfo(pdfName);
                long     byteSecond = infoSecond.Length;
                if (byteFirst != byteSecond)
                {
                    File.Copy(pdfName, Config.outPath + "Rok_20" + year + "\\duplikaty\\" + docName + ".pdf");
                    StreamWriter WZ2;
                    WZ2 = File.AppendText(fileLog);
                    WZ2.WriteLine("!! DUPLIKAT !!    " + Config.outPath + "Rok_20" + year + "\\duplikaty\\" + docName + ".pdf" + "    !! DUPLIKAT !!");
                    WZ2.Close();
                }
                else
                {
                    StreamWriter WZ3;
                    WZ3 = File.AppendText(fileLog);
                    WZ3.WriteLine("!! Identyczny plik istnieje !!    " + Config.outPath + "Rok_20" + year + "\\" + docName + ".pdf" + "    !! Identyczny plik istnieje !!");
                    WZ3.Close();
                }
            }
        }
Esempio n. 4
0
        public void CopyOther()
        {
            conf Config = new conf();

            File.Copy(pdfName, Config.inPath + "\\!do_przetworzenia_recznego\\" + docName);
            StreamWriter RW;

            RW = File.AppendText(fileLog);
            RW.WriteLine(Config.inPath + "\\!do_przetworzenia_recznego\\" + docName);
            RW.Close();
        }
Esempio n. 5
0
        public Tiff(string scanName, string fileLogName)
        {
            conf Config = new conf();

            if ((File.Exists(Config.inPath + "\\!ocr\\oryginal_files\\tiff\\" + scanName)) == true)
            {
                DateTime thisTime    = DateTime.Now;
                string   filesSurfix = thisTime.ToString().Replace(" ", "_").Replace("-", "").Replace(":", "");
                string   fileDuble   = scanName.Replace(".tiff", "") + "_" + filesSurfix + ".tiff";
                string   fileName    = fileDuble.Replace(".tiff", "");
                fileNamePDF = Config.inPath + "\\!ocr\\po_ocr\\" + fileName + ".pdf";

                File.Move(Config.inPath + "\\" + scanName, Config.inPath + "\\!ocr\\oryginal_files\\tiff\\" + fileDuble);

                ProcessStartInfo tesseract = new ProcessStartInfo();
                tesseract.WorkingDirectory = ".\\tesseract";
                tesseract.WindowStyle      = ProcessWindowStyle.Hidden;
                tesseract.UseShellExecute  = false;
                tesseract.FileName         = "cmd.exe";
                tesseract.Arguments        =
                    "/c tesseract.exe " +
                    "\"" + Config.inPath + "\\!ocr\\oryginal_files\\tiff\\" + fileName + ".tiff" + "\"" + " " +
                    "\"" + Config.inPath + "\\!ocr\\po_ocr\\" + fileName + "\"" +
                    " -l " + "pol " + "pdf";
                // Start tesseract.
                Process process = Process.Start(tesseract);
                process.WaitForExit();
            }
            else
            {
                File.Move(Config.inPath + "\\" + scanName, Config.inPath + "\\!ocr\\oryginal_files\\tiff\\" + scanName);
                string fileName = scanName.Replace(".tiff", "");
                fileNamePDF = Config.inPath + "\\!ocr\\po_ocr\\" + fileName + ".pdf";

                ProcessStartInfo tesseract = new ProcessStartInfo();
                tesseract.WorkingDirectory = ".\\tesseract";
                tesseract.WindowStyle      = ProcessWindowStyle.Hidden;
                tesseract.UseShellExecute  = false;
                tesseract.FileName         = "cmd.exe";
                tesseract.Arguments        =
                    "/c tesseract.exe " +
                    "\"" + Config.inPath + "\\!ocr\\oryginal_files\\tiff\\" + fileName + ".tiff" + "\"" + " " +
                    "\"" + Config.inPath + "\\!ocr\\po_ocr\\" + fileName + "\"" +
                    " -l " + "pol " + "pdf";
                // Start tesseract.
                Process process = Process.Start(tesseract);
                process.WaitForExit();
            }
            StreamWriter SW;

            SW = File.AppendText(fileLogName);
            SW.WriteLine("Przetworzenie do przeszukiwalnego pliku PDF ...   OK");
            SW.Close();
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Program do automatycznego przetwarzania zeskanowanych dokumentów wykonany przez Marcin Pawlak tel. 797-155-154");
            ExistPath CheckIn = new ExistPath();
            //ReadTxt reading = new ReadTxt("C:\\ARCHIWUM_WZ\\!skany\\!ocr\\po_ocr\\WZ_18_03676.txt", "C:\\ARCHIWUM_WZ\\!skany\\!ocr\\logi\\files_20180516_115210.txt");
            conf     Config      = new conf();
            DateTime thisTime    = DateTime.Now;
            string   filesSurfix = thisTime.ToString().Replace(" ", "_").Replace("-", "").Replace(":", "");
            string   fileLogName;

            try
            {
                string[] extensions = new[] { ".jpg", ".png", ".tif", ".tiff", ".pdf", ".gif", ".bmp" }; //tworzę listę plików do przetworzenia
                string[] files      = Directory.GetFiles(Config.inPath, "*.*")
                                      .Select(Path.GetFileName)
                                      .Where(f => extensions.Contains(new FileInfo(f).Extension.ToLower())).ToArray();
                fileLogName = Config.inPath + "\\!ocr\\logi\\files_" + filesSurfix + ".txt"; //Nazwa pliku txt z zawartością skanów (files_RRRRMMDD_HHMMSS.txt)
                string pathLogName = fileLogName.Replace(".txt", "");
                Directory.CreateDirectory(pathLogName);
                foreach (string file in files)
                {
                    File.WriteAllLines(fileLogName, files);
                }
                int lines = File.ReadAllLines(fileLogName).Length;
                Console.WriteLine("Wyeksportowano listę z " + lines.ToString() + " plikami do " + Config.inPath + fileLogName);
                string[] linesFileLog = File.ReadAllLines(fileLogName);
                foreach (string fileName in linesFileLog)
                {
                    string fileLogNameDone = pathLogName + "\\" + fileName + ".txt";// !!sprawdzić działanie!!
                    var    t = new Task(() => { Scan Scan = new Scan(fileName, fileLogNameDone); });
                    t.Start();
                }
            }
            catch (Exception)
            {
                File.WriteAllText(Config.inPath + "\\!ocr\\logi\\error_" + filesSurfix + ".txt", "Brak plików do przetworzenia!"); //zapisuje log z informacją, że nie było plików do przetworzenia
            }

            foreach (var file in Directory.GetFiles(Path.GetTempPath(), "*.*"))
            {
                try
                {
                    File.Delete(file);
                }
                catch
                {
                }
            }

            Console.ReadKey();
            // pętla sprawdza folder tmp jeżeli są jakieś pliki to sprawdza czy istnie plik pdf w lokalizacji po_pdf, jeżeli istnieje to usuń.
            //dopisać warunek jeżeli w \po_ocr\ są pliki 0kb przenies oryginały do skany
        }
Esempio n. 7
0
        public ExistPath()
        {
            conf Config = new conf();

            string[] path;
            path     = new string[35];
            path[0]  = Config.inPath;
            path[1]  = Config.inPath + "\\!do_przetworzenia_recznego";
            path[2]  = Config.inPath + "\\!do_przetworzenia_recznego\\duplikaty";
            path[3]  = Config.inPath + "\\!ocr";
            path[4]  = Config.inPath + "\\!ocr\\logi";
            path[5]  = Config.inPath + "\\!ocr\\oryginal_files";
            path[6]  = Config.inPath + "\\!ocr\\oryginal_files\\bmp";
            path[7]  = Config.inPath + "\\!ocr\\oryginal_files\\gif";
            path[8]  = Config.inPath + "\\!ocr\\oryginal_files\\jpg";
            path[9]  = Config.inPath + "\\!ocr\\oryginal_files\\pdf";
            path[10] = Config.inPath + "\\!ocr\\oryginal_files\\png";
            path[11] = Config.inPath + "\\!ocr\\oryginal_files\\tif";
            path[12] = Config.inPath + "\\!ocr\\oryginal_files\\tiff";
            path[13] = Config.inPath + "\\!ocr\\po_ocr";
            path[14] = Config.inPath + "\\!ocr\\po_ocr\\przetworzone";
            path[15] = Config.inPath + "\\!ocr\\tmp";
            path[16] = Config.outPath;
            DateTime date = DateTime.Today;
            int      year = date.Year;

            path[17] = Config.outPath + "\\Rok_" + (year - 1).ToString();
            path[18] = Config.outPath + "\\Rok_" + (year - 1).ToString() + "\\duplikaty";
            path[19] = Config.outPath + "\\Rok_" + (year - 1).ToString() + "\\WW";
            path[20] = Config.outPath + "\\Rok_" + (year - 1).ToString() + "\\FV";
            path[21] = Config.outPath + "\\Rok_" + (year - 1).ToString() + "\\RW";
            path[22] = Config.outPath + "\\Rok_" + (year - 1).ToString() + "\\do_polaczenia";
            path[23] = Config.outPath + "\\Rok_" + year.ToString();
            path[24] = Config.outPath + "\\Rok_" + year.ToString() + "\\duplikaty";
            path[25] = Config.outPath + "\\Rok_" + year.ToString() + "\\WW";
            path[26] = Config.outPath + "\\Rok_" + year.ToString() + "\\FV";
            path[27] = Config.outPath + "\\Rok_" + year.ToString() + "\\RW";
            path[28] = Config.outPath + "\\Rok_" + year.ToString() + "\\do_polaczenia";
            path[29] = Config.outPath + "\\Rok_" + (year + 1).ToString();
            path[30] = Config.outPath + "\\Rok_" + (year + 1).ToString() + "\\duplikaty";
            path[31] = Config.outPath + "\\Rok_" + (year + 1).ToString() + "\\WW";
            path[32] = Config.outPath + "\\Rok_" + (year + 1).ToString() + "\\FV";
            path[33] = Config.outPath + "\\Rok_" + (year + 1).ToString() + "\\RW";
            path[34] = Config.outPath + "\\Rok_" + (year + 1).ToString() + "\\do_polaczenia";

            foreach (string pathElement in path)
            {
                if (Directory.Exists(pathElement))
                {
                    Console.Write("Istnienie folderu " + pathElement + "\t");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("OK");
                    Console.ResetColor();
                    Console.WriteLine();
                }
                else
                {
                    DirectoryInfo inPath = Directory.CreateDirectory(pathElement);
                    Console.WriteLine("Utworzono folder: " + pathElement);
                }
            }
        }
Esempio n. 8
0
        public Pdf(string scanName, string fileLogName)
        {
            conf   Config = new conf();
            string fileName;

            if ((File.Exists(Config.inPath + "\\!ocr\\oryginal_files\\pdf\\" + scanName)) == true)
            {
                DateTime thisTime    = DateTime.Now;
                string   filesSurfix = thisTime.ToString().Replace(" ", "_").Replace("-", "").Replace(":", "");
                string   fileDuble   = scanName.Replace(".pdf", "") + "_" + filesSurfix + ".pdf";

                File.Move(Config.inPath + "\\" + scanName, Config.inPath + "\\!ocr\\oryginal_files\\pdf\\" + fileDuble);

                MagickReadSettings settings = new MagickReadSettings();
                settings.Density     = new Density(300, 300);
                settings.Compression = Compression.Fax;
                using (MagickImageCollection filePDF = new MagickImageCollection())
                {
                    filePDF.Read(Config.inPath + "\\!ocr\\oryginal_files\\pdf\\" + fileDuble, settings);
                    fileName    = fileDuble.Replace(".pdf", "");
                    fileNamePDF = Config.inPath + "\\!ocr\\po_ocr\\" + fileName + ".pdf";
                    filePDF.Write(Config.inPath + "\\!ocr\\tmp\\" + fileName + ".tif");
                }
                ProcessStartInfo tesseract = new ProcessStartInfo();
                tesseract.WorkingDirectory = ".\\tesseract";
                tesseract.WindowStyle      = ProcessWindowStyle.Hidden;
                tesseract.UseShellExecute  = false;
                tesseract.FileName         = "cmd.exe";
                tesseract.Arguments        =
                    "/c tesseract.exe " +
                    "\"" + Config.inPath + "\\!ocr\\tmp\\" + fileName + ".tif" + "\"" + " " +
                    "\"" + Config.inPath + "\\!ocr\\po_ocr\\" + fileName + "\"" +
                    " -l " + "pol " + "pdf";
                // Start tesseract.
                Process process = Process.Start(tesseract);
                process.WaitForExit();
                if (System.IO.File.Exists(Config.inPath + "\\!ocr\\tmp\\" + fileName + ".tif"))
                {
                    try
                    {
                        System.IO.File.Delete(Config.inPath + "\\!ocr\\tmp\\" + fileName + ".tif");
                    }
                    catch (System.IO.IOException)
                    {
                        return;
                    }
                }
            }
            else
            {
                File.Move(Config.inPath + "\\" + scanName, Config.inPath + "\\!ocr\\oryginal_files\\pdf\\" + scanName);

                MagickReadSettings settings = new MagickReadSettings();
                settings.Density     = new Density(300, 300);
                settings.Compression = Compression.Fax;

                using (MagickImageCollection filePDF = new MagickImageCollection())
                {
                    filePDF.Read(Config.inPath + "\\!ocr\\oryginal_files\\pdf\\" + scanName, settings);
                    fileName    = scanName.Replace(".pdf", "");
                    fileNamePDF = Config.inPath + "\\!ocr\\po_ocr\\" + fileName + ".pdf";
                    filePDF.Write(Config.inPath + "\\!ocr\\tmp\\" + fileName + ".tif");
                }

                ProcessStartInfo tesseract = new ProcessStartInfo();
                tesseract.WorkingDirectory = ".\\tesseract";
                tesseract.WindowStyle      = ProcessWindowStyle.Hidden;
                tesseract.UseShellExecute  = false;
                tesseract.FileName         = "cmd.exe";
                tesseract.Arguments        =
                    "/c tesseract.exe " +
                    "\"" + Config.inPath + "\\!ocr\\tmp\\" + fileName + ".tif" + "\"" + " " +
                    "\"" + Config.inPath + "\\!ocr\\po_ocr\\" + fileName + "\"" +
                    " -l " + "pol " + "pdf";
                // Start tesseract.
                Process process = Process.Start(tesseract);
                process.WaitForExit();
                if (System.IO.File.Exists(Config.inPath + "\\!ocr\\tmp\\" + fileName + ".tif"))
                {
                    try
                    {
                        System.IO.File.Delete(Config.inPath + "\\!ocr\\tmp\\" + fileName + ".tif");
                    }
                    catch (System.IO.IOException)
                    {
                        return;
                    }
                }
            }
            StreamWriter SW;

            SW = File.AppendText(fileLogName);
            SW.WriteLine("Przetworzenie do przeszukiwalnego pliku PDF ...   OK");
            SW.Close();
        }