# Save figures as pdf

**URL:** https://discourse.julialang.org/t/save-figures-as-pdf/57503
**Category:** General Usage
**Tags:** visualization, input-output
**Created:** [March 18, 2021, 10:55pm UTC](https://discourse.julialang.org/t/save-figures-as-pdf/57503 "2021-03-18T22:55:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Rasoul\_Jafarzadeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rasoul_jafarzadeh/32/9967_2.png) [@Rasoul\_Jafarzadeh](https://discourse.julialang.org/u/Rasoul_Jafarzadeh)
#### Post date: [March 18, 2021, 10:55pm UTC](https://discourse.julialang.org/t/save-figures-as-pdf/57503/1 "2021-03-18T22:55:59Z")

</div>

In my code, I have lots of figuers and I want them to save as pdf. I did it but all plots saved in one page. How can I save them in some pages?

---

<div class="post-metadata">

### Author: ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)
#### Post date: [March 19, 2021, 3:40am UTC](https://discourse.julialang.org/t/save-figures-as-pdf/57503/2 "2021-03-19T03:40:21Z")

</div>

I currently do that with a for loop and FileIO. Don’t know if it’s the best way. This is how I do it:

```julia
using VegaLite
using FileIO

# create empty array that will hold graph names
gpharr = []

# create graphs
graph1 = ... 
push!(gpharr, :graph1)

graph2 = ... 
push!(gpharr, :graph2)

# save graphs
for g in gpharr
    save(File(format"PDF", joinpath("graphs", string(g)*".pdf")), eval(g))
    println(string(g))
end

```

I find that saving is the most time consuming part.

---

<div class="post-metadata">

### Author: ![JackDevine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackdevine/32/1048_2.png) [@JackDevine](https://discourse.julialang.org/u/JackDevine)
#### Post date: [March 19, 2021, 4:42am UTC](https://discourse.julialang.org/t/save-figures-as-pdf/57503/3 "2021-03-19T04:42:50Z")

</div>

If your goal is to just put all of the plots in a document and you don’t need the document to be a pdf, then an alternative is html.

The easiest way is to save your plots as either .svg or .png and use the img tag to include all of the plots into the document. The problem is that then if you email someone the document, the you will have to send them all of the images too. I have found two ways to inline the images into the html document.

One is to get the binary representation of the png images of your plots and put that into the img tags.

The other way is to just directly embed the plots into the document with the svg tag.

If you really need a pdf, then one possibility would be to use pgfplots. Basically, you save the plots as .pgf or .tex and use the `\include` macro in LaTeX to combine the plots into your document. I am happy to provide examples if you like.

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [March 19, 2021, 12:35pm UTC](https://discourse.julialang.org/t/save-figures-as-pdf/57503/4 "2021-03-19T12:35:29Z")

</div>

One solution is here:

[https://stackoverflow.com/questions/45018517/redirect-graphical-output-to-multi-page-pdf-in-julia](https://stackoverflow.com/questions/45018517/redirect-graphical-output-to-multi-page-pdf-in-julia)

It may matter whether you are using `Plots.jl` or some other plotting package.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 20, 2021, 7:33am UTC](https://discourse.julialang.org/t/save-figures-as-pdf/57503/5 "2021-03-20T07:33:02Z")

</div>

Welcome to the Julia community! Julia has quite a few plotting packages, so it would be useful to know which one you are using. Please provide an MWE

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …
