コード例 #1
0
ファイル: MainForm.cs プロジェクト: sakpung/webstudy
        private void Init()
        {
            _viewer             = new Viewer();
            _viewer.Dock        = DockStyle.Fill;
            _viewer.BackColor   = Color.Bisque;
            _viewer.BorderStyle = BorderStyle.Fixed3D;
            Controls.Add(_viewer);
            _viewer.BringToFront();
            _viewer.MouseMove += new MouseEventHandler(_viewer_MouseMove);
            _viewer.UseDpi     = true;
            _selectTextToolStripMenuItem.Checked = true;

            _loadSvgOptions = new CodecsLoadSvgOptions();

            try
            {
                if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
                {
                    _printDocument             = new PrintDocument();
                    _printDocument.BeginPrint += new PrintEventHandler(_printDocument_BeginPrint);
                    _printDocument.PrintPage  += new PrintPageEventHandler(_printDocument_PrintPage);
                    _printDocument.EndPrint   += new PrintEventHandler(_printDocument_EndPrint);
                }
                else
                {
                    _printDocument = null;
                }
            }
            catch (Exception)
            {
                _printDocument = null;
            }

            InitPan();
            UpdateControls();
            string defaultFile =
#if LT_CLICKONCE
                Path.Combine(Application.StartupPath, @"documents\Leadtools.pdf");
#else
                Path.Combine(DemosGlobal.ImagesFolder, "Leadtools.pdf");
#endif // #if LT_CLICKONCE

            if (File.Exists(defaultFile))
            {
                LoadDocument(defaultFile, true);
            }
        }
コード例 #2
0
ファイル: BaseController.cs プロジェクト: sakpung/webstudy
        /// <summary>
        /// Method to ensure that a files that is sent to the service is valid
        /// </summary>
        internal void ValidateFile(Stream s, ref int lastPage)
        {
            try
            {
                using (var codecs = new RasterCodecs())
                    using (var info = codecs.GetInformation(s, true))
                    {
                        //Now that we have the actual file information, we can verify the properties of the file itself.  We will sanitize the lastPage parameter of the request to make sure that it pointing to a valid location within the file.
                        if (lastPage == -1 || lastPage > info.TotalPages)
                        {
                            lastPage = info.TotalPages;
                        }

                        //Check to determine whether or not a file is raster-based, or if it is a document/vector file.  If it is a document/vector file, we can check and see if it is a format that is supposed by calling codecs.LoadSvg
                        if (info.Document.IsDocumentFile || info.Vector.IsVectorFile)
                        {
                            var options = new CodecsLoadSvgOptions {
                                MaximumElements = DemoConfiguration.MaxSvgElements
                            };
                            using (var svg = codecs.LoadSvg(s, 1, options))
                                if (svg == null)
                                {
                                    throw new RejectedFileException();
                                }
                        }
                    }
            }
            //If the file format is not supported by the LEADTOOLS SDK, or if it isn't possible to pull info from the file (such as the case with txt files), the RasterCodecs.GetInformation call will fail.  This will cause the SDK to throw a RasterException -- which we can catch, and then reject the file.
            catch (RasterException)
            {
                throw new RejectedFileException();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        private static LEADDocument AddDocumentToCache(LEADDocument largestDocument, IOcrEngine ocrEngine, Uri documentUri, LoadDocumentOptions loadOptions, DocumentCacheOptions cacheOptions)
        {
            // Adds the document to the cache. Note that a new cache entry is created for each different maximumImagePixelSize.

            var document = DocumentFactory.LoadFromUri(documentUri, loadOptions);

            try
            {
                if (document == null)
                {
                    throw new InvalidOperationException("Failed to load URI: " + documentUri);
                }

                // We will modify this document...
                bool wasReadOnly = document.IsReadOnly;
                document.IsReadOnly = false;

                if (document.Text.TextExtractionMode != DocumentTextExtractionMode.OcrOnly && !document.Images.IsSvgSupported && ocrEngine != null)
                {
                    document.Text.OcrEngine = ocrEngine;
                }

                // Set in the cache options that we want
                document.CacheOptions = cacheOptions;

                // prepare the document, caching as much as possible.
                if (document.IsStructureSupported && !document.Structure.IsParsed)
                {
                    document.Structure.Parse();
                }

                // Need to cache the SVG with and without getting the back image
                var loadSvgOptions = new CodecsLoadSvgOptions();

                foreach (var page in document.Pages)
                {
                    // If we have a previous largest document, use the same
                    // SVG and text instead of recreating them (they do not change based on image size)
                    DocumentPage largestDocumentPage = null;

                    if (largestDocument != null)
                    {
                        largestDocumentPage = largestDocument.Pages[page.PageNumber - 1];
                    }

                    if (cacheOptions == DocumentCacheOptions.None)
                    {
                        // We are done, do not cache the images, svg or text
                        continue;
                    }

                    if ((cacheOptions & DocumentCacheOptions.PageSvg) == DocumentCacheOptions.PageSvg)
                    {
                        // SVG, this does not depend on the image size
                        using (var svg = page.GetSvg(null))
                        {
                        }

                        using (var svg = page.GetSvg(loadSvgOptions))
                        {
                        }
                    }

                    if ((cacheOptions & DocumentCacheOptions.PageSvgBackImage) == DocumentCacheOptions.PageSvgBackImage)
                    {
                        // SVG back image, this is different based on the image size
                        using (var svgBack = page.GetSvgBackImage(RasterColor.FromKnownColor(RasterKnownColor.White)))
                        {
                        }
                    }

                    if ((cacheOptions & DocumentCacheOptions.PageImage) == DocumentCacheOptions.PageImage)
                    {
                        // Image, this is different based on the image size
                        using (var image = page.GetImage())
                        {
                        }
                    }

                    if ((cacheOptions & DocumentCacheOptions.PageThumbnailImage) == DocumentCacheOptions.PageThumbnailImage)
                    {
                        // Thumbnail, this does not depend on the image size but there is no set thumbnail method
                        using (var thumbnailImage = page.GetThumbnailImage())
                        {
                        }
                    }

                    if ((cacheOptions & DocumentCacheOptions.PageText) == DocumentCacheOptions.PageText)
                    {
                        // Text, this does not depend on the image size
                        if (largestDocumentPage == null)
                        {
                            page.GetText();
                        }
                        else
                        {
                            var pageText = largestDocumentPage.GetText();
                            page.SetText(pageText);
                        }
                    }
                }

                document.AutoDeleteFromCache  = false;
                document.AutoDisposeDocuments = true;
                document.AutoSaveToCache      = false;
                // Stop caching
                document.CacheOptions = DocumentCacheOptions.None;
                document.IsReadOnly   = wasReadOnly;

                // save it to the regular cache
                document.SaveToCache();

                return(document);
            }
            catch (Exception)
            {
                if (document != null)
                {
                    document.Dispose();
                }
                throw;
            }
        }
コード例 #4
0
        public HttpResponseMessage GetSvg([FromUri] GetSvgRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            int pageNumber = request.PageNumber;

            if (string.IsNullOrEmpty(request.DocumentId))
            {
                throw new ArgumentException("documentId must not be null");
            }

            if (pageNumber < 0)
            {
                throw new ArgumentException("'pageNumber' must be a value greater than or equals to 0");
            }

            // Default is page 1
            if (pageNumber == 0)
            {
                pageNumber = 1;
            }

            // Now load the document
            var cache = ServiceHelper.Cache;

            using (var document = DocumentFactory.LoadFromCache(cache, request.DocumentId))
            {
                DocumentHelper.CheckLoadFromCache(document);
                DocumentHelper.CheckPageNumber(document, pageNumber);

                document.Images.UnembedSvgImages = request.UnembedImages;

                var documentPage = document.Pages[pageNumber - 1];
                var loadOptions  = new CodecsLoadSvgOptions();
                loadOptions.ForceTextPath          = (request.Options & DocumentGetSvgOptions.ForceTextPath) == DocumentGetSvgOptions.ForceTextPath;
                loadOptions.ForceRealText          = (request.Options & DocumentGetSvgOptions.ForceRealText) == DocumentGetSvgOptions.ForceRealText;
                loadOptions.DropImages             = (request.Options & DocumentGetSvgOptions.DropImages) == DocumentGetSvgOptions.DropImages;
                loadOptions.DropShapes             = (request.Options & DocumentGetSvgOptions.DropShapes) == DocumentGetSvgOptions.DropShapes;
                loadOptions.DropText               = (request.Options & DocumentGetSvgOptions.DropText) == DocumentGetSvgOptions.DropText;
                loadOptions.ForConversion          = (request.Options & DocumentGetSvgOptions.ForConversion) == DocumentGetSvgOptions.ForConversion;
                loadOptions.IgnoreXmlParsingErrors = (request.Options & DocumentGetSvgOptions.IgnoreXmlParsingErrors) == DocumentGetSvgOptions.IgnoreXmlParsingErrors;

                using (var svgDocument = documentPage.GetSvg(loadOptions))
                {
                    if (svgDocument != null)
                    {
                        if (!svgDocument.IsFlat)
                        {
                            svgDocument.Flat(null);
                        }

                        if (!svgDocument.IsRenderOptimized)
                        {
                            svgDocument.BeginRenderOptimize();
                        }

                        var svgBounds = svgDocument.Bounds;
                        if (!svgBounds.IsValid)
                        {
                            svgDocument.CalculateBounds(false);
                        }
                    }

                    if (svgDocument != null)
                    {
                        var gzip   = ServiceHelper.GetSettingBoolean(ServiceHelper.Key_Svg_GZip);
                        var stream = ToStream(svgDocument, gzip);

                        // HttpContext is Web Api's version of WebOperationContext
                        //var currentContext = WebOperationContext.Current;
                        var currentContext = HttpContext.Current;
                        if (currentContext != null)
                        {
                            if (gzip)
                            {
                                currentContext.Response.Headers.Add("Content-Encoding", "gzip");
                            }

                            currentContext.Response.ContentType = "image/svg+xml";
                            currentContext.Response.Headers.Add("ContentLength", stream.Length.ToString());
                        }

                        // If we just return the stream, Web Api will try to serialize it.
                        // If the return type is "HttpResponseMessage" it will not serialize
                        // and you can set the content as you wish.
                        var response = new HttpResponseMessage();
                        response.Content = new StreamContent(stream);
                        ServiceHelper.UpdateCacheSettings(response);
                        return(response);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
コード例 #5
0
ファイル: PropertiesDialog.cs プロジェクト: sakpung/webstudy
 public void UpdateCodecsLoadSvgOptions(CodecsLoadSvgOptions options)
 {
     options.DropImages = DropImages;
     options.DropShapes = DropShapes;
     options.DropText   = DropText;
 }
コード例 #6
0
ファイル: PropertiesDialog.cs プロジェクト: sakpung/webstudy
 public LoadSvgProperties(CodecsLoadSvgOptions options)
 {
     DropImages = options.DropImages;
     DropShapes = options.DropShapes;
     DropText   = options.DropText;
 }