function savefigpdf(fig, name, width, height)
% Saves figure fig in pdf file name.pdf with appropriately set page size
% and fonts

  % default width:
  if nargin < 3
      width = 11.7;
  end
  % default height:
  if nargin < 4
      height = 9.0;
  end

  % paper:
  set(fig, 'PaperUnits', 'centimeters');
  set(fig, 'PaperSize', [width height]);
  set(fig, 'PaperPosition', [0.0 0.0 width height]);
  set(fig, 'Color', 'white')

  % font:
  set(findall(fig, 'type', 'axes'), 'FontSize', 12)
  set(findall(fig, 'type', 'text'), 'FontSize', 12)

  % save:
  saveas(fig, name, 'pdf')

end