27

I have scanned some materials at 600 dpi, ~ 9.36x12.67 inches and prepared in PostScript (PS) format.

Now when I try to transform PS to PDF with Ghostscript (GS), I get clipped output, as I assume GS's default page size is set to A4. I found available templates for GS here: [updated] https://ghostscript.readthedocs.io/en/latest/Use.html#appendix-paper-sizes-known-to-ghostscript but none matches closely to dimensions of my PS files, so:

Can I instruct GS to output custom size, and if so how?

-sPAPERSIZE instruction seem to accept only predefined templates name, as in linked documentation.

K J
  • 8,045
  • 3
  • 14
  • 36
theta
  • 24,593
  • 37
  • 119
  • 159

4 Answers4

35

You can set the used page size with -gNNNNxMMMM where NNMN is the width in pixels at 720 dpi (720 pixels == 1 inch), and MMMM is the height in pixels at 720 dpi.

Or you can set the custom size in PostScript points (72 points == 1 inch) with -dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h.

If I'm not wrong, 9.36 inch ≈= 674 points and 12.67 inch ≈= 912 points.

You'll also have to apply -dPDFFitPage in order to fit your input onto the page.

So you could use either

gs                          \
   -o output.pdf            \
   -sDEVICE=pdfwrite        \
   -dDEVICEWIDTHPOINTS=674  \
   -dDEVICEHEIGHTPOINTS=912 \
   -dPDFFitPage             \
    input.ps

or

gs                   \
   -o output.pdf     \
   -sDEVICE=pdfwrite \
   -r600             \
   -g8112x7596       \
   -dPDFFitPage      \
    input.ps
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • I think you wanted to use `-r720` for 720 dpi. Thanks for your answer anyway – Dorian Mar 04 '14 at 18:23
  • I have an app that is using Ghostscriptsharp (C# implementation). It's just a .dll and doesn't have all the command line options (that I can find) for custom page sizes. Any idea on how to implement this in this wrapper? – Valien May 07 '14 at 21:00
  • rasterizer.CustomSwitches.Add("-dMySwitch"); – wbt11a Jan 06 '17 at 16:20
3

What worked for me:

gs -sDEVICE=pdfwrite -r720 -g4308x6066 -dPDFFitPage -o out.pdf in.pdf

The 4308x6066 is the number of pixels, the -r720 is the number of pixels per inch.

So here we have 720dpi, so for instance fo 5 inches, this will be 3600 pixels.

Dorian
  • 22,759
  • 8
  • 120
  • 116
3

I am using GhostPDL 9.10 and although my paper size of 8.5x13 is listed at https://ghostscript.readthedocs.io/en/latest/Use.html#appendix-paper-sizes-known-to-ghostscript as flsa the -sPAPERSIZE=flsa switch had no effect, the paper size remained Letter.

The correct units for the -g5100x7800 switch matched my -r600 (not 720); -g works.

Bruno Bronosky
  • 66,273
  • 12
  • 162
  • 149
user2584621
  • 2,305
  • 2
  • 15
  • 9
  • link is broken. fixed link: https://www.ghostscript.com/doc/current/Use.htm#Known_paper_sizes – Mugen Jan 23 '19 at 11:20
  • Thanks, this helped me with my problem. A ps-file as iso-A4 was converted to Letter, while the top margin appears shifted upwards. Using -sPAPERSIZE=a4, - thanks to the link, I get correct pdf format – Rob May 12 '22 at 12:25
2

I found that gs was clipping my output even though I had forced the page to the largest standard size, A0.

The reason turned out to be that the PostScript document sent to gs by groff / grops contained a %%DocumentMedia specification that was overriding Ghostscript's choice.

The solution was to give groff the command-line flag -p-P48i,48i. The -p tells groff to pass the rest of the option to grops. The -P48i,48i to grops sets the paper size to 48 inches by 48 inches.

Mark Dominus
  • 1,726
  • 12
  • 38