How to convert a PDF file to letter size using groff?

162 Views Asked by At

I am trying to convert a text file in groff format to PDF, using the following command:

groff -Tps -dpaper=letter -P-letter -P-l -ms foo.ms | ps2pdf - output.pdf

The command works fine and outputs me a PDF file, but the paper size is "a4". I would like to change the paper size to "letter", which is the paper size I need for my document.

I've tried changing the "-dpaper" option to "letter" but that doesn't seem to have any effect on the paper size of the resulting PDF file. I have also tried changing the "-P-letter" option to "-P-usletter", but that hasn't worked either.

Is there a way to specify the paper size as "letter" when converting a groff file to PDF using groff and ps2pdf? Or are there any other steps I need to take to achieve this?

2

There are 2 best solutions below

0
Ljm Dullaart On

groff seems to work just fine:

$ groff -Tps -dpaper=a4 -P-pa4  -ms tst.ms > tst.ps
$ grep 'PageSize' tst.ps
%%BeginFeature: *PageSize Default
<< /PageSize [ 595 842 ] /ImagingBBox null >> setpagedevice
$ groff -Tps -dpaper=letter -P-pletter  -ms tst.ms > tst.ps
$ grep 'PageSize' tst.ps
%%BeginFeature: *PageSize Default
<< /PageSize [ 612 792 ] /ImagingBBox null >> setpagedevice
 

The ps2pdf may cause the problems here. There are multiple versions of ps2pdf, some require a -sPAPERSIZE=letter (the mictex version for example).

0
tavo-wasd On

For people looking to make a groff document US-letter sized, with custom margins, I use this snippet of code:

.\" US letter dimensions
.device papersize=8.5i,11i
.
.\" Calculate line length with PO
.if (\\n[PO] == 0) \{\
.   \" If PO not defined, set to 1i
.   nr PO 1i
.\}
.
.\" Define line and header/footer
.\" lengh as such
.nr LL \\n[PO]*-2+8.5i
.nr LT \\n[PO]*-2+8.5i

Just add it to the top of your document. Note that it will automatically use 1i margins, but you can set the PO variable after pasting this snippet, for example, change it to .nr PO 1.5i and it will center the text for you using 1.5i left and right margins.

For more control, just keep the .device papersize=8.5i,11i option and adjust PO, LL and LT values manually. man groff_ms has more info about these registers.