Re: Help in using gsapi_set_stdio() to capture stdout into a memory buffer

Chris Liddell <[email protected]>
Newsgroups gmane.comp.printing.ghostscript.devel
Message-ID <[email protected]>
On 16/03/16 01:13, Joaquim Luis wrote:
> Hi,
> 
> I am trying to learn how to capture the raster conversion of a PS file
> into memory but it's not being easy.
> The following example (adapted from one posted here before) correctly
> prints in stdout a png version of the small PS embedded in code. I know
> it's correct because I save it into a file I see it is. But my goal is
> to save it in a memory buffer so, as an intermediate step, I wanted to
> save it in file via gsapi_set_stdio.

This is *known* not to work and there is, in fact, a bug open to that
effect (with a summary of why it doesn't work):

http://bugs.ghostscript.com/show_bug.cgi?id=694993

The trouble is, without changing a fundamental assumption of the device
API, it's unlikely to be possible.

FWIW, your best solution would be to write your own device. If you are
not doing high resolution or large page work, you could look at using
the "display device".

Lastly, a possible workable solution would be to use a named pipe: pass
the named pipe to gs for output, and have your code read back from it -
depending on the amount of buffering Windows does on named pipes, you
might need to do some fiddling (maybe theads, maybe separate processes)
to read as data is being written.... if it were me, I'd spawn a separate
process for gs.

Chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.