Import external PDF or SVG to Makie figure

Hello,

I would like to create a simple figure with Makie.jl, where on the left I have an Axis, and on the right an external PDF. I haven’t found anything around, except the MakieTeX.jl package, where I can import a PDF or SVG with

SVGDocument(read("file.svg", String))
PDFDocument(read("file.pdf", String))

However this is specific for latex files, while I just need to import a PDF.

Are there simpler ways?

Hello!

Try loading your PDF file with FileIO.jl and then plot it as an image:

using FileIO, CairoMakie # You'll need to install ImageMagick.jl package, too
pdf_file = load("path/to/your.pdf")

fig = Figure()
scatter(fig[1, 1], 1:10, rand(10))
img_ax, = image(fig[1, 2], pdf_file', axis = (aspect = DataAspect(), yreversed = true))
hidedecorations!(img_ax)
fig

I have installed imagemagick with brew update && brew install imagemagick but I still get

Error encountered while load File{DataFormat{:PDF}, String}("figures/header.pdf").

Fatal error:
ERROR: ArgumentError: Package ImageMagick [6218d12a-5da1-5696-b52f-db25d2ecc6d1] is required but does not seem to be installed:
 - Run `Pkg.instantiate()` to install all recorded dependencies.

Oh, probably my bad wording. You need ImageMagick.jl, like, the Julia package.

]add ImageMagick

Ok, it crashes now

julia> using FileIO

julia> pdf_file = load("figures/header.pdf")
Assertion failed: (string_info->signature == MagickCoreSignature), function GetStringInfoDatum, file MagickCore/string.c, line 1200.

[26859] signal 6: Abort trap: 6
in expression starting at REPL[4]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 6701183 (Pool: 6700724; Big: 459); GC: 9
zsh: abort      julia --project

Ok, with a different PDF file works. It very strange since MakieTeX is able to import the previous file.

BTW, it seems that the image is resterized, while I still need it to be a vector graphic.

You could try if this still works Viewer for PDF images - #35 by jules

Why do you say that is specifically for latex files? An SVGDocument or PDFDocument in MakieTeX can work with arbitrary PDFs or SVGs…maybe that wasn’t made clear in the docs?