コード例 #1
0
        /// <summary>
        /// Gets text from a PDF based that is within a given area.
        /// </summary>
        /// <param name="pdfFilePath">PDF location on disk.</param>
        /// <param name="cropAreaInfo">Percentual area which is to be extracted.</param>
        /// <param name="pdfPageSizeInfo">Size information of the PDF file. Used to calculate absolute area from percental area.</param>
        /// <returns></returns>
        public async Task <string> GetTextFromPdf(string pdfFilePath, PercentalAreaInfo cropAreaInfo, PdfPageSizeInfo pdfPageSizeInfo)
        {
            var pdfInfo = pdfPageSizeInfo;
            var x       = (int)Math.Round(cropAreaInfo.TopLeftX * pdfInfo.SizeX, 0);
            var y       = (int)Math.Round(cropAreaInfo.TopLeftY * pdfInfo.SizeY, 0);
            var W       = (int)Math.Round(cropAreaInfo.Width * pdfInfo.SizeX, 0);
            var H       = (int)Math.Round(cropAreaInfo.Height * pdfInfo.SizeY, 0);

            var pdfToTextOptions = " -f " + cropAreaInfo.PageNumber + " -l " + cropAreaInfo.PageNumber + " -x " + x + " -y " + y + " -W " + W + " -H " + H + " -layout -nopgbrk ";

            var retVal = await GetTextFromPdf(pdfFilePath, false, pdfToTextOptions);

            // Remove last line break, as it is added by poppler and does not represent the selected area
            if (retVal.Length > 1)
            {
                retVal = retVal.Remove(retVal.Length - 2);
            }

            if (retVal is null)
            {
                retVal = string.Empty;
            }

            return(retVal);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        /// <summary>
        /// Changes or defines a new value area
        /// </summary>
        /// <param name="areaInfo">percental area info</param>
        public void ChangeValueArea(PercentalAreaInfo areaInfo)
        {
            this.ValueArea = areaInfo;

            txtRegexOrPosition.Text = "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) + " %";
        }
コード例 #4
0
        public async Task <string> GetTextFromPdf(string pdfFilePath, int pageNumber, float percentalLeftX, float percentalTopY, float percentalWidth, float percentalHeigth)
        {
            var cropArea = new PercentalAreaInfo()
            {
                PageNumber = pageNumber,
                TopLeftX   = percentalLeftX,
                TopLeftY   = percentalTopY,
                Width      = percentalWidth,
                Height     = percentalHeigth
            };

            return(await AreaLoader.GetTextFromPdf(pdfFilePath, cropArea));
        }
コード例 #5
0
        public void FireTextSelected(string selectedText, int pageNumber, float percentalTopLeftX, float percentalTopLeftY, float percentalWidth, float percentalHeight)
        {
            var areaInfo = new PercentalAreaInfo()
            {
                PageNumber = pageNumber,
                TopLeftX   = percentalTopLeftX,
                TopLeftY   = percentalTopLeftY,
                Width      = percentalWidth,
                Height     = percentalHeight
            };

            TextSelected?.Invoke(selectedText, areaInfo);
        }
コード例 #6
0
 /// <summary>
 /// Changes or defines a new value area
 /// </summary>
 /// <param name="positionHelperID">ID of the area position, which shall be changed</param>
 /// <param name="areaInfo">percental area info</param>
 public void ChangeValueArea(Guid positionHelperID, PercentalAreaInfo areaInfo)
 {
     foreach (Control control in flowLayoutPanel1.Controls)
     {
         var dataFieldControl = control as ucDataFieldClassTemplate;
         if (dataFieldControl != null)
         {
             try
             {
                 var id = (Guid)(dataFieldControl.Tag);
                 if (id == positionHelperID)
                 {
                     dataFieldControl.ChangeValueArea(areaInfo);
                     return;
                 }
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.Message);
             }
         }
     }
 }
コード例 #7
0
 public async Task <string> GetTextFromPdf(string pdfFilePath, PercentalAreaInfo cropAreaInfo)
 {
     return(await AreaLoader.GetTextFromPdf(pdfFilePath, cropAreaInfo));
 }
コード例 #8
0
        /// <summary>
        /// Gets text from a PDF based that is within a given area.
        /// </summary>
        /// <param name="pdfFilePath">PDF location on disk.</param>
        /// <param name="cropAreaInfo">Percentual area which is to be extracted.</param>
        /// <returns></returns>
        public async Task <string> GetTextFromPdf(string pdfFilePath, PercentalAreaInfo cropAreaInfo)
        {
            var pdfInfo = await GetPdfPageSize(pdfFilePath);

            return(await GetTextFromPdf(pdfFilePath, cropAreaInfo, pdfInfo));
        }
コード例 #9
0
ファイル: ucViewer.cs プロジェクト: pikju/DokuExtractor
 private void ViewerControlBase_TextSelected(string selectedText, PercentalAreaInfo areaInfo)
 {
     TextSelected?.Invoke(selectedText, areaInfo);
 }
コード例 #10
0
 /// <summary>
 /// Changes or defines a new value area
 /// </summary>
 /// <param name="positionHelperID">ID of the area position, which shall be changed</param>
 /// <param name="areaInfo">percental area info</param>
 public void ChangeValueArea(Guid positionHelperID, PercentalAreaInfo areaInfo)
 {
     ucDataFieldEditor1.ChangeValueArea(positionHelperID, areaInfo);
 }
コード例 #11
0
 /// <summary>
 /// Changes or defines a new value area
 /// </summary>
 /// <param name="positionHelperID">ID of the area position, which shall be changed</param>
 /// <param name="areaInfo">percental area info</param>
 public void ChangeValueArea(Guid positionHelperID, PercentalAreaInfo areaInfo)
 {
     ucSingleTemplateEditor1.ChangeValueArea(positionHelperID, areaInfo);
 }
コード例 #12
0
 /// <summary>
 /// Changes or defines a new value area
 /// </summary>
 /// <param name="positionHelperID">ID of the area position, which shall be changed</param>
 /// <param name="areaInfo">percental area info</param>
 private void ChangeValueArea(Guid positionHelperID, PercentalAreaInfo areaInfo)
 {
     ucResultAndEditor1.ChangeValueArea(positionHelperID, areaInfo);
 }
コード例 #13
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);
            }
        }