Message Boards Message Boards

Exporting dimensionally accurate images in PDF format with margins?

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):
 
 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?
POSTED BY: Donald Barnhart
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.
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.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract