[gs-devel] Can Ghostscript stream PDF?

Ken Sharp ken.sharp at artifex.com
Wed Jun 2 08:34:49 UTC 2021


At 08:54 02/06/2021, Till Kamppeter wrote:

>As Ghostscript does not take Raster as input I have to encapsulate my 
>Raster data in a format which Ghostscript understands as input format. 
>That is either PostScript or PDF.

GhostPDL, however, does accept several raster formats, and since it uses 
the Ghostscript graphics library it therefore supports the legacy devices.


>Now I have heard about approaches of streamable PDF, a sub-set of PDF, 
>PDFs written in a special way so that one does not need to read the file 
>up to its end to be able to print the first page.
>
>Examples are PDF/is
>
>https://ftp.pwg.org/pub/pwg/candidates/cs-ifxpdfis10-20040315-5102.3.pdf

A *candidate* standard since 2004, not (as far as I can see) adopted by ISO 
and not exactly widely used. To the extent that I've never actually 
encountered one.

Only supports up to PDF 1.4 and has never been updated. I'd regard this as 
obselete.

And you can't tell if the file conforms to this standard until you've 
already read a chunk of it. You have to rely on the PDF/is dictionary 
existing in the first buffer of data you receive.


>and also PCLm. PCLm is a raster-only sub-set of PDF

Not exactly, I don't recall the details offhand but it's a not-quite-PDF 
format that we can handle by pretending it is PDF. We have an output device 
that produces it.

Its also not a public standard. I realise that the format is (sort of) 
documented on the web, obviously since we've got a device to write it, but 
there is no freely available standard.

Again you have to rely on the PCLm magic number appearing in the first 
buffer of data in order to recognise it as such, though I concede this is 
much more likely to be the case with the simple format of PCLm as opposed 
to PDF/is.


The problem with any format which 'looks like' a PDF file, is that we're 
going to treat it as a PDF file, because someone might have (for example) 
edited it. Once it's been edited then it may no longer conform to the 
subset standard, but *does* conform to the PDF standard. If we try to treat 
it as the subset, we'll get the answer wrong.

You can argue that the PDF editor should realise that this is a 'special 
case' and remove the subset standard identifiers, but frankly that's just 
not reliable.

Also you can argue that in *your* case you always know that the file is of 
the required standard, but Ghostscript itself cannot rely on that, it is 
(as you know) used very widely in other applications.


>Now my questions are:
>
>1. Is Ghostscript able to stream PDF/is or PCLm input? Or has it to read 
>the whole file as it was a "normal" PDF?

*Ghostscript* will always read something identified as a PDF file as a PDF 
file.


>2. If I want to print Raster data with a legacy driver built into 
>Ghostscript, is there any advantage for me (like color management, color 
>reproduction quality) to convert the Raster data into PDF and not into 
>PostScript?

You might be able to get a smaller PDF file than a PostScript file, you 
might (theoretically) be able to do a more accurate colour matching, or at 
least match more easily, because PDF supports ICC profiles, which 
PostScript doesn't. I doubt either of these are of any great importance.


>I have no problem to send the data as PostScript as it is much easier in 
>terms of coding (the code is already in the PostScript Printer 
>Application) and for legacy printer support most important is that it 
>works at all instead of that it works in perfect color, I only want to 
>know whether I do not miss anything important when feeding in the data via 
>PostScript instead of via PDF.

For the specific case of sending image data to a printer, no I can't see 
any reason to use PDF instead of PostScript.


>And if I stream in the Raster data as PostScript, how do I embed color 
>space/profile metadata

Well it won't be metadata once its in the PostScript program, it'll be real 
actual data that has an effect on the rendered output.

Simply put; you will need to set up the colour space correctly before you 
execute the image operator.

In the general case you can't use an ICC profile, you'll have to convert it 
into something else (presumably a CIEBased colour space) because PostScript 
doesn't support ICC profiles.

For the special case of creating PostScript to use only with Ghostscript 
you could turn the ICC profile into an ICCBased space, because Ghostscript 
has support for ICCBased spaces in PostScript (it needs to for PDF input, 
currently). Offfhand I don't know how to do that, but it's certainly 
possible. This would, obviously, preclude using any other PostScript 
interpreter to consume the PostScript, I've no idea if this is a problem.


>in the PostScript or what command line options I should add to the 
>GhostScript command line to get best color fidelity?

If you get the colour specification correct on the input PostScript which 
you create, then you can use the Ghostscript colour management tools.

There is quite a bit of documentation surrounding this already available, 
and I know you've spoken with Michael Vrhel recently. If you have specific 
questions I suggest you contact Michael directly (I've CC'ed him on this 
reply).


                     Ken



More information about the gs-devel mailing list