Quantcast
Channel: Ghostscript.NET
Viewing all articles
Browse latest Browse all 393

New Post: Send output to variable in place of file

$
0
0
Hi Albert,

You can achieve that by using pipes. Here is C# example:
using Ghostscript.NET.Processor;

namespace Ghostscript.NET.Samples
{
    /// <summary>
    /// Sample that demonstrates how to tell Ghostscript to write the output result to 
    /// an anonymous pipe (memory) instead of the writing it to the disk.
    /// </summary>
    public class PipedOutputSample : ISample
    {
        public void Start()
        {
            string inputFile = @"E:\__test_data\test2.pdf";

            GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();

            // pipe handle format: %handle%hexvalue
            string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");

            using (GhostscriptProcessor processor = new GhostscriptProcessor())
            {
                List<string> switches = new List<string>();
                switches.Add("-empty");
                switches.Add("-dQUIET");
                switches.Add("-dSAFER");
                switches.Add("-dBATCH");
                switches.Add("-dNOPAUSE");
                switches.Add("-dNOPROMPT");
                switches.Add("-sDEVICE=txtwrite");
                switches.Add("-o" + outputPipeHandle);
                switches.Add("-q");
                switches.Add("-f");
                switches.Add(inputFile);

                try
                {
                    processor.StartProcessing(switches.ToArray(), null);

                    byte[] rawDocumentData = gsPipedOutput.Data;

                    string txtOutput = System.Text.Encoding.UTF8.GetString(rawDocumentData);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    gsPipedOutput.Dispose();
                    gsPipedOutput = null;
                }
            }
        }
    }
}
I hope that helps.

Cheers,
Josip

Viewing all articles
Browse latest Browse all 393

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>