# Viewer for PDF images

**URL:** <https://discourse.julialang.org/t/viewer-for-pdf-images/95668>\
**Category:** General Usage\
**Tags:** question, images, cairomakie-plotting\
**Created:** [March 7, 2023, 1:47pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668 "2023-03-07T13:47:43Z")\
**Posts on this page:** 15\
**Page:** 2

<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 10, 2023, 1:59pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/21 "2023-03-10T13:59:44Z")

</div>

Yes, I did - before I actually tried it (not realizing that not all the tools run on my M1 mac).

For the record, what I ended up with (so far) is:

- Convert pdfs to pngs using ghostscript (always available on the mac). A step that I would like to avoid.
- Write a simple html file with `img` tags and open it in a web browser.

But (given that I am already converting to png) I might try the Makie based solution that you are suggesting.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 10, 2023, 2:01pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/22 "2023-03-10T14:01:17Z")

</div>

In case you did not know, you can always run the intel / rosetta version of Julia if you need a tool that doesn’t exist for ARM.

---

<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 10, 2023, 2:03pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/23 "2023-03-10T14:03:38Z")

</div>

That’s probably not a price I am willing to pay for improving my figure comparisons. But thanks.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [March 10, 2023, 2:12pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/24 "2023-03-10T14:12:08Z")

</div>

But why do you produce figs in pdf in first place if you later need them in another format? Why no create them directly in, say, png?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 10, 2023, 3:04pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/25 "2023-03-10T15:04:25Z")

</div>

With juliaup you could in principle easily have both of them and call one as `julia +1.9~x64` for example. So it’s not that big a price 😉

---

<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 10, 2023, 3:06pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/26 "2023-03-10T15:06:38Z")

</div>

Mainly the vector graphics behave better in slides and typeset papers. I tried SVG as a middle ground but ran into trouble with typesetting the paper. Probably fixable with some effort.

---

<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 10, 2023, 3:10pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/27 "2023-03-10T15:10:43Z")

</div>

That’s true. What I don’t know is whether the Intel Julia packages under the hood call tools that won’t run on the M1 (such as imagemagick). Worth a try.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [March 10, 2023, 3:18pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/28 "2023-03-10T15:18:38Z")

</div>

I know that but here you are having a specific _raster_ needs.  
GMT produces **only** postscript (vector graphics) but under hood we convert to more common formats (PDF by default or any other that ghostscript can convert). The CI testing system uses `ImageMagic` (and it works on M’s too) to take a _ground true_ ps and compare it to the tested one. To do it IM converts from PS to PNG and shows (and counts the amount of differences) those differences as pink pixels. Maybe you can use this idea for your comparisons.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 10, 2023, 3:18pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/29 "2023-03-10T15:18:48Z")

</div>

So far I’ve never had the case that the Intel version didn’t run, only ARM versions. Mostly tectonic which I remember now but a couple others as well. Might be worth a try. Supposedly it’s a bit slower, but for me that has not mattered, yet.

---

<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 10, 2023, 3:29pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/30 "2023-03-10T15:29:16Z")

</div>

That is good to know. I will give it a try. Thanks again.

---

<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 10, 2023, 3:36pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/31 "2023-03-10T15:36:32Z")

</div>

So you are saying I should give ImageMagick another try - it should work on the M1 mac? (Sorry if I misunderstand you suggestion; I am not sure what GMT refers to).

So far I am getting the `libwand not defined` error with ImageMagick.  
If I cannot resolve it, @jules 's suggestion of running Intel Julia may be the solution.

Thanks again.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [March 10, 2023, 8:53pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/32 "2023-03-10T20:53:43Z")

</div>

I thought [QuartzImageIO.jl](https://github.com/JuliaIO/QuartzImageIO.jl) should work on my Mac Mini M1.

However

```julia
julia> using QuartzImageIO
julia> img = QuartzImageIO.load(pdf_path)

┌ Warning: QuartzImageIO found empty colormodel string
└ @ QuartzImageIO ~/.julia/packages/QuartzImageIO/4Fkqk/src/QuartzImageIO.jl:83
julia> typeof(img)
Nothing

```

And in case I have loaded `Images.jl` before, `ImageMagick` will be used anyway and throw an error.

Independent of the OP problem, it is desirable to have some way to open PDFs as images on Arm Macs. Any ideas?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 11, 2023, 11:59am UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/33 "2023-03-11T11:59:35Z")

</div>

Looks like poppler and cairo can work together on this, it could be really handy for CairoMakie to have an option to insert pdf files into figures (they would remain vector graphics which is desirable).

[https://www.cairographics.org/cookbook/renderpdf/](https://www.cairographics.org/cookbook/renderpdf/)

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [March 11, 2023, 4:49pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/34 "2023-03-11T16:49:01Z")

</div>

First, I don’t want that this looks like a competition but GMT already has a mechanism to do this **IF** original figures are created in postscript (like those in GMT are). The [image](https://www.generic-mapping-tools.org/GMTjl_doc/documentation/modules/image/index.html#image) module lets do mosaics of _eps_ and raster formats.

Example

```julia
using GMT

x = linspace(-2pi,2pi);
plot(x, sin.(x), figname="sin.eps")
plot(x, cos.(x), figname="cos.eps")
image("sin.eps", pos=(paper=true, anchor=(0,0), width=8))
image!("cos.eps", pos=(paper=true, anchor=(8.5, 0), width=8), show=true)

```

The end result may be a PDF or a raster format.

 ![GMTjl_tmp](https://global.discourse-cdn.com/julialang/original/3X/b/e/be4fdfb46ad4beda828d0a68a326e6a8306c3d6f.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 12, 2023, 4:47pm UTC](https://discourse.julialang.org/t/viewer-for-pdf-images/95668/35 "2023-03-12T16:47:32Z")

</div>

I’ve made a prototype work (without error checking or resource freeing) and with that one can freely plot existing PDFs into CairoMakie `Figures`. Whoever is motivated could turn that easily into a small CairoMakie extension package:

> <https://gist.github.com/jkrumbiegel/e6b998e1a0660dd550ce436beee67f2d>

The usage part looks like this:

```julia
f = lines(cumsum(randn(100)), color = :red; figure = (resolution = (400, 300)))
CairoMakie.save("f1.pdf", f)
f = lines(cumsum(randn(100)), color = :blue; figure = (resolution = (400, 300)))
CairoMakie.save("f2.pdf", f)

##

f = Figure(resolution = (600, 800))
pdf!(f.scene, path = "f1.pdf", bbox = (BBox(0, 600, 400, 800)))
pdf!(f.scene, path = "f2.pdf", bbox = (BBox(0, 600, 0, 400)))
CairoMakie.save("f1_f2.pdf")

```

And the end result:

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/8/1/81f7ff91fae304038c5c5aefd075b2d82e1f94ce.png)

[Previous page](https://discourse.julialang.org/t/viewer-for-pdf-images/95668.md?page=1)
