CopyTo() public method

public CopyTo ( Stream result ) : void
result Stream
return void
Esempio n. 1
0
        /// <summary>
        /// Extracts text from the provided stream - stream must be readable
        /// </summary>
        /// <param name="pdfStream">Stream to extract to</param>
        /// <returns></returns>
        public Stream ExtractText(Stream pdfStream)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("Extractor");
            }

            if (pdfStream == null)
            {
                throw new ArgumentNullException("pdfStream");
            }

            if (!pdfStream.CanRead)
            {
                throw new ApplicationException("Stream not readable");
            }

            var result = new MemoryStream();

            using (var sourceFile = new TemporaryFile(pdfStream))
                using (var destinationFile = new TemporaryFile())
                {
                    var processStartInfo = new ProcessStartInfo(" \"" + _pdfToTextExecutable.Value.Info.FullName + " \"")
                    {
                        UseShellExecute        = false,
                        Arguments              = " \"" + sourceFile.Info + "\" \"" + destinationFile.Info + "\"",
                        WindowStyle            = ProcessWindowStyle.Maximized,
                        CreateNoWindow         = true,
                        LoadUserProfile        = false,
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true,
                        StandardOutputEncoding = Encoding.ASCII,
                    };


                    using (var process = Process.Start(processStartInfo))
                    {
                        process.ErrorDataReceived  += (sender, eventargs) => Log(eventargs.Data);
                        process.OutputDataReceived += (sender, eventargs) => Log(eventargs.Data);
                        process.BeginOutputReadLine();
                        process.WaitForExit();
                    }

                    destinationFile.CopyTo(result);
                }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts text from the provided stream - stream must be readable
        /// </summary>
        /// <param name="pdfStream">Stream to extract to</param>
        /// <returns></returns>
        public Stream ExtractText(Stream pdfStream)
        {
            if (_disposed)
                throw new ObjectDisposedException("Extractor");

            if (pdfStream == null)
                throw new ArgumentNullException("pdfStream");

            if (!pdfStream.CanRead)
                throw new ApplicationException("Stream not readable");

            var result = new MemoryStream();
            using (var sourceFile = new TemporaryFile(pdfStream))
            using (var destinationFile = new TemporaryFile())
            {
                var processStartInfo = new ProcessStartInfo(" \"" + _pdfToTextExecutable.Value.Info.FullName + " \"")
                {
                    UseShellExecute = false,
                    Arguments = " \"" + sourceFile.Info + "\" \"" + destinationFile.Info + "\"",
                    WindowStyle = ProcessWindowStyle.Maximized,
                    CreateNoWindow = true,
                    LoadUserProfile = false,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    StandardOutputEncoding = Encoding.ASCII,
                };

                using (var process = Process.Start(processStartInfo))
                {
                    process.ErrorDataReceived += (sender, eventargs) => Log(eventargs.Data);
                    process.OutputDataReceived += (sender, eventargs) => Log(eventargs.Data);
                    process.BeginOutputReadLine();
                    process.WaitForExit();
                }

                destinationFile.CopyTo(result);
            }
            return result;
        }