Printing and Graphics []

I would like to draw a rectangle (or more) that is printed on paper, shows the rectangle in units see. So

Graphics[{Rectangle[{0, 0}, {19, 28}], Orange, Rectangle[{0, 0}, {1, 1}]}] 

will be printed as two rectangles that can be measured exactly 1 cm x 1 cm (orange), and black - 19 x 28 cm.

It looks like some variables are important: ImageSize and, of course, AspectRatio .

I used AspectRatio->19/28 and for ImageSize various settings such as ImageSize->{19*27,28*27} , but it remains not very accurate.

I export the graphics to TIFF and then print using the photo gallery of windows to a full page. Does anyone have any experience? There should be a formula instead of trial and error.

UPDATE: I tried the @Szabolcs suggestion, and I used the following code:

  g = Graphics[{White, EdgeForm[Directive[Thick, Black]], Rectangle[{0, 0}, {18, 28}], Orange, Rectangle[{0, 0}, {10, 10}]}] final = Show[g, AspectRatio -> Automatic, PlotRange -> {{-0.5, 18.5}, {-0.5, 28.5}}] cm = 72/2.54 Export["final.pdf", Show[final, ImageSize -> {19 cm, 29 cm}]] 

This works great. 10x10cm orange rectangle when measured accurately 10x10cm

The value of cm 72 / 2.54 was not what I expected, since I, although Windows uses 96dpi and Mac 72dpi (read from www). However 72 is a value that works. I also played with frames, but then it gets ugly. They did not find a way to get the correct results in order to reproduce all possible settings. What should work creates frames / ticks, etc. Inside the chosen borders, but this is not the way I would like to pursue.

+7
source share
2 answers
 g = Graphics[{Rectangle[{0, 0}, {19, 28}], Orange, Rectangle[{0, 0}, {1, 1}]}] 

Ok, the first thing you need to do is set the x and y directions to use the same units, which means

 Show[g, AspectRatio -> Automatic] 

But this is already the default value.

The second thing you need to do is select the size and range for your site. Let it make it 21 by 30 with centered rectangles:

 plotArea = {{0, 21}, {0, 30}} - {1, 1} Show[g, AspectRatio -> Automatic, PlotRange -> plotArea] 

The third thing you need to do is disable the addition of add-ons / fields that make the actual size of your figure larger than your graph:

 final = Show[g, AspectRatio -> Automatic, PlotRange -> plotArea, PlotRangePadding -> 0, ImagePadding -> 0] 

I believe ImageMargins doesn't make any difference, but if so, set it also to 0.

The last thing you need to do is export it to a print format that saves the image size and set the image size so that 1 cm is 1 unit in your area. Mathematica takes the size of the images at the points of the printer, so let's define:

 cm = 72/2.54 Export["final.pdf", Show[final, ImageSize -> 21 cm]] 

We want the plot to have a width of 21 cm, since it has a width of 21 inches. Use PDF as an export format, not TIFF. ImageSize needs to be used inside Show to solve some problems with Export ...

Now open the PDF in Adobe Reader, open the print dialog and make sure Page Scaling is set to No! I don’t know how to do it in other readers ... Also make sure your figure fits the paper (21 by 30 cm is too big for A4 ...)

I'm not going to make a test print, so let me know if this works for you :-) The size of the generated PDF file is exactly 21 by 30 cm, so if something goes wrong, this should happen at the printing stage. A.

+8
source

I believe that you need to add PlotRangePadding -> None and set the image size accordingly.

In this case, the size of the bounding box is the same as your large rectangle: {19, 28}

A reliable way to do this is to set ImageSize to the actual required size and use ImageResolution , which will insert this value into the TIFF file for proper printing:

 cm = 72 / 2.54; g = Graphics[{Rectangle[{0, 0}, {19, 28}], Orange, Rectangle[{0, 0}, {1, 1}]}, PlotRangePadding -> None, ImageSize -> {19, 28}*cm]; Export["print.tif", g, ImageResolution -> 300] 

It is assumed that you want to print from a raster format (TIFF), but you can also export it to other formats, such as PDF, using the same method.

+4
source

All Articles