예제 #1
0
            public PageInfoModel(PdfPageModel pdfPageModel)
            {
                this.pdfPageModel = pdfPageModel;
                var filteredLetters = pdfPageModel.GetLetters().Where(l => !string.IsNullOrEmpty(l.Value.Trim())).ToList();

                HeightDistribution = new Distribution(filteredLetters.Select(l => l.GlyphRectangle.Height));
                WidthDistribution  = new Distribution(filteredLetters.Select(l => l.GlyphRectangle.Width));
            }
예제 #2
0
        private bool LoadPage(int pageNo)
        {
            if (_pdfDocumentModel == null)
            {
                return(false);
            }

            _pdfPageModel = _pdfDocumentModel.GetPage(pageNo);

            if (_pdfPageModel == null)
            {
                return(false);
            }

            // set remove duplicate letters
            _pdfPageModel.SetRemoveDuplicateLetters(_removeDuplicateLetters);

            // set word extractor
            _pdfPageModel.SetWordExtractor(WordExtractor);

            // set page segmenter
            _pdfPageModel.SetPageSegmenter(PageSegmenter);

            var pageInfoModel = _pdfPageModel.GetPageInfo();

            // Plot height distrib
            HeightHistoPlotModel = pageInfoModel.HeightDistribution?.GetPlotModel("Letters height distribution");
            WidthHistoPlotModel  = pageInfoModel.WidthDistribution?.GetPlotModel("Letters width distribution");

            // Plot page
            var pagePlotModel = new PlotModel {
                IsLegendVisible = false
            };

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

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

                pagePlotModel.Annotations.Add(new ImageAnnotation
                {
                    ImageSource         = PageImage,
                    Opacity             = 0.5,
                    X                   = new PlotLength(_pdfPageModel.CropBox.Bounds.BottomLeft.X, PlotLengthUnit.Data),
                    Y                   = new PlotLength(_pdfPageModel.CropBox.Bounds.BottomLeft.Y, PlotLengthUnit.Data),
                    Width               = new PlotLength(_pdfPageModel.CropBox.Bounds.Width, PlotLengthUnit.Data),
                    Height              = new PlotLength(_pdfPageModel.CropBox.Bounds.Height, PlotLengthUnit.Data),
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Bottom
                });
            }
            catch (Exception)
            {
                throw;
            }

            this.PagePlotModel = pagePlotModel;

            if (IsDisplayLetters)
            {
                DisplayLetters();
            }

            if (IsDisplayWords)
            {
                DisplayWords();
            }

            if (IsDisplayTextLines)
            {
                DisplayTextLines();
            }

            if (IsDisplayTextBlocks)
            {
                DisplayTextBlocks();
            }

            if (IsDisplayPaths)
            {
                DisplayPaths();
            }

            if (IsDisplayImages)
            {
                DisplayImages();
            }

            return(true);
        }