groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] Get margin of a Postscript file


From: Ted Harding
Subject: Re: [Groff] Get margin of a Postscript file
Date: Sun, 09 Dec 2012 20:01:27 -0000 (GMT)

On 09-Dec-2012 16:48:31 Jérôme Frgacic wrote:
> On Sun, 09 Dec 2012 12:35:10 +0000, Ralph Corderoy wrote :
>> Ghostscript can report the bounding-box for the ink laid on each page.
> 
> Thanks for this trick, it works well for getting left and right margin. :)
> Nevertheless, I realized that there is an annoying problem for the top and
> bottom margin.  In fact, in MS Word, these margins do not apply to the
> header and the footer but only to the text (which, IMHO, is quite strange).
> So, I cannot get the top and bottom margin size from a PDF produce by MS
> Word...
> 
> On Sun, 09 Dec 2012 12:31:27 -0000, Ted Harding wrote :
>> And to Ralph's question I would add: Tell us exactly *what* you
>> want to know!
> 
> So, as you say, I want to know how far from the left-hand edge of the paper,
> and from the right-hand edge, the printing would normally extend and, for the
> top and the bottom, the same information but without taking into account the
> footer and the header (which, I think, is not possible).

If you convert the PDF into PS, then it is possible to parse the PS
(in principle it is in plain text) so as to locate the vertical position
of the first line of text on a page (which will be its "baseline"),
and that of the next line of text. The difference between these will be
the line spacing. All measurements are in points (possibly fractional).

Then you can locate the baseline of the bottom line of text.

The vertical position of the top line of text from the top of the page,
minus the line spacing, should be the top margin according to your
description.

For the bottom, you will however need to also take into account the
length of "descenders" (i.e. the dangly bits of letters like "g",
"p", "q" and "y"). The "baseline" is where the bottoms lof letters
like "z", "m2 etc. lie. I don't know how to obtain this from a file
produced by MS Word!

Nevertheless, this may help to get started. However, the parsing may
turn out to be complicated (especially with a file from MS Word ... ),
since there will be a lot of preliminary definitions of procedures,
and you would need to find the one which generates a move to a vertical
position to start a line.

Ted.

-------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 09-Dec-2012  Time: 20:01:24
This message was sent by XFMail
-------------------------------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]