Ghostscript.NET.Viewer.GhostscriptViewer.Open C# (CSharp) Method

Open() private method

private Open ( ) : void
return void
        private void Open()
        {
            string extension = Path.GetExtension(_filePath).ToLower();

            if (!string.IsNullOrWhiteSpace(_filePath) && string.IsNullOrWhiteSpace(extension))
            {
                using (FileStream srm = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    extension = StreamHelper.GetStreamExtension(srm);
                }
            }

            switch (extension)
            {
                case ".pdf":
                    {
                        _formatHandler = new GhostscriptViewerPdfFormatHandler(this);
                        break;
                    }
                case ".ps":
                    {
                        _formatHandler = new GhostscriptViewerPsFormatHandler(this);
                        break;
                    }
                case ".eps":
                    {
                        _formatHandler = new GhostscriptViewerEpsFormatHandler(this);
                        break;
                    }
                default:
                    {
                        _formatHandler = new GhostscriptViewerDefaultFormatHandler(this);
                        break;
                    }
            }

            _interpreter.Setup(new GhostscriptViewerStdIOHandler(this, _formatHandler), new GhostscriptViewerDisplayHandler(this));

            List<string> args = new List<string>();
            args.Add("-gsnet");
            args.Add("-sDEVICE=display");

            if (Environment.Is64BitProcess)
            {
                args.Add("-sDisplayHandle=0");
            }
            else
            {
                args.Add("-dDisplayHandle=0");
            }

            args.Add("-dDisplayFormat=" +
                        ((int)DISPLAY_FORMAT_COLOR.DISPLAY_COLORS_RGB |
                        (int)DISPLAY_FORMAT_ALPHA.DISPLAY_ALPHA_NONE |
                        (int)DISPLAY_FORMAT_DEPTH.DISPLAY_DEPTH_8 |
                        (int)DISPLAY_FORMAT_ENDIAN.DISPLAY_LITTLEENDIAN |
                        (int)DISPLAY_FORMAT_FIRSTROW.DISPLAY_BOTTOMFIRST).ToString());



            args.Add("-dDOINTERPOLATE");
            args.Add("-dGridFitTT=0");

            // fixes bug: http://bugs.ghostscript.com/show_bug.cgi?id=695180
            if (_interpreter.LibraryRevision > 910)
            {
                args.Add("-dMaxBitmap=1g");
            }

            foreach(string customSwitch in _customSwitches)
            {
                args.Add(customSwitch);
            }

            _interpreter.InitArgs(args.ToArray());

            _formatHandler.Initialize();

            _formatHandler.Open(_filePath);

            if (_showPageAfterOpen)
            {
                this.ShowPage(_formatHandler.FirstPageNumber, true);
            }
        }

Same methods

GhostscriptViewer::Open ( GhostscriptVersionInfo versionInfo, bool dllFromMemory ) : void
GhostscriptViewer::Open ( Stream stream ) : void
GhostscriptViewer::Open ( Stream stream, GhostscriptVersionInfo versionInfo, bool dllFromMemory ) : void
GhostscriptViewer::Open ( Stream stream, byte library ) : void
GhostscriptViewer::Open ( byte library ) : void
GhostscriptViewer::Open ( string path ) : void
GhostscriptViewer::Open ( string path, GhostscriptVersionInfo versionInfo, bool dllFromMemory ) : void
GhostscriptViewer::Open ( string path, byte library ) : void

Usage Example

コード例 #1
0
        public void Start()
        {
            // there can be multiple Ghostscript versions installed on the system
            // and we can choose which one we will use. In this sample we will use
            // the last installed Ghostscript version. We can choose if we want to
            // use GPL or AFPL (commercial) version of the Ghostscript. By setting
            // the parameters below we told that we want to fetch the last version
            // of the GPL or AFPL Ghostscript and if both are available we prefer
            // to use GPL version.

            _lastInstalledVersion =
                GhostscriptVersionInfo.GetLastInstalledVersion(
                        GhostscriptLicense.GPL | GhostscriptLicense.AFPL,
                        GhostscriptLicense.GPL);

            // create a new instance of the viewer
            _viewer = new GhostscriptViewer();

            // set the display update interval to 10 times per second. This value
            // is milliseconds based and updating display every 100 milliseconds
            // is optimal value. The smaller value you set the rasterizing will
            // take longer as DisplayUpdate event will be raised more often.
            _viewer.ProgressiveUpdateInterval = 100;

            // attach three main viewer events
            _viewer.DisplaySize += new GhostscriptViewerViewEventHandler(_viewer_DisplaySize);
            _viewer.DisplayUpdate += new GhostscriptViewerViewEventHandler(_viewer_DisplayUpdate);
            _viewer.DisplayPage += new GhostscriptViewerViewEventHandler(_viewer_DisplayPage);

            // open PDF file using the last Ghostscript version. If you want to use
            // multiple viewers withing a single process then you need to pass 'true'
            // value as the last parameter of the method below in order to tell the
            // viewer to load Ghostscript from the memory and not from the disk.
            _viewer.Open("E:\test\test.pdf",_lastInstalledVersion, false);
        }
All Usage Examples Of Ghostscript.NET.Viewer.GhostscriptViewer::Open