コード例 #1
0
        public void DisplayTextBlocks()
        {
            if (PagePlotModel == null)
            {
                return;
            }

            foreach (var s in PagePlotModel.Series.Where(s => (string)s.Tag == "textblock").ToList())
            {
                PagePlotModel.Series.Remove(s);
            }

            foreach (var block in _pdfPageModel.GetTextBlocks())
            {
                var series1 = new LineSeries {
                    Tag = "textblock", Title = GetShorterText(block.Text), LineStyle = LineStyle.Solid, Color = OxyColors.Brown
                };
                var bbox = block.BoundingBox;
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomRight));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopRight));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopLeft));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                PagePlotModel.Series.Add(series1);
            }

            PagePlotModel.InvalidatePlot(true);
        }
コード例 #2
0
        public void DisplayImages()
        {
            if (PagePlotModel == null)
            {
                return;
            }

            foreach (var s in PagePlotModel.Series.Where(s => (string)s.Tag == "image").ToList())
            {
                PagePlotModel.Series.Remove(s);
            }

            foreach (var block in _pdfPageModel.GetImages())
            {
                var series1 = new LineSeries {
                    Tag = "image", Title = "image", LineStyle = LineStyle.Solid, Color = OxyColors.YellowGreen
                };
                var bbox = block.Bounds;
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomRight));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopRight));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopLeft));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                PagePlotModel.Series.Add(series1);
            }

            PagePlotModel.InvalidatePlot(true);
        }
コード例 #3
0
        public void DisplayLetters()
        {
            if (PagePlotModel == null)
            {
                return;
            }

            foreach (var s in PagePlotModel.Series.Where(s => (string)s.Tag == "letter").ToList())
            {
                PagePlotModel.Series.Remove(s);
            }

            foreach (var letter in _pdfPageModel.GetLetters())
            {
                var series1 = new LineSeries {
                    Tag = "letter", Title = GetShorterText(letter.Value), LineStyle = LineStyle.Solid, Color = OxyColors.Blue
                };
                var bbox = letter.GlyphRectangle;
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomRight));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopRight));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopLeft));
                series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                PagePlotModel.Series.Add(series1);
            }

            PagePlotModel.InvalidatePlot(true);
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel" /> class.
        /// </summary>
        public MainViewModel()
        {
            CustomController = new CustomPlotController();

            WordExtractorList = new ObservableCollection <Type>(PdfDocumentModel.GetWordExtractors());
            PageSegmenterList = new ObservableCollection <Type>(PdfDocumentModel.GetPageSegmenters());
        }
コード例 #5
0
        public void OpenDocument(string path)
        {
            if (Path.GetExtension(path) != ".pdf")
            {
                return;
            }

            _pdfImageConverter = new PdfImageConverter(path);
            _pdfDocumentModel  = PdfDocumentModel.Open(path);
            NumberOfPages      = _pdfDocumentModel.NumberOfPages;
            CurrentPageNumber  = 1;
        }
コード例 #6
0
        public void DisplayPaths()
        {
            if (PagePlotModel == null)
            {
                return;
            }

            foreach (var s in PagePlotModel.Series.Where(s => (string)s.Tag == "pdfpath").ToList())
            {
                PagePlotModel.Series.Remove(s);
            }

            foreach (var path in _pdfPageModel.GetPdfPaths())
            {
                foreach (var sp in path)
                {
                    string title = ("path: " + (path.IsStroked ? "stroked " + (path.StrokeColor?.ToRGBValues()).ToString() : "") +
                                    (path.IsFilled ? "filled " + (path.FillColor?.ToRGBValues()).ToString() : "") +
                                    (path.IsClipping ? "clipping" : "")
                                    ).Trim();
                    var series1 = new LineSeries {
                        Tag = "pdfpath", Title = title, LineStyle = LineStyle.Solid, Color = OxyColors.Yellow
                    };

                    PdfPoint first = PdfPoint.Origin;
                    foreach (var c in sp.Commands)
                    {
                        if (c is Move m)
                        {
                            first = m.Location;
                            series1.Points.Add(PdfDocumentModel.ToDataPoint(first));
                        }
                        else if (c is Line l)
                        {
                            series1.Points.Add(PdfDocumentModel.ToDataPoint(l.From));
                            series1.Points.Add(PdfDocumentModel.ToDataPoint(l.To));
                        }
                        else if (c is BezierCurve bc)
                        {
                            var lines = bc.ToLines(10).ToList();
                            for (int i = 0; i < lines.Count; i++)
                            {
                                series1.Points.Add(PdfDocumentModel.ToDataPoint(lines[i].From));
                                series1.Points.Add(PdfDocumentModel.ToDataPoint(lines[i].To));
                            }
                        }
                        else if (c is Close)
                        {
                            series1.Points.Add(PdfDocumentModel.ToDataPoint(first));
                        }
                        else
                        {
                            throw new ArgumentException();
                        }
                    }

                    PagePlotModel.Series.Add(series1);
                }
            }

            PagePlotModel.InvalidatePlot(true);
        }
コード例 #7
0
        private void DisplayPage(int pageNo)
        {
            if (_pdfDocumentModel == null)
            {
                return;
            }

            var page = _pdfDocumentModel.GetPage(pageNo);

            // Create the plot model
            var tmp = new PlotModel {
                IsLegendVisible = false
            };

            tmp.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, Minimum = 0, Maximum = page.Height
            });
            tmp.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, Minimum = 0, Maximum = page.Width
            });



            switch (BboxLevel)
            {
            case "Words":
                foreach (var word in page.GetWords())
                {
                    var series1 = new LineSeries {
                        Title = GetShorterText(word.Text), LineStyle = LineStyle.Solid, Color = OxyColors.Red
                    };
                    var bbox = word.BoundingBox;
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomRight));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopRight));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopLeft));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                    tmp.Series.Add(series1);
                }
                break;

            case "Lines":
                foreach (var line in page.GetTextBlocks().SelectMany(b => b.TextLines))
                {
                    var series1 = new LineSeries {
                        Title = GetShorterText(line.Text), LineStyle = LineStyle.Solid, Color = OxyColors.Red
                    };
                    var bbox = line.BoundingBox;
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomRight));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopRight));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopLeft));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                    tmp.Series.Add(series1);
                }
                break;

            case "Paragraphs":
                foreach (var block in page.GetTextBlocks())
                {
                    var series1 = new LineSeries {
                        Title = GetShorterText(block.Text), LineStyle = LineStyle.Solid, Color = OxyColors.Red
                    };
                    var bbox = block.BoundingBox;
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomRight));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopRight));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopLeft));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                    tmp.Series.Add(series1);
                }
                break;

            default:
                foreach (var letter in page.GetLetters())
                {
                    var series1 = new LineSeries {
                        Title = letter.Value, LineStyle = LineStyle.Solid, Color = OxyColors.Red
                    };
                    var bbox = letter.GlyphRectangle;
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomRight));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopRight));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.TopLeft));
                    series1.Points.Add(PdfDocumentModel.ToDataPoint(bbox.BottomLeft));
                    tmp.Series.Add(series1);
                }
                break;
            }

            // Add background image
            try
            {
                using (var stream = _pdfImageConverter.GetPageStream(pageNo, 2))
                {
                    Image = new OxyImage(stream);
                }

                tmp.Annotations.Add(new ImageAnnotation
                {
                    ImageSource         = Image,
                    Opacity             = 0.5,
                    X                   = new PlotLength(0, PlotLengthUnit.Data),
                    Y                   = new PlotLength(0, PlotLengthUnit.Data),
                    Width               = new PlotLength(page.Width, PlotLengthUnit.Data),
                    Height              = new PlotLength(page.Height, PlotLengthUnit.Data),
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Bottom
                });
            }
            catch (Exception)
            {
                throw;
            }

            this.PlotModel = tmp;
        }