# Exporting dimensionally accurate images in PDF format with margins?

**URL:** <https://community.wolfram.com/t/exporting-dimensionally-accurate-images-in-pdf-format-with-margins/644>\
**Category:** Questions\
**Tags:** authoring-and-publishing, computer-science, engineering, image-processing, optics, computational-arts, units\
**Created:** [October 1, 2013, 8:58pm UTC](https://community.wolfram.com/t/exporting-dimensionally-accurate-images-in-pdf-format-with-margins/644 "2013-10-01T20:58:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![barnhart298](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/barnhart298/32/28791_2.png) [@barnhart298](https://community.wolfram.com/u/barnhart298)\
**Post date:** [October 1, 2013, 8:58pm UTC](https://community.wolfram.com/t/exporting-dimensionally-accurate-images-in-pdf-format-with-margins/644/1 "2013-10-01T20:58:24Z")

</div>

I need to generate a pdf image file that is dimensionally accurate for print-out into a hard copy. In addition, I need to accurately specify of the margins around the printed image. Here is an simple test example of a possible solution (that does not seem to work correctly):

```auto
SetDirectory[NotebookDirectory[]];

{xsize,ysize} = {7,9}; (*scale is in inches*)

{{left,right},{bottom,top}} = {{1/4.,8.5-xsize-1/4.},{1/2.,11-ysize-1/2.}}; (*scale is in inches*)

Export["TestPDFNotebook.pdf",
Rasterize[Graphics[Line[72*{{0,0},{0,ysize},{xsize,ysize},{xsize,0},{0,0}}]],
ImageSize->{xsize,ysize}*72], ImageSize->{xsize,ysize}*72, ImageMargins->Floor[72.*{{left,right},{bottom,top}}]] (*scale is now in printer points*)

```

Note that here I am using Export to generate a pdf file of a bitmapped image that is created with Rasterize. In addition, I am using the ImageSize option to specify the intended image size during printout. I am also using the ImageMargins options to specify margin widths. Both ImageSize and ImageMargins have units of printer points (72 pnts/inch). The intended paper size is 8.5 x 11 inches. The intended image size in this example is 7 inches x 9 inches. Unfortunately the image dimensions are completely lost during printout. Why is this happening? and more importantly, how to fix it?

---

<div class="post-metadata">

**Author:** ![cfrench](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/cfrench/32/27859_2.png) [@cfrench](https://community.wolfram.com/u/cfrench)\
**Post date:** [October 2, 2013, 1:03am UTC](https://community.wolfram.com/t/exporting-dimensionally-accurate-images-in-pdf-format-with-margins/644/2 "2013-10-02T01:03:51Z")

</div>

I tried your example code out both with ImageMargins option for Export and with ImageMargins as an option for Graphics and seem to be getting the same thing that you describe. When round-trip testing using ImportString[ExportString it seems to work.

```auto
ImportString[ExportString[
  Rasterize[
   Graphics[
    Line[72*{{0, 0}, {0, ysize}, {xsize, ysize}, {xsize, 0}, {0, 0}}],
     ImageMargins -> {{left, right}, {bottom, top}}],
   ImageSize -> xsize*72],
  "PDF"]]

```

Either location ImageMargins is used, the resulting TestPDFNotebook.pdf created by Export seems to be made without custom set margins. I am using M- version 9.0.1 for Windows 7.
