Exemple #1
0
        public OmrDetectionDialog(MainForm mainForm, DiskMasterForm masterForm, int selectedPageNumber)
        {
            if (selectedPageNumber == 0)
            {
                Messager.ShowWarning(this, new ArgumentOutOfRangeException("selectedPageNumber"));
                Close();
            }

            InitializeComponent();

            _mainForm           = mainForm;
            _masterForm         = masterForm;
            _selectedPageNumber = selectedPageNumber;
        }
Exemple #2
0
        public HttpResponseMessage DeletePage(FormDataCollection Form)
        {
            HttpResponseMessage httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, "Some problem in delete master form page.");

            if (Form != null)
            {
                string PageNumber = Form["PageNumber"]?.ToString().Trim() ?? "";
                string FolderName = Form["FolderName"]?.ToString().Trim() ?? "";
                string result     = DBHelper.GetFileFriendlyName(FolderName);

                string workingDirectory = HttpContext.Current.Server.MapPath("~/" + RootFolderName + "/" + result);
                if (Directory.Exists(workingDirectory))
                {
                    using (RasterCodecs _codecs = new RasterCodecs())
                    {
                        RasterDefaults.DitheringMethod = RasterDitheringMethod.None;
                        ServiceHelper.SetLicense();

                        workingRepository = new DiskMasterFormsRepository(_codecs, workingDirectory);
                        var masterForm = workingRepository?.RootCategory?.MasterForms?.FirstOrDefault();
                        if (masterForm != null)
                        {
                            DiskMasterForm            currentMasterForm = (DiskMasterForm)masterForm;
                            FormRecognitionAttributes attributes        = currentMasterForm.ReadAttributes();

                            int currentPageIdx = Convert.ToInt32(PageNumber);

                            FormPages   formPages = currentMasterForm.ReadFields();
                            RasterImage formImage = currentMasterForm.ReadForm();

                            //Delete page from master form attaributes
                            DeletePageFromMasterForm(currentPageIdx + 1, attributes); //page number here is 1 based
                                                                                      //Delete fields page
                            formPages.RemoveAt(currentPageIdx);
                            //Delete the page from the image
                            if (formImage.PageCount == 1)
                            {
                                formImage = null; //You cannot remove the only page from a rasterimage, an exception will occur
                            }
                            else
                            {
                                formImage.RemovePageAt(currentPageIdx + 1);
                            }

                            //We need to recreate the FormPages to ensure the page numbers are updated correctly
                            for (int i = 0; i < formPages.Count; i++)
                            {
                                FormPage currentPage = formPages[i];
                                FormPage newPage     = new FormPage(i + 1, currentPage.DpiX, currentPage.DpiY);
                                newPage.AddRange(currentPage.GetRange(0, currentPage.Count));
                                formPages[i] = newPage;
                            }
                            //Write the updated masterform to disk. Delete it first just in case the entire image was deleted
                            DiskMasterFormsCategory parentCategory = (workingRepository.RootCategory) as DiskMasterFormsCategory;
                            parentCategory.DeleteMasterForm(currentMasterForm);
                            parentCategory.AddMasterForm(attributes, formPages, formImage);
                            httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, "Page deleted from master set sucessfully.");
                            DBHelper.UpdateTifPageCount(formPages.Count.ToString(), FolderName);
                        }
                    }
                }
            }
            return(httpResponseMessage);
        }
Exemple #3
0
        private void AddMasterFormPages(RasterImage imagesToAdd, DiskMasterForm currentform, string folderName)
        {
            try
            {
                DiskMasterForm            currentMasterForm = currentform;
                FormRecognitionAttributes attributes        = currentMasterForm.ReadAttributes();
                FormPages   formPages = currentMasterForm.ReadFields();
                RasterImage formImage = currentMasterForm.ReadForm();

                for (int i = 0; i < imagesToAdd.PageCount; i++)
                {
                    //Add each new page to the masterform by creating attributes for each page
                    imagesToAdd.Page = i + 1;
                    AddPageToMasterForm(imagesToAdd.Clone(), attributes, -1, null);
                }

                //Add image
                if (formImage != null)
                {
                    formImage.AddPages(imagesToAdd.CloneAll(), 1, imagesToAdd.PageCount);
                }
                else
                {
                    formImage = imagesToAdd.CloneAll();
                }

                //Only add processing pages for the new pages
                if (formPages != null)
                {
                    for (int i = 0; i < imagesToAdd.PageCount; i++)
                    {
                        formPages.Add(new FormPage(formPages.Count + 1, imagesToAdd.XResolution, imagesToAdd.YResolution));
                    }
                }
                else
                {
                    //No processing pages exist so we must create them
                    FormRecognitionEngine recognitionEngine    = SetupRecognitionEngine();
                    FormProcessingEngine  tempProcessingEngine = new FormProcessingEngine();
                    tempProcessingEngine.OcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false);
                    //tempProcessingEngine.BarcodeEngine = barcodeEngine;

                    for (int i = 0; i < recognitionEngine.GetFormProperties(attributes).Pages; i++)
                    {
                        tempProcessingEngine.Pages.Add(new FormPage(i + 1, imagesToAdd.XResolution, imagesToAdd.YResolution));
                    }

                    formPages = tempProcessingEngine.Pages;
                }

                //FormField newField = null;
                //AnnHiliteObject newObject = new AnnHiliteObject();
                //newField = new TextFormField();
                //newField.Name = "test";
                //newField.Bounds = new LogicalRectangle(50, 50, 50, 50, LogicalUnit.Pixel);

                //FormField newField1 = null;
                //AnnHiliteObject newObject1 = new AnnHiliteObject();
                //newField1 = new OmrFormField();
                //newField1.Name = "test1";
                //newField1.Bounds = new LogicalRectangle(50, 50, 50, 50, LogicalUnit.Pixel);

                //newObject.Tag = newField;
                //newObject1.Tag = newField1;
                //FormField currentField = newObject.Tag as FormField;
                //FormField currentField1 = newObject1.Tag as FormField;

                //formPages[0].Add(currentField);
                //formPages[0].Add(currentField1);

                currentMasterForm.WriteForm(formImage);
                currentMasterForm.WriteAttributes(attributes);
                currentMasterForm.WriteFields(formPages);
                DBHelper.UpdateTifPageCount(formImage.PageCount.ToString(), folderName);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void UpdateData()
        {
            var recognitionEngineVersion = FormRecognitionEngine.Version;

#if FOR_DOTNET4
            var originalFullTextSearchManager = recognitionEngine.FullTextSearchManager;
#endif

            try
            {
                if (!Directory.Exists(_txtSrcFolder.Text))
                {
                    Invoke((MethodInvoker) delegate { Messager.Show(this, "Please select valid folder", MessageBoxIcon.Error, MessageBoxButtons.OK); });
                    return;
                }

                // Set the data version to latest, we want to update the data to use the latest
                FormRecognitionEngine.Version = FormRecognitionEngine.LatestVersion;

                // Set the full text search engine
                DiskMasterFormsRepository workingRepository = new DiskMasterFormsRepository(_codecs, _txtSrcFolder.Text);

#if FOR_DOTNET4
                if (_cbUseFullTextSearch.Checked)
                {
                    DiskFullTextSearchManager fullTextSearchManager = new DiskFullTextSearchManager();
                    fullTextSearchManager.IndexDirectory    = Path.Combine(workingRepository.Path, "index");
                    recognitionEngine.FullTextSearchManager = fullTextSearchManager;
                }
#endif
                IMasterFormsCategory parentCategory = workingRepository.RootCategory;
                Invoke((MethodInvoker) delegate { _prgbar.Maximum = parentCategory.MasterForms.Count; });

                for (int i = 0; i < _prgbar.Maximum; i++)
                {
                    if (!_isRunning)
                    {
                        return;
                    }

                    Invoke((MethodInvoker) delegate { _prgbar.Value++; });

                    //Get the Original Attributes
                    DiskMasterForm            originalMasterForm = parentCategory.MasterForms[i] as DiskMasterForm;
                    FormRecognitionAttributes originalAttributes = originalMasterForm.ReadAttributes();
                    recognitionEngine.OpenMasterForm(originalAttributes);
                    recognitionEngine.CloseMasterForm(originalAttributes);

                    FormRecognitionOptions    options    = new FormRecognitionOptions();
                    FormRecognitionAttributes attributes = recognitionEngine.CreateMasterForm(parentCategory.MasterForms[i].Name, new Guid(), options);
                    recognitionEngine.CloseMasterForm(attributes);

                    IMasterForm newForm = parentCategory.AddMasterForm(attributes, null, (RasterImage)null);

                    DiskMasterForm currentMasterForm = parentCategory.MasterForms[i] as DiskMasterForm;
                    attributes = currentMasterForm.ReadAttributes();
                    FormPages   formPages = currentMasterForm.ReadFields();
                    RasterImage formImage = currentMasterForm.ReadForm();

                    for (int j = 0; j < formImage.PageCount; j++)
                    {
                        //Get the Page Recognition Options for the original Attributes
                        PageRecognitionOptions pageOptions = GetPageOptions(j, originalAttributes);

                        //Add each new page to the masterform by creating attributes for each page
                        formImage.Page = j + 1;
                        recognitionEngine.OpenMasterForm(attributes);
                        recognitionEngine.DeleteMasterFormPage(attributes, j + 1);
                        recognitionEngine.InsertMasterFormPage(j + 1, attributes, formImage.Clone(), pageOptions, null);
#if FOR_DOTNET4
                        if (_cbUseFullTextSearch.Checked)
                        {
                            recognitionEngine.UpsertMasterFormToFullTextSearch(attributes, "index", null, null, null, null);
                        }
#endif

                        recognitionEngine.CloseMasterForm(attributes);
                    }

                    FormProcessingEngine tempProcessingEngine = new FormProcessingEngine();
                    tempProcessingEngine.OcrEngine     = ocrEngine;
                    tempProcessingEngine.BarcodeEngine = barcodeEngine;

                    for (int j = 0; j < recognitionEngine.GetFormProperties(attributes).Pages; j++)
                    {
                        tempProcessingEngine.Pages.Add(new FormPage(j + 1, formImage.XResolution, formImage.YResolution));
                    }

                    formPages = tempProcessingEngine.Pages;
                    currentMasterForm.WriteAttributes(attributes);

                    currentMasterForm.WriteFields(parentCategory.MasterForms[i].ReadFields());
                }
#if FOR_DOTNET4
                if (recognitionEngine.FullTextSearchManager != null)
                {
                    recognitionEngine.FullTextSearchManager.Index();
                }
#endif
                System.Diagnostics.Process.Start(_txtSrcFolder.Text);
            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate { Messager.Show(this, ex, MessageBoxIcon.Error); });
            }
            finally
            {
                // Restore the original version
                FormRecognitionEngine.Version = recognitionEngineVersion;
#if FOR_DOTNET4
                recognitionEngine.FullTextSearchManager = originalFullTextSearchManager;
#endif
                _isRunning = false;
                Invoke((MethodInvoker) delegate
                {
                    _prgbar.Value = 0;
                    UpdateControls();
                });
            }
        }
Exemple #5
0
        private bool AddField(DiskMasterForm currentform, List <XmlModel> model)
        {
            try
            {
                DiskMasterForm            currentMasterForm = currentform;
                FormRecognitionAttributes attributes        = currentMasterForm.ReadAttributes();
                FormPages   formPages = currentMasterForm.ReadFields();
                RasterImage formImage = currentMasterForm.ReadForm();
                foreach (XmlModel xmlModel in model)
                {
                    int i = formPages[xmlModel.PageNumber - 1].Count;
                    formPages[xmlModel.PageNumber - 1].RemoveRange(0, i);
                    foreach (XmlDetail xmlDetail in xmlModel.Detail)
                    {
                        FormField newField = null;

                        if (xmlDetail.FieldInfo.ObjectId == -51) // For textfield => -51 //for OmrField => -50
                        {
                            newField = new TextFormField();
                            (newField as TextFormField).EnableIcr = xmlDetail.FieldInfo.OcrFieldInfo.EnableICR;
                            (newField as TextFormField).EnableOcr = xmlDetail.FieldInfo.OcrFieldInfo.EnableOCR;
                            (newField as TextFormField).Type      = (xmlDetail.FieldInfo.OcrFieldInfo.Character == true ? TextFieldType.Character : (xmlDetail.FieldInfo.OcrFieldInfo.Numeric == true ? TextFieldType.Numerical : TextFieldType.Data));
                            if (xmlDetail.FieldInfo.OcrFieldInfo.CellBoarders)
                            {
                                newField.Dropout |= DropoutFlag.CellsDropout;
                            }
                            else
                            {
                                newField.Dropout &= ~DropoutFlag.CellsDropout;
                            }

                            if (xmlDetail.FieldInfo.OcrFieldInfo.Words)
                            {
                                newField.Dropout |= DropoutFlag.WordsDropout;
                            }
                            else
                            {
                                newField.Dropout &= ~DropoutFlag.WordsDropout;
                            }
                        }
                        else
                        {
                            newField = new OmrFormField();
                            if (xmlDetail.FieldInfo.OmrFieldInfo.WithFrame)
                            {
                                (newField as OmrFormField).FrameMethod = OcrOmrFrameDetectionMethod.WithFrame;
                            }
                            else if (xmlDetail.FieldInfo.OmrFieldInfo.WithoutFrame)
                            {
                                (newField as OmrFormField).FrameMethod = OcrOmrFrameDetectionMethod.WithoutFrame;
                            }
                            else if (xmlDetail.FieldInfo.OmrFieldInfo.Auto)
                            {
                                (newField as OmrFormField).FrameMethod = OcrOmrFrameDetectionMethod.Auto;
                            }

                            if (xmlDetail.FieldInfo.OmrFieldInfo.Lowest)
                            {
                                (newField as OmrFormField).Sensitivity = OcrOmrSensitivity.Lowest;
                            }
                            else if (xmlDetail.FieldInfo.OmrFieldInfo.Low)
                            {
                                (newField as OmrFormField).Sensitivity = OcrOmrSensitivity.Low;
                            }
                            else if (xmlDetail.FieldInfo.OmrFieldInfo.High)
                            {
                                (newField as OmrFormField).Sensitivity = OcrOmrSensitivity.High;
                            }
                            else if (xmlDetail.FieldInfo.OmrFieldInfo.Highest)
                            {
                                (newField as OmrFormField).Sensitivity = OcrOmrSensitivity.Highest;
                            }
                        }
                        newField.Name   = xmlDetail.FieldInfo.Name;
                        newField.Bounds = new LeadRect(Convert.ToInt32(Annotations.Engine.AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.X, Leadtools.Annotations.Engine.AnnUnit.Unit, 96)), Convert.ToInt32(Annotations.Engine.AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Y, Annotations.Engine.AnnUnit.Unit, 96)), Convert.ToInt32(Annotations.Engine.AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Width, Annotations.Engine.AnnUnit.Unit, 96)), Convert.ToInt32(Annotations.Engine.AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Height, Annotations.Engine.AnnUnit.Unit, 96)));
                        // newField.Bounds= new LogicalRectangle(AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.X, AnnUnit.Unit, 96), AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Y, AnnUnit.Unit, 96), AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Width, AnnUnit.Unit, 96), AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Height, AnnUnit.Unit, 96), LogicalUnit.Pixel);

                        Annotations.Engine.AnnHiliteObject newObject = new Annotations.Engine.AnnHiliteObject();
                        newObject.Tag = newField;
                        FormField currentField = newObject.Tag as FormField;
                        formPages[xmlModel.PageNumber - 1].Add(currentField);
                    }
                }
                currentMasterForm.WriteForm(formImage);
                currentMasterForm.WriteAttributes(attributes);
                currentMasterForm.WriteFields(formPages);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw;
            }
        }
Exemple #6
0
        public bool SaveXml([FromBody] XmlElement data, [FromUri] string FolderName)
        {
            try
            {
                #region Added by Prasanta, For saving XML in physical folder
                string strLogicalFolderName  = string.Empty;
                string strPhysicalFolderName = string.Empty;

                int start = FolderName.IndexOf("[[") + 2;
                int end   = FolderName.IndexOf("]]", start);
                strPhysicalFolderName = FolderName.Substring(start, end - start);
                strLogicalFolderName  = FolderName.Substring(0, FolderName.IndexOf("[["));
                #endregion

                //if (string.IsNullOrEmpty(Data))
                if (data == null)
                {
                    throw new ArgumentNullException("data");
                }

                // get an element from the string
                var    element  = data;
                string filePath = "";
                if (string.IsNullOrEmpty(FolderName))
                {
                    return(true);
                }
                //filePath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"MasterForm\Annotation\" + FolderName + ".xml");//commented By Prasanta
                filePath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"MasterForm\Annotation\" + strLogicalFolderName + ".xml");

                // Save the data
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent             = true;
                settings.OmitXmlDeclaration = false;
                settings.Encoding           = Encoding.UTF8;

                using (XmlWriter writer = XmlWriter.Create(filePath, settings))
                {
                    writer.WriteStartDocument();
                    element.WriteTo(writer);
                    writer.WriteEndDocument();
                }

                //string workingDirectory = HttpContext.Current.Server.MapPath("~/" + RootFolderName + "/" + FolderName);//Commented by Prasanta
                //string workingFile = HttpContext.Current.Server.MapPath("~/" + RootFolderName + "/Annotation/" + FolderName + ".xml");//Commented by Prasanta
                string workingDirectory = HttpContext.Current.Server.MapPath("~/" + RootFolderName + "/" + strPhysicalFolderName);
                string workingFile      = HttpContext.Current.Server.MapPath("~/" + RootFolderName + "/Annotation/" + strLogicalFolderName + ".xml");
                if (Directory.Exists(workingDirectory) && File.Exists(workingFile))
                {
                    using (RasterCodecs _codecs = new RasterCodecs())
                    {
                        RasterDefaults.DitheringMethod = RasterDitheringMethod.None;
                        ServiceHelper.SetLicense();
                        workingRepository = new DiskMasterFormsRepository(_codecs, workingDirectory);
                        var masterForm = workingRepository?.RootCategory?.MasterForms?.FirstOrDefault();


                        if (masterForm != null)
                        {
                            DiskMasterForm currentMasterForm = (DiskMasterForm)masterForm;
                            bool           result            = AddField(currentMasterForm, GetPoints(workingFile));
                        }
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }