コード例 #1
0
        private void MenuOpenOnClick(object sender, EventArgs e)
        {
            if (_openFileDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            var file       = _openFileDialog.FileName;
            var frameCount = RegisteredDecoders.GetImageInfo(file, 0).FrameCount;

            _totalPageLabel.Text = @"of " + frameCount;
            _thumbnailView.Items.Cancel();
            _thumbnailView.Items.Clear();

            // Create the Thumbnail objects and pass them into the ThumbnailView all at once.
            var thumbs = new Thumbnail[frameCount];

            for (var i = 0; i < frameCount; i++)
            {
                thumbs[i] = new Thumbnail(file, i, (i + 1).ToString(), "");
            }
            _thumbnailView.Items.AddRange(thumbs);

            //open the first full size page
            ViewPage(0);

            _extractedImages = false;
            _currentFile     = file;
            _workspaceViewer.Annotations.CurrentLayer.Items.Clear();
            _menuItemFind.Enabled = true;

            LoadPdfBookmarks(file);
        }
コード例 #2
0
        private void UploadFile(HttpContext context, string filename)
        {
            var file = context.Request.Files[0];

            using (var outStream = new FileStream(filename, FileMode.CreateNew, FileAccess.ReadWrite))
            {
                using (var ms = new MemoryStream())
                {
                    file.InputStream.CopyTo(ms);
                    ms.Seek(0, 0);

                    var decoder = RegisteredDecoders.GetDecoder(ms);
                    if (decoder is TiffDecoder || decoder is PdfDecoder || decoder is OfficeDecoder)
                    {
                        ms.CopyTo(outStream);
                    }
                    else
                    {
                        var ic          = new ImageCollection(ms, null);
                        var tiffEncoder = new TiffEncoder();
                        ic.Save(outStream, tiffEncoder, null);
                    }
                }
            }
        }
コード例 #3
0
        private void OnPageTextRequested(object sender, PageTextRequestedEventArgs pageTextRequestedEventArgs)
        {
            var serverPath = HttpContext.Current.Server.MapPath(pageTextRequestedEventArgs.FilePath);

            if (File.Exists(serverPath))
            {
                using (var stream = File.OpenRead(serverPath))
                {
                    try
                    {
                        var decoder = RegisteredDecoders.GetDecoder(stream) as ITextFormatDecoder;
                        if (decoder != null)
                        {
                            using (var extractor = new SegmentedTextTranslator(decoder.GetTextDocument(stream)))
                            {
                                // for documents that have comlicated structure, i.e. consist from the isolated pieces of text, or table structure
                                // it's possible to configure nearby text blocks are combined into text segments(text containers that provide
                                // selection isolated from other document content)
                                extractor.RegionDetection = TextRegionDetectionMode.BlockDetection;

                                // each block boundaries inflated to one average character width and two average character height
                                // and all intersecting blocks are combined into single segment.
                                // Having vertical ratio bigger then horizontal behaves better on column-layout documents.
                                extractor.BlockDetectionDistance = new System.Drawing.SizeF(1, 2);
                                pageTextRequestedEventArgs.Page  = extractor.ExtractPageText(pageTextRequestedEventArgs.Index);
                            }
                        }
                    }
                    catch (ImageReadException imagingException)
                    {
                        Debug.WriteLine("Text extraction: image type is not recognized. {0}", imagingException);
                    }
                }
            }
        }
コード例 #4
0
        private Int32 FramCount(string ImagePath)
        {
            Int32 frmCount;

            try
            {
                frmCount = RegisteredDecoders.GetImageInfo(ImagePath).FrameCount;
                return(frmCount);
            }
            catch
            {
                return(-1);
            }
        }
コード例 #5
0
            public LayerCollection ToAnnotationUI(LayerData[] layers, string docPath)
            {
                Size[] pageSizes = new Size[0];

                if (File.Exists(docPath))
                {
                    using (FileStream fs = new FileStream(docPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        pageSizes = new PageSizeAggregate(new DocumentPageSizes(RegisteredDecoders.GetDecoder(fs), fs, false)).ToArray();
                    }
                }

                return ToAnnotationUI(layers, pageSizes);
            }
コード例 #6
0
        public LayerData[] ToWebDocumentViewer(LayerCollection layerCollection, string docPath)
        {
            var pageSizes = new Size[0];

            if (File.Exists(docPath))
            {
                using (var fs = new FileStream(docPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    pageSizes = new PageSizeAggregate(new DocumentPageSizes(RegisteredDecoders.GetDecoder(fs), fs, false)).ToArray();
                }
            }

            return(ToWebDocumentViewer(layerCollection, pageSizes));
        }
コード例 #7
0
        private string UploadFile(HttpContext context, string filename)
        {
            string         msg  = "";
            HttpPostedFile file = context.Request.Files[0];

            byte[] fileBytes = new byte[file.ContentLength];
            file.InputStream.Read(fileBytes, 0, file.ContentLength);


            using (FileStream outStream = new FileStream(filename, FileMode.CreateNew, FileAccess.ReadWrite))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    ms.Write(fileBytes, 0, fileBytes.Length);
                    ms.Position = 0;
                    try
                    {
                        ImageDecoder decoder = RegisteredDecoders.GetDecoder(ms);
                        if (decoder is TiffDecoder)
                        {
                            outStream.Write(fileBytes, 0, fileBytes.Length);
                            outStream.Position = 0;
                        }
                        else
                        {
                            ImageCollection ic          = new ImageCollection(ms, null);
                            TiffEncoder     tiffEncoder = new TiffEncoder();
                            ic.Save(outStream, tiffEncoder, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        msg = ex.Message;
                    }

                    ms.Position = 0;
                }
            }

            return(msg);
        }