Esempio n. 1
0
        internal static byte[] ConvertPageToGrayscaleImageIncludeAnnotations(IDocLib library, string path, int pageIndex)
        {
            using (var docReader = library.GetDocReader(path, new PageDimensions(1080, 1920)))
            {
                using (var pageReader = docReader.GetPageReader(pageIndex))
                {
                    var bytes = GetModifiedImage(pageReader);

                    return(bytes);
                }
            }
        }
Esempio n. 2
0
        internal static byte[] ConvertPageToSimpleImageWithoutTransparency(IDocLib library, string path, int pageIndex)
        {
            using (var docReader = library.GetDocReader(path, new PageDimensions(1080, 1920)))
            {
                using (var pageReader = docReader.GetPageReader(pageIndex))
                {
                    var bytes = GetModifiedImage(pageReader);

                    return(bytes);
                }
            }
        }
Esempio n. 3
0
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
        #endregion
        public MainViewModel(IOptionService optionService, IDirectoryService directoryService,
                             IAppService infoService, IThemeService themeService)
        {
            // Initialize services
            _docLib           = DocLib.Instance;
            _optionService    = optionService;
            _directoryService = directoryService;
            _themeService     = themeService;
            _infoService      = infoService;

            // Initialize commands
            GetDirectory = ReactiveCommand.Create(BrowseDirectory);
            ReadPDF      = ReactiveCommand.Create(() => {
                _th = new Thread(() => StartReading());
                _th.IsBackground = true;
                _th.Start();
            }, this.IsValid());
            ChangeTheme = ReactiveCommand.Create(() =>
            {
                themeService.ChangeTheme();
                CurrentThemeName = themeService.GetCurrentThemeName();
            });
            ChangeLanguage = ReactiveCommand.Create(() =>
            {
                infoService.ChangeLanguage();
                CurrentLanguageName = infoService.GetCurrentLanguage();
                UpdateStringResources();
            });

            // Initialize variables
            PrecisionOCR = new ObservableCollection <RecognitionPrecision>(Enum.GetValues(typeof(RecognitionPrecision)).Cast <RecognitionPrecision>());
            LanguageOCR  = new ObservableCollection <RecognitionLanguage>(Enum.GetValues(typeof(RecognitionLanguage)).Cast <RecognitionLanguage>());
            Options      = new SearchOptions("", "", PrecisionOCR.FirstOrDefault(), LanguageOCR.FirstOrDefault(),
                                             false, true, false, true, false, false);
            Results             = new ObservableCollection <QueryResult>();
            Stats               = new ResultStats("0/0", true, 0, "0");
            ResultInfo          = infoService.GetSearchInfo(SearchInfo.Init);
            StatusName          = infoService.GetSearchStatus(SearchStatus.Ready);
            CurrentThemeName    = themeService.GetCurrentThemeName();
            CurrentLanguageName = infoService.GetCurrentLanguage();
            ItemsReady          = false;

            // Subscribe for events and set validation rules
            ErrorsChanged += OnValidationErrorsChanged;
            this.ValidationRule(x => x.Options.Keyword, key => !string.IsNullOrEmpty(key), "Keyword cannot be empty!");
            this.ValidationRule(x => x.Options.Path, key => !string.IsNullOrEmpty(key) && Directory.Exists(key), "Path has to be valid!");

            // Get assembly version
            AppVersion = infoService.GetVersion();
        }
Esempio n. 4
0
        public MemoryStream PdfToImage(Stream filepdf)
        {
            var          pdfBytes     = ReadToEnd(filepdf);
            MemoryStream memoryStream = new MemoryStream();
            MagickImage  imgBackdrop;
            MagickColor  backdropColor = MagickColors.White; // replace transparent pixels with this color
            int          pdfPageNum    = 0;                  // first page is 0

            using (IDocLib pdfLibrary = DocLib.Instance)
            {
                // Console.WriteLine("pdfBytes");
                //Console.WriteLine(pdfBytes.Length);
                using (var docReader = pdfLibrary.GetDocReader(pdfBytes, new PageDimensions(1.0d)))
                {
                    using (var pageReader = docReader.GetPageReader(pdfPageNum))
                    {
                        var rawBytes = pageReader.GetImage();
                        rawBytes = RearrangeBytesToRGBA(rawBytes);
                        var width  = pageReader.GetPageWidth();
                        var height = pageReader.GetPageHeight();

                        PixelReadSettings pixelReadSettings = new PixelReadSettings(width, height, StorageType.Char, PixelMapping.RGBA);
                        using (MagickImage imgPdfOverlay = new MagickImage(rawBytes, pixelReadSettings))
                        {
                            imgBackdrop = new MagickImage(backdropColor, width, height);
                            imgBackdrop.Composite(imgPdfOverlay, CompositeOperator.Over);
                        }
                    }
                }
            }

            imgBackdrop.Write(memoryStream, MagickFormat.Png);
            imgBackdrop.Dispose();
            memoryStream.Position = 0;
            return(memoryStream);
        }
Esempio n. 5
0
 public ExampleFixture()
 {
     DocNet = DocLib.Instance;
 }
Esempio n. 6
0
        internal static byte[] ConvertPageToSimpleImageWithLetterOutlinesUsingScaling(IDocLib library, string path, int pageIndex)
        {
            using (var docReader = library.GetDocReader(path, new PageDimensions(1.337)))
            {
                using (var pageReader = docReader.GetPageReader(pageIndex))
                {
                    var bytes = GetModifiedImage(pageReader);

                    return(bytes);
                }
            }
        }