/// <summary>
        /// Loads native Ghostscript library from the memory.
        /// </summary>
        /// <param name="buffer">Byte array.</param>
        public GhostscriptLibrary(byte[] gsDll)
        {
            if (gsDll == null)
            {
                throw new ArgumentNullException("gsDll", "Cannot be null.");
            }

            _library = new DynamicNativeLibrary(gsDll);
            _loadedFromMemory = true;

            this.Initialize();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the Ghostscript.NET.GhostscriptLibrary class
        /// from the native library represented as the memory buffer.
        /// </summary>
        /// <param name="library">Memory buffer representing native Ghostscript library.</param>
        public GhostscriptLibrary(byte[] library)
        {
            if (library == null)
            {
                throw new ArgumentNullException("library");
            }

            // check if library is compatibile with a running process
            if (Environment.Is64BitProcess != NativeLibraryHelper.Is64BitLibrary(library))
            {
                // throw friendly gsdll incompatibility message
                this.ThrowIncompatibileNativeGhostscriptLibraryException();
            }

            // create DynamicNativeLibrary instance from the memory buffer
            _library = new DynamicNativeLibrary(library);

            // set the flag that the library is loaded from the memory
            _loadedFromMemory = true;

            // get and map native library symbols
            this.Initialize();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Releases all resources used by the Ghostscript.NET.GhostscriptLibrary instance.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _library.Dispose(); 
                    _library = null;
                }

                _disposed = true;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the Ghostscript.NET.GhostscriptLibrary class
        /// from the GhostscriptVersionInfo object.
        /// </summary>
        /// <param name="version">GhostscriptVersionInfo instance that tells which Ghostscript library to use.</param>
        /// <param name="fromMemory">Tells if the Ghostscript should be loaded from the memory or directly from the disk.</param>
        public GhostscriptLibrary(GhostscriptVersionInfo version, bool fromMemory)
        {
            // check if Ghostscript version is specified
            if (version == null)
            {
                throw new ArgumentNullException("version");
            }

            // check if specified Ghostscript native library exist on the disk
            if (!File.Exists(version.DllPath))
            {
                throw new DllNotFoundException("Ghostscript native library could not be found.");
            }

            _version = version;
            _loadedFromMemory = fromMemory;

            // check if library is compatibile with a running process
            if (Environment.Is64BitProcess != NativeLibraryHelper.Is64BitLibrary(version.DllPath))
            {
                // throw friendly gsdll incompatibility message
                this.ThrowIncompatibileNativeGhostscriptLibraryException();
            }

            // check wether we need to load Ghostscript native library from the memory or a disk
            if (fromMemory)
            {
                // load native Ghostscript library into the memory
                byte[] buffer = File.ReadAllBytes(version.DllPath);

                // create DynamicNativeLibrary instance from the memory buffer
                _library = new DynamicNativeLibrary(buffer);
            }
            else
            {
                // create DynamicNativeLibrary instance from the local disk file
                _library = new DynamicNativeLibrary(version.DllPath);
            }

            // get and map native library symbols
            this.Initialize();
        }
        /// <summary>
        /// Loads native Ghostscript library from the GhostscriptVersionInfo.
        /// </summary>
        /// <param name="version">GhostscriptVersionInfo object.</param>
        /// <param name="fromMemory">Load Ghostscript from the memory or directly from a disk.</param>
        public GhostscriptLibrary(GhostscriptVersionInfo version, bool fromMemory)
        {
            if (version == null)
            {
                throw new ArgumentNullException("version", "Cannot be null.");
            }

            _version = version;
            _loadedFromMemory = fromMemory;

            if (fromMemory)
            {
                _library = new DynamicNativeLibrary(File.ReadAllBytes(version.DllPath));
            }
            else
            {
                _library = new DynamicNativeLibrary(version.DllPath);
            }

            this.Initialize();
        }