Update: The problem is solved!
Apart from the three alternative resolutions 100%, 125% and 150% suggested on the right pane, there is the "Set custom text size (DPI)" item on the left pane:
When clicking on this item you get the following dialog:
Notice the "Use Windows XP style DPI scaling" checkbox - it is the key! But what it does? Citing this article (emphasis is mine),
Un-checking this checkbox causes Windows to use the desktop composition engine to perform DPI scaling for all applications that don’t explicitly mark themselves as DPI aware via manifest. In this case, the composition engine will use your graphics hardware to scale the bitmap output of the window to a larger size, and apply an input transform to any mouse-clicks on the window to route them back to the right place in "real coordinates" for the application. The OS will also virtualize the system DPI for that application, so that it thinks it is running at 96DPI. This applies to most traditional Win32, GDI based applications.
This checkbox is checked by default when you select resolution 100% or 125% on the right, but it is un-checked when you select resolution 150%. Moreover, if you manually check this checkbox for resolution 150%, it will be un-checked automatically! But it will be kept checked if you enter, for example, resolution 160% in the "Scale to this percentage of normal size" combo box of the second dialog. After changing the resolution you need to log off the user and log on the user again for the changes to take effect, and you'll see that the problem with Export
to EMF disappeared!
- A side note: according to the above citation, this checkbox shouldn't have effect on applications which correctly mark themselves as DPI aware via manifest. Therefore Mathematica version 11.0.1 either still isn't DPI aware or has a bug in how it marks itself as DPI aware...
So now we have at least a workaround. But what if you really need resolution exactly 150%? It is possible! By monitoring the system registry I've found that the "Use Windows XP style DPI scaling" checkbox in the second dialog corresponds to the "UseDpiScaling"
DWORD key in HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM
. The value 0
corresponds to the checkbox being checked, and the value 1
corresponds to the un-checked checkbox.
A word of warning: modifying the system registry is a potentially dangerous operation which may damage your system. It is recommended to backup important data before you proceed.
For changing the value of this key, open the Windows Registry Editor and select HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM
key on le left:
Double click on the "UseDpiScaling"
DWORD key on the right, enter 0
and press Enter. You'll see the following:
Now you need to log off the user and then log on the user again for the changes to take effect. Then check Export
to EMF: now generated EMF figure has no white borders when pasted in MS Word:
Voilà!
P.S. Related articles:
Original answer
I confirm this problem with Mathematica versions 5.2 (Export
as WMF because this version doesn't support EMF export), 8.0.4, 10.4.1 and 11.0.1 on Windows 7 x64 when the system-wide screen resolution is set to 150% on the OS level. I've checked all the ways to produce a metafile (Export
, Save Selection As…
, Save Graphic As…
, FrontEndTokenExecute[EvaluationNotebook[], "SelectionConvert", "Metafile"]
) and got identical results: exported metafile has 50% white margin added at the right and at the bottom. Changing FrontEnd option FontProperties -> {"ScreenResolution" -> 72}
doesn't affect this behavior. The problem doesn't appear when the system-wide screen resolution is set to 100% or 125%.
As a workaround I can suggest Export
ing your plot as SVG or PDF and then using third-party utility like Inkscape (command line solution) for converting it into EMF. Note also that most versions of MS Office support EPS, hence another workaround is to switch to EPS instead of EMF.
I have found that it is possible to cure the exported EMF file using free EMFexplorer utility, but this method works only when the system-wide screen resolution is set to 100% or 125%. This observation indicates that we have a bug not in Mathematica, but in Windows 7 itself. It would be interesting to find out whether the bug is present in other versions of Windows.
Here is the procedure:
Export
your EMF (system-wide screen resolution is set to 150%):
g = Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, PlotStyle -> Thickness /@ {0, .01}];
Export["i.emf", g]
When pasted in MS Word the EMF file has white borders:
On a computer with system-wide screen resolution 100% or 125% open the file in EMFexplorer, go to Document ► More Settings…
menu item, set zero margins, and save as EMF again using the File ► Save Page As…
menu item:
Now paste new EMF file in MS Word:
The figure has no margins!
Export
? $\endgroup$