leonardorame
leonardorame

Reputation: 1161

Postscript to PDF scale to fit into A4

I need to create an A4 PDF file by fitting into page this 13.44x16.44 inches Postscript file. I thought ps2pdf could help me but I cannot get the desired effect.

I use this command to create the PDF:

ps2pdf -dFIXEDMEDIA -dPDFFitPage -sPAPERSIZE=a4 ori.postscript salida.pdf
Please note I used -dFIXEDMEDIA and -dPDFFitPage to force fit the Postscript file into the A4 paper size, but those apparently aren't working.

This is the original file:

Edit: Here's the original file

original Postscript file

And this is the resulting file. As you can see, the image isn't resized to fit, but just placed as is:

resulting PDF file

Upvotes: 0

Views: 2615

Answers (1)

KenS
KenS

Reputation: 31197

Firstly; the order of operands in Ghostscript is important, they are applied in the command line order. So you would want to apply the -sPAPERSIZE before you apply -dFIXEDMEDIA and both of those before you apply -dPDFFitPage.

I'd also suggest that you use Ghostscript directly rather than using the ps2pdf script.

If that still doesn't work for you, then you will need to provide an example file to show the problem, I can't tell you anything by looking at pictures.

You should also state the operating system and version of Ghostscript being used.

EDIT

The problem is that your PostScript program doesn't request a media size, it simply draws on whatever media happens to be available at the time. Some programs will rescale their content to fit whatever media is currently available, this isn't one of them. Anything which doesn't lie on the current media is allowed to be clipped off.

The 'FitPage' code relies on the PostScript program requesting a media size, which it then compares to the current (fixed) size. From that it works out how much to scale the content so that it fits into the new media.

If your program doesn't request a media size then there's no way for Ghostscript to know how much to scale it so it fits.

Now your program does have BoundingBox comments, but those are just comments, a PostScript consumer will ignore them. But you can use them.....

You can either modify the header of your PostScript program to pretend its an EPS instead of a PostScirpt program. :

Change

%!PS-Adobe-2.0

To

%!PS-Adobe-2.0 EPSF-3.0

and then use -dEPSFitPage instead of -dPDFFitPage then it will produce something like what (I think) you want. Note that PDFFitPage is for PDF input, so you shouldn't really be using it anyway. For PostScript input you want -dPSFitPage

Alternatively, read the BoundingBox comments and apply a media size request and origin translation yourself.

This command:

gs -sPAPERSIZE=a4 -dFIXEDMEDIA -dPSFitPage -sDEVICE=pdfwrite -sOutputFile=\temp\out.pdf -c "<</PageSize [968 1184]>> setpagedevice -20 -50 translate" -f d:\temp\ori.eps

Produces the same output as treating the file as EPS would.

Upvotes: 2

Related Questions