[Top][All Lists]

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

[Groff] PDF_IMAGE and MOM

From: mikkel meinike
Subject: [Groff] PDF_IMAGE and MOM
Date: Sun, 2 Nov 2014 11:45:48 +0100

Now I have worked with .PDF_IMAGE and made me some experience and
understand a great deal. I love to share a bit with you. I believe it could
be useful to someone.

Bounding box
When you need to convert an image to PDF or EPS, there is very high
probability that the meta data about the image size as generated in the
process does not correspond to what you want.

In my case, I convert the image from PNM format (Portable Network Map the
image format used by Netpbm tool suite) a very simple image format without
any indication of the "printing size" of the image. This PNM-image was:

1866 x 1866 pixels

I use sam2p to convert PNM image to PDF (I can highly recommend the small
program sam2p). When I later try to find the image bounding box using this

gs -q -dBATCH -dNOPAUSE -sDEVICE=bbox <image file>.pdf 2>&1 \ | grep
"%%BoundingBox" | cut -d " " -f4,5

Could I see the image bounding box was set to:

1866 x 1866 points

This is too big. I want a picture with a resolution of 200 dpi, but here I
had a picture with a resolution of 72 dpi.
I wanted an image that was approximately 24 cm wide and thus fit into a A3
size paper. Now I instead got a picture which was about 67 cm wide and does
not fit into an A3 size and therefore there was no picture on my paper when
I try to insert it with PDF_IMAGE (.PDF_IMAGE image.pdf 1866p 1866p)

OK so I must supply the right bounding box my self.

There are 72 points to an inch and I want a resolution of 200 dpi so the
calculation would look like.

1866 / 200 * 72

I made a small script which can make the small calculation from measuring
the PNM-image and generate a PDF_IMAGE line and append it to a
mom-formatted document. The script uses Netpbm program suite and the small
CLI calculator tool bc

-------------- script ----------------
#The script is given a filename as arg. The file must be in PNM format
# and you give the full file name.

#Removes the file extension so I only have the base name

rose=`echo "$1" |sed 's/.pnm//'`

#To measured size of the image in pixels. I use Netpbm
# tool pamfile and then I use sed to isolate the
#numbers I need.

maal=`pamfile $1`
pixwidth=`echo -n $maal |sed 's/.*, //' |sed 's/ by .*//'`
pixheight=`echo -n $maal |sed 's/.*by //' |sed 's/ m.*//'`

# I ask bc to include two decimal places
# by using the command "scale = 2"

pointwidth=`echo "scale=2;$pixwidth/200*72" | bc`
pointheight=`echo "scale=2;$pixheight/200*72" | bc`
sam2p $1 $rose.pdf;
echo ".PDF_IMAGE $rose.pdf ${pointwidth}p ${pointheight}p" >>;

------------- End of script --------------
(The script can easily be ajusteted to work with other format than PNM it
is just a demo)

The script generated this line:

.PDF_IMAGE anittabw03.pdf 671.76p 671.76p

and with that line in my mom source code the picture was exactly as I
wanted it to be when I compiled it with:

pdfmom > pdffile.pdf

An other little thing I discovered was that.


In the head of mom code was not enough to give me the correct format into
the PDF. I could see it by opening the PDF file in a text viewer (less).

statement at the very top of the file did not have the right

When I wrote instead:

\ # Upright A3

in the source of the mom file and then compiled it was now the right
specifications in the PDF file's source code.

/MediaBox [0 0 842 1190 ]

I was a little bit of everything I have found out by working with mom and
PDF_IMAGE macro today and yesterday. Once I got things in place p find mom
and PDF_IMAGE to be really good tools so thanks to all of you involved with
making and maintaining it.


Attachment: ret1tmp.png
Description: PNG image

Description: Binary data

reply via email to

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