6
$\begingroup$

There is an Export syntax that lets you specify the elements being exported. This appears to be ignored by "PDF".

plots = Plot[#[x], {x, 0, 1}, ImageSize -> Large] & /@ {Sin, Cos, Tan};

To print each of plots to a PDF page the syntax is

SetDirectory[$UserDocumentsDirectory];
Export["plots.pdf", {"Pages" -> plots}, "Rules", "AllowRasterization" -> False]
ResetDirectory[];

However, the resulting PDF places the list (with curly braces) on one page of the PDF.

enter image description here

Any ideas how to get this to work? Mind you this is in version 10.4 on Win 7 Ent as version 11.1.0 always crashes if I try to Export PDF even after reinstalling.


Update: WRI has responded and said that "PDF" "Pages" Export is not currently supported. A similar workaround of creating a notebook with page break cells was provided.

$\endgroup$
  • $\begingroup$ "Pages" is an option for Import, non for Export You should look for printing environment styling If you wish to set the margins, paper size, etc for output document. $\endgroup$ – Rom38 May 16 '17 at 8:33
  • 1
    $\begingroup$ @Rom38 Look at the documentation for "XLSX" in the Elements section and notice how the "Sheets" element is documented. You can Export "Sheets" for Excel files. In "PDF" "Pages" is documented the same as "Sheets" in "XLSX". Therefore, it stands to reason that you should be able to Export "Pages". $\endgroup$ – Edmund May 16 '17 at 10:57
  • $\begingroup$ logic is absent sometimes in Wolfram documentation. $\endgroup$ – Rom38 May 16 '17 at 12:26
  • $\begingroup$ Related: (17008), (13251). $\endgroup$ – Alexey Popkov May 16 '17 at 15:46
  • $\begingroup$ @user6014 Export of "Sheets" is not undocumented. Read the documentation. $\endgroup$ – Edmund May 18 '17 at 18:34
10
$\begingroup$

You need something like this:

nb = CreateDocument[
   ExpressionCell[#, PageBreakBelow -> True] & /@ plots];
Export["plots.pdf", nb]

Therefore, you first create a structured document with page-breaks and then export (print) it to pdf.

$\endgroup$
  • $\begingroup$ This is a good workaround. (+1) $\endgroup$ – Edmund May 16 '17 at 10:53
  • 1
    $\begingroup$ Is there any way to break cells too? $\endgroup$ – H. R. Mar 9 '18 at 21:20
  • 1
    $\begingroup$ @H.R., I guess you should initially create cells with desired size (satisfying the good alignment regarding to current paper size) $\endgroup$ – Rom38 Mar 10 '18 at 22:44
  • $\begingroup$ Yeah, but that takes too much time for a long code. :) $\endgroup$ – H. R. Mar 11 '18 at 20:58
5
$\begingroup$

Turn off the popping up of the NB:

nb = CreateDocument[
   ExpressionCell[#, PageBreakBelow -> True] & /@ plots, Visible -> False];
Export["plots.pdf", nb]

After playing around a little bit it is clear that everything is already -magically- built inside CreateDocument (Mathematica 10.3). Just activate the right Options:

nb = CreateDocument[plots, PageBreakBelow -> True, Visible -> False];
Export["plots.pdf", nb]
$\endgroup$
  • $\begingroup$ (+1) Nice discovery of PageBreakBelow being supported by CreateDocument! It looks like we can pass in the same way any other Cell option too. $\endgroup$ – Alexey Popkov Dec 1 '17 at 20:38
  • $\begingroup$ e.g. TextAlignment -> Center is working. Also tried to pass a List with individual ailgnmnet for pages TextAlignment -> {Left,Left,Center,Right,...} this unfortunately does not work $\endgroup$ – Robert Nowak Dec 3 '17 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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