private async void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;

            if (string.IsNullOrWhiteSpace(this.pdfPath) == false)
            {
                var rect = GetRectangleOnImageFromLastPoint(e.Location);

                var crop = new PercentalAreaInfo()
                {
                    PageNumber = activePageIndex + 1,
                    TopLeftX   = (float)(rect.X) / (float)(pictureBox1.Image.Width),
                    TopLeftY   = (float)(rect.Y) / (float)(pictureBox1.Image.Height),
                    Height     = (float)(rect.Height) / (float)(pictureBox1.Image.Height),
                    Width      = (float)(rect.Width) / (float)(pictureBox1.Image.Width)
                };

                var rectText = await PdfTextLoader.GetTextFromPdf(pdfPath, crop);

                tooltip.Hide(this);
                FireTextSelected(rectText, crop.PageNumber, crop.TopLeftX, crop.TopLeftY, crop.Width, crop.Height);
                if (string.IsNullOrEmpty(rectText) == false)
                {
                    Clipboard.SetText(rectText);
                }
                tooltip.Show(rectText, this, this.PointToClient(Control.MousePosition), 5000);
            }

            lastPoint = Point.Empty;
        }
Exemplo n.º 2
0
        private async void butGo_Click(object sender, EventArgs e)
        {
            ucResultAndEditor1.SwitchTab(false);
            //  var loader = new PdfTextLoader();
            var inputString = await PdfTextLoader.GetTextFromPdf(selectedFilePath, false);

            var matchingTemplateResult = templateProcessor.MatchTemplates(this.classTemplates, inputString);
            var template = matchingTemplateResult.GetTemplate();

            if (matchingTemplateResult.IsMatchSuccessfull)
            {
                MessageBox.Show(Translation.LanguageStrings.MsgTemplateFound + template.TemplateClassName, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
                var result = await templateProcessor.ExtractData(template, groupTemplates, inputString, selectedFilePath);

                var groupTemplate = groupTemplates.Where(x => x.TemplateGroupName == template.TemplateGroupName).FirstOrDefault();
                ucResultAndEditor1.ShowExtractedData(result, template, groupTemplate);
            }
            else
            {
                //   template = templateProcessor.AutoCreateClassTemplate("NewTemplate", inputString, this.groupTemplates);
                var baseGroupTemplateMatchResult = templateProcessor.MatchTemplates(groupTemplates, inputString);
                if (baseGroupTemplateMatchResult.IsMatchSuccessfull)
                {
                    template = templateProcessor.AutoCreateClassTemplate("NewTemplate", inputString, baseGroupTemplateMatchResult.GetTemplate());
                }
                else
                {
                    // TODO: Show group template selection dialog instead of defaulting to "Rechnung"
                    using (var frmGroupTemplate = new frmGroupTemplateSelection(groupTemplates))
                    {
                        frmGroupTemplate.ShowDialog();
                        if (frmGroupTemplate.SelectedGrouptTemplate != null)
                        {
                            template = templateProcessor.AutoCreateClassTemplate("NewTemplate", inputString, frmGroupTemplate.SelectedGrouptTemplate);
                        }
                        else
                        {
                            template = templateProcessor.AutoCreateClassTemplate("NewTemplate", inputString, groupTemplates.Where(x => x.TemplateGroupName == "Rechnung").FirstOrDefault());
                        }
                    }
                }

                var result = await templateProcessor.ExtractData(template, groupTemplates, inputString, selectedFilePath);

                var groupTemplate = groupTemplates.Where(x => x.TemplateGroupName == template.TemplateGroupName).FirstOrDefault();
                ucResultAndEditor1.ShowExtractedData(result, template, groupTemplate);

                ucResultAndEditor1.SwitchTab(true);
                MessageBox.Show(Translation.LanguageStrings.MsgNoTemplateFound, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        public override async Task LoadPdf(string pdfPath)
        {
            this.pdfPath = pdfPath;

            //var pdfTextLoader = new PdfTextLoader();
            var hashwert = PdfTextLoader.CheckMD5(pdfPath);

            var dexTempPath = Path.Combine(Application.StartupPath, "DexPdfTemp");

            if (Directory.Exists(dexTempPath) == false)
            {
                var dir = Directory.CreateDirectory(dexTempPath);
                dir.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
            }

            var pdfImagesPath = Path.Combine(dexTempPath, hashwert);

            if (Directory.Exists(pdfImagesPath) == false)
            {
                var dir = Directory.CreateDirectory(pdfImagesPath);
                dir.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
            }

            if (Directory.GetFiles(pdfImagesPath)?.Count() == 0)
            {
                await PdfRenderer.RenderPdfToPngs(pdfPath, pdfImagesPath);
            }

            CloseDisplayedPdf();

            foreach (var file in Directory.GetFiles(pdfImagesPath))
            {
                AddPageToThumbnailViewer(file);
            }

            var firstPage = flowLayoutPanel1.Controls[0] as PictureBox;

            ImageViewer_Click(firstPage, null);
        }
Exemplo n.º 4
0
        private async void UcViewer1_TextSelected(string selectedText, PercentalAreaInfo areaInfo)
        {
            if (isAnchorSelectionRunning)
            {
                this.regexHelperAnchorText = selectedText;
                isAnchorSelectionRunning   = false;
                isValueSelectionRunning    = true;
                lblInstruction.Text        = Translation.LanguageStrings.InstructionSelectValue;
                lblInstruction.BackColor   = Color.Yellow;
            }
            else if (isValueSelectionRunning)
            {
                this.regexHelperValueText = selectedText;
                isValueSelectionRunning   = false;
                lblInstruction.Text       = string.Empty;
                lblInstruction.BackColor  = Color.White;

                // var loader = new PdfTextLoader();
                var inputString = await PdfTextLoader.GetTextFromPdf(selectedFilePath, false);

                var regexResult = new RegexExpressionFinderResult();
                if (templateProcessor.TryFindRegexMatchExpress(inputString, regexHelperAnchorText, regexHelperValueText, regexHelperFieldType, false, out regexResult))
                {
                    var matchingValues = string.Empty;
                    foreach (var matchingValue in regexResult.AllMatchingValues)
                    {
                        matchingValues = matchingValues + Environment.NewLine + matchingValue;
                    }

                    var result = MessageBox.Show(Translation.LanguageStrings.MsgAskAcceptRegexExpressionHelperResult + Environment.NewLine + Environment.NewLine + "Regex Expression: " + regexResult.RegexExpression
                                                 + Environment.NewLine + "Matching Values: " + matchingValues, string.Empty, MessageBoxButtons.YesNo);

                    if (result == DialogResult.Yes)
                    {
                        var additionalRegex = MessageBox.Show(Translation.LanguageStrings.MsgAskAdditionalRegexExpression, string.Empty, MessageBoxButtons.YesNo);
                        if (additionalRegex == DialogResult.Yes)
                        {
                            ChangeOrAddRegexExpression(this.regexOrPositionHelperId, regexResult.RegexExpression, true);
                        }
                        else
                        {
                            ChangeOrAddRegexExpression(this.regexOrPositionHelperId, regexResult.RegexExpression, false);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(Translation.LanguageStrings.MsgNoRegexExpressionFinderResult, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                EnableOrDisableControlsAndButtons(true);
            }
            else if (isPositionSelectionRunning)
            {
                isPositionSelectionRunning = false;
                lblInstruction.Text        = string.Empty;
                lblInstruction.BackColor   = Color.White;

                var result = MessageBox.Show(Translation.LanguageStrings.MsgAskAcceptRegexExpressionHelperResult + Environment.NewLine + Environment.NewLine
                                             + "Position:" + Environment.NewLine + "page\t" + areaInfo.PageNumber + Environment.NewLine + "x\t" + Math.Round(areaInfo.TopLeftX * 100, 1) + " %"
                                             + Environment.NewLine + "y\t" + Math.Round(areaInfo.TopLeftY * 100, 1) + " %" + Environment.NewLine + "width\t" + Math.Round(areaInfo.Width * 100, 1) + " %"
                                             + Environment.NewLine + "height\t" + Math.Round(areaInfo.Height * 100, 1) + " %" + Environment.NewLine + Environment.NewLine
                                             + "Text: " + Environment.NewLine + selectedText, string.Empty, MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    ChangeValueArea(this.regexOrPositionHelperId, areaInfo);
                }

                EnableOrDisableControlsAndButtons(true);
            }
        }