[gs-devel] Converting PDF to PS keeping native resolution
Ken Sharp
ken.sharp at artifex.com
Fri Apr 17 01:10:15 PDT 2009
Hi Thomas,
At 22:01 16/04/2009 -0400, you wrote:
>using gs directly). However, the PDF contains a low-resolution bitmap,
>and I would like the bitmap to keep the same resolution in the PS
>file. However, it seems that the default behaviour is for pdf2ps/gs to
>rasterize the bitmap to a specific resolution.
Actually the 'bitmap' is converted into a series of rectangular fills, one
rectangle per pixel.
In fact the PDF file not only contains an image, the image has a soft mask
as well, so this file involves transparency and is therefore considerably
more complex than you might think. The soft mask seems pointless, since it
appears to have all the values at 255.
See later regarding transparency.
>Is there any way to prevent this from happening? I want to be able to
>convert files which may have bitmaps of varying resolution to start
>with, so I am looking for a way to simply conserve the original
>resolution when converting to a PS file.
General observations
=====================
This is the way that pswrite works. Do you specifically need level 1
PostScript or DSC-compliant PostScript output ? If so then I'm afraid this
is the only way to go.
However, if you can accept non-DSC level 2 output, you could use the
ps2write device instead of the pswrite device. This is based on the
pdfwrite device and does a *much* better job of preserving the details of
the input. Pswrite often degenerates into lower level primitives, ps2write
does this much less often.
Currently (expanding the commands in pdf2ps) your command line looks more
or less like this:
gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pswrite -q -sOutputFile=$2 $1
If you instead use:
gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=ps2write -q -sOutputFile=$2 $1
The file comes out at 686Kb and contains image data.
Specific to this file
======================
Please note that, like the pswrite data, this output involves transparency
'flattening', that is conversion of transparent areas to an image, because
PostScript does not support transparency. This image is created at the
specified output resolution, it is important that you make sure this is
high enough for reasonable output on your printer if you intend to print
the PostScript. (use the -r switch to set the resolution).
Ghostscript has no choice in this, it cannot preserve the transparency
because there is no provision for it in the PostScript imaging model. It
does the best it can by converting the transparent area into an image, and
embedding that, which is adequate for printing provided you ensure a decent
resolution is selected during the conversion process.
This is why the output, at ~700Kb for me, is so much larger than the
original. Rather than containing the original low resolution image, and low
resolution soft mask, both stretched to cover the requisite area, the
combination has been converted to a much larger bitmap at a higher
effective resolution.
The original format of the data is lost though, and unrecoverable, so you
should only do this if you do not intend further conversion, for example
back to PDF.
I'm afraid your goal of preserving the original image is not possible with
this file, when converting to PostScript.
Ken
More information about the gs-devel
mailing list