Exemplo n.º 1
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);
                    }
                }
            }
        }
Exemplo n.º 2
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);
                    }
                }
            }
        }
            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);
            }
Exemplo n.º 4
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));
        }
        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);
        }