4
$\begingroup$

I have produced a lot of graphs and tables in my notebook. I am trying to save all these outputs as pdf file. As we know form Rodney and form Mr. Wizard , we can not use save as function. I have adobe acrobat PDF writer. When I use my PDF writer to print notebook, it cannot print.

I can delete all my input cells and leave outputs only. Then, I can go to file and select save as and save as type as my .pdf.

How can I save entire notebook that has only outputs without deleting input cells? (I have many figures and tables. Combining them while exporting should not change look of my tables and figures)

We can make one table and one graph for illustration purpose and export both at one time without affecting their format.

Any help is greatly appreciated. Thank you in advance.

$\endgroup$
7
  • $\begingroup$ Just the outputs, or the entire Notebook? $\endgroup$
    – Mr.Wizard
    Commented Jan 18, 2015 at 19:40
  • 1
    $\begingroup$ myFig = Plot[x^2, {x, 0, 1}]; Export[".../Desktop/myFig.pdf", myFig, "PDF"] but we cannot import pdf to StackExchange (just bmp and a few other formats). $\endgroup$ Commented Jan 18, 2015 at 19:42
  • 1
    $\begingroup$ @Mr. Wizard, I want just output. By the say, all figures and tables in one pdf file at one time. Thank you. $\endgroup$
    – ramesh
    Commented Jan 18, 2015 at 19:45
  • $\begingroup$ @ David, is it possible for you to answer this question? I have over 25 figures and over 10 tables. I want to export all in one file at one time. Please, address my concern if possible. Thank you. $\endgroup$
    – ramesh
    Commented Jan 18, 2015 at 19:49
  • 2
    $\begingroup$ You can select all output cells with NotebookFind[EvaluationNotebook[], "Output", All, CellStyle]; and then Save Selection As.... I hope someone remember how to do it fully automatically. $\endgroup$
    – ybeltukov
    Commented Jan 18, 2015 at 21:31

3 Answers 3

5
$\begingroup$

Edit

I was thinking about some automation of your request. With the the following approach you can create a new notebook, show your tables and graphs and save a new notebook as PDF.

SetDirectory@NotebookDirectory[];
some Code
...
some Code

List all global variables, see here:

names = Select[Names["Global`*"], Head@Symbol[#] =!= Symbol && Head@Symbol[#] =!= Function &]

(*
{"a0", "a1", "a2", "plo1", "plo2", "plo3", "plo4", "plo5", "plo6", "plo7", "tab1", "tf1"}
*)

You can then select the variables and reuse with ToExpression as Language input.

print = names[[4 ;; Length[names]]] // ToExpression // TableForm;

Use CreateDocument to open a document notebook and pass “print” as expression to that file.

nb = CreateDocument[print];

Then you can export the document created, as usual to PDF

Export["printPDF.pdf", %]

The result with my settings:

enter image description here


Say you have two notebooks open, one named Work.nb, the other Print.nb, on a fresh Kernel of course. With Work.nb you do all your graphs and tables. All required elements must have a unique variable name:

tab1 = Text[
  Grid[Table[
    With[{n = n}, 
     With[{u = HoldForm[\[Integral]1/(x^n - 1) \[DifferentialD]x]}, 
      TraditionalForm /@ {u, ReleaseHold[u]}]], {n, 4}], Frame -> All,
    ItemSize -> Automatic, Background -> LightYellow]]

enter image description here

    plo1 = Plot[{f[x], g[x]}, {x, -π, π}, Frame -> True, 
  FrameTicks -> {Range[-π, π, π/2], Automatic}]

enter image description here

plo2 = Plot[1/2 x^3 - 7 x + 4, {x, -5, 6}]

enter image description here

Because all kind variables are available in all open notebooks, you can also recall it in the notebook Print.nb. In the first line you can query the variables you need;

tab1
GraphicsGrid[{{plo1, plo2}}]
f[5] + f[π]
g[x + 1]
plo2

The result might look like this:

enter image description here

Done so, it will be easy to save Print.nb as PDF.

$\endgroup$
1
  • $\begingroup$ @ Lou, thank you for your time and answer. I am sorry for being so late to get back to you. $\endgroup$
    – ramesh
    Commented Jan 19, 2015 at 19:46
2
$\begingroup$

Based on my answer at Referencing cells after reopening a saved notebook, get a list of all output cell expressions with

outputs = ToExpression[#, StandardForm, Defer] & @@@ 
          (NotebookRead /@ Cells[CellStyle -> "Output"]);

then export via

Export["outputs.pdf", Column[outputs], "PDF"];
$\endgroup$
1
  • 2
    $\begingroup$ Instead of ToExpression (which can change the appearance of the contents and sometimes simply fails) you could simply Map RawBoxes: outputs = RawBoxes /@ NotebookRead /@ Cells[CellStyle -> "Output"]; Export["outputs.pdf", Column[outputs]];. $\endgroup$ Commented Jun 29, 2016 at 6:44
1
$\begingroup$
myFigs = Table[Plot[Sin[i x], {x, -2, 2}], {i, 6}];
myTables = 
  Table[Grid[
    RandomInteger[20, {RandomInteger[10], RandomInteger[10]}], 
    Frame -> All], {6}];
FinalFig = GraphicsGrid[Partition[Union[myFigs, myTables], 3]];
Export[".../Desktop/FinalFig.pdf", FinalFig, "PDF"];
$\endgroup$
3
  • $\begingroup$ @ David, thank you for taking time to answer this question. It helps me but it also leaves some of my concerns unanswered. For example, when I combined my figures and tables, outlook of figures and tables changes. If I could save entire notebook only with outputs, it would save my life. $\endgroup$
    – ramesh
    Commented Jan 18, 2015 at 20:37
  • 1
    $\begingroup$ Then use NotebookWrite[] around each figure and table, writing them to a single Notebook (thereby preserving the format of each). Then use SaveAs... pdf for that output notebook. $\endgroup$ Commented Jan 18, 2015 at 21:05
  • $\begingroup$ Thank you David for you suggestion. I will follow. $\endgroup$
    – ramesh
    Commented Jan 18, 2015 at 21:08

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.