This project is read-only.

GhostscriptRasterizer Open

May 28, 2014 at 4:43 PM

is there a special reason to use MemoryStream in the parameter of Open in the GhostscriptRasterizer class?

Because i need to call it with Stream. The only way to get a MemoryStream from a Stream is to copy it in memory.

I did a look at GhostscriptRasterizer (on github) and it passes the MemoryStream object to GhostscriptViewer Open method which uses Stream as Parameter. And then it gets written to a temporary file.

I think it would be better to use Stream instead of MemoryStream.

May 29, 2014 at 3:23 PM

Couple of months a go there was a request for MemorySteram support. One of the parameters in most of the 'Open' methods is a System.IO.Stream type which can accept any stream (FileStream, MemoryStream). Stream type is mostly there for the MemoryStream objects as Ghostscript.NET saves MemoryStream to a temporary file and pass the file path to the Ghostscript instance. If you have FileStream object, that means you made FileStream instance from some file path, in this case I would recommend you to use file path directly and not to pass FileStream as this way you will avoid saving a stream to the disk again as it already exists there. The reason for saving Streams to the disk is because Ghostscript needs a random access to the PDF file and if there is any way to pass PDF as byte array to the Ghostscript, Ghostscript will save that byte array to disk anyway. So, it's either Ghostscript.NET will create a file on the disk or native Ghostscript library will create a file on the disk.

The point is, for the input PDF files, Ghostscript.NET always pass file path to a native Ghostsript library. The output can be various (file, memory byte array). In case of memory output, Ghostscript.NET and native Ghostscript library really do their job in-memory, so there is no any track of any output file on the disk.