Viewer for PDF images

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.

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.

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

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?

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 :wink:

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.

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.

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.

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.

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

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.

I thought QuartzImageIO.jl should work on my Mac Mini M1.

However

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?

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/

2 Likes

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 module lets do mosaics of eps and raster formats.

Example

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.

1 Like

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:

The usage part looks like this:

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:

5 Likes