3
$\begingroup$

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

$\endgroup$
4
  • 2
    $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Mar 22, 2017 at 10:16
  • $\begingroup$ @Szabolcs: Thank you for this information. I am only surprised that I do not get any message after executing the upper Export command. $\endgroup$
    – lio
    Commented Mar 22, 2017 at 10:22
  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Mar 22, 2017 at 10:23
  • 2
    $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Mar 22, 2017 at 10:49

1 Answer 1

2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.