3

I want for example export a simple plot to a PDF file. The paper orientation should be portrait and the printing margings should have a certain value.

I tried the following:

p = Plot[Sin[x], {x, 0, 2 Pi}];

Export[StringJoin["Sin.pdf"], p, "PDF", 
  PrintingOptions -> {"PrintingMargins" -> {{300, 300}, {300, 300}}, 
                      "PaperOrientation" -> "Portrait"}];

but it gives me the follwing image of the PDF file which is not portrait and has no margins:

enter image description here

lio
  • 2,396
  • 13
  • 26
  • 2
    That's not how it works. There is no paper size. Plots are exported at their actual size. What size of paper you want to print this on later is not factored into the equation. Read this on how to export to a precise size. Check ImageMargins and ImagePadding to add extra space around the plot. Check the documentation for what units these options use. – Szabolcs Mar 22 '17 at 10:16
  • @Szabolcs: Thank you for this information. I am only surprised that I do not get any message after executing the upper Export command. – lio Mar 22 '17 at 10:22
  • Export is a bit weird. The allowed options are different for each format, and it does not always warn if some incorrect option names are given. It just ignores them. – Szabolcs Mar 22 '17 at 10:23
  • 2
    BTW when saving a notebook (not Graphics), there is a paper size. A starting point for a workaround could be Plot[Sin[x], {x, 0, 10}, ImageSize -> Full], then File -> Save As... and save the notebook as PDF. This could be automated. Notebooks (handles like the one returned by EvaluationNotebook[], or explicit Notebook expressions) can be exported to PDF with Export. In this case the page size matters. ImageSize -> Full makes the figure as wide as the available space. There would be more work to remove the cell labels, and I do not know how to centre vertically. – Szabolcs Mar 22 '17 at 10:49

1 Answers1

2

If you want to create a whole "page" pdf you can do like this:

p = Show[{Graphics[{FaceForm[White], EdgeForm[White], 
     Rectangle[{0, 0}, {612, 792}], Inset[Plot[Sin[x], {x, 0, Pi}]]}]}]
Export["Sin.pdf", p, "PDF", ImageSize -> {612, 792}];

Play with the options to inset to control the size/placement.

george2079
  • 38,913
  • 1
  • 43
  • 110