Viewer for PDF images

How can I display two PDF images side-by-side for a visual comparison?

Background:
I run different versions of a model and wish to compare their outputs (Makie plots saved in PDF format). Effectively, I have two directories with several PDF image files. I want to scroll through them, viewing each pair of images side-by-side.

I am open to using an app for this purpose, but have not been able to find one that works well (I am on MacOS).

I am aware of ImageView.jl; it can display to images side-by-side, but those would have to be loaded somehow from the PDF files.

One option is to convert the PDF files to SVG on the fly as suggested at

I am hoping to avoid creating a folder full of temporary files, though.

3 Likes

When I look at a git diff of a modified image in vscode, I see a side by side comparison. Possibly that will also happen for pdfs although I am not completely sure.
Would this work for you?
Perhaps it is neccessary to also install git lens.

Thank you for the suggestion. I have to investigate whether this solution would allow me to scroll through a directory full of files.

I don’t think I can make this suggestion work. I need to be able to scroll through a directory of files. When I pick “a.pdf” in dir1, I want to compare with “a.pdf” in dir2 without having to manually open it.
In VSCode, it seems I would have to manually pick both files.

One workaround that may be quite acceptable:

  • write a markdown file with a bunch of <img ...> statements (two per line)
  • preview that file in Marked

But there really should be an app for such a common task…

I could also cook up something using ImageView.jl (e.g., by converting pdf → jpg using ghostscript). But it turns out that ImageView takes several seconds to open a file, so that’s not practical (unless I am doing something wrong).

Thanks again for the suggestion.

Are the files always pretty much the same except for plots? You might grab a pdf editing package (Poppler_jll) and create a new file with A3 pages out of your two old files, where each page has v1 on the left side and v2 on the right. Then you can scroll through it side by side. Kind of crude but if there’s no app that does it?

1 Like

I think this is a commonly required task in the business world - lawyers, real estate agents, politicians, journalists, etc. all need this frequently - so there are many applications for doing this. Probably more for Windows than Mac, some text-only rather than visual, some online, and many paid or subscription options… Adobe Acrobat Pro would like $20 per month from you for their PDF tool kit… :slight_smile:

But, since you’re on a Mac, you could investigate creating an Automator action. I managed to create a Automator workflow that ‘zips’ two PDF files together page by page, using the Compare PDF (shuffle) function:

The workflow is available from the Services menu:

Then you can see both Page 1s of the two PDFs at the same time, altbeit vertically ordered…

If you’re new to scripting MacOS, using Automator (or, if absolutely necessary, AppleScript), it may take you a while to get the hang of it. Sometimes it’s worth paying someone else to save you time. :slight_smile:

And if you do not have a mac, you can use Julia :slight_smile:

2 Likes

There is also a pretty easy Julia workaround, at least with CairoMakie:

Generate test plots
let 
    mkpath("OldFigs")
    mkpath("NewFigs")
    x = LinRange(0,2pi,100)
    funcs = (sin, cos, exp)
    for f in funcs
        fig = Figure(resolution = 350 .*(2.,1.3),fontsize = 20)
        ax = Axis(fig[1,1])
        lines!(ax,x,f.(x),)
        save("OldFigs/$(string(f)).pdf",current_figure())
    end

    for f in funcs
        fig = Figure(resolution = 350 .*(2.,1.3),fontsize = 20)
        ax = Axis(fig[1,1])
        lines!(ax,x,f.(x/2),)
        save("NewFigs/$(string(f)).pdf",current_figure())
    end
end
# This is the actual function that makes the comparison plot
using CairoMakie, FileIO, ImageMagick #ImageMagick seems to be neccessary for pdfs

function PicturesComparison(OldPath,NewPath)
    files1 = readdir(OldPath)
    files2 = readdir(NewPath)
    
    names = files1 ∩ files2

    fig = Figure(resolution = 800 .*(1,0.4*length(names)))

    axkwargs = (;
    xticklabelsvisible = false,
    xticksvisible = false,
    yticklabelsvisible = false,
    yticksvisible = false,
    spinewidth = 0.,
    xgridvisible = false,
    ygridvisible = false,
    aspect = DataAspect(),
    )
    OldAx = [Axis(fig[i,1],title = n;axkwargs...) for (i,n) in enumerate(names)]
    NewAx = [Axis(fig[i,2];axkwargs...) for (i,n) in enumerate(names)]


    for (i,n) in enumerate(names)
        for (j,p) in enumerate((OldPath,NewPath))
            img = rotr90(load(joinpath(p,n)))
            ax = [OldAx,NewAx][j][i]
            image!(ax,img)
        end
    end

    fig
end
PicturesComparison("OldFigs","NewFigs")

This produces the plot

2 Likes

Yes, one could make a pdf file and page through it. I have done something similar before with pdflatex. I was hoping to avoid pdf. I have a hard time articulating exactly why I find paging through the pdf file inconvenient, but it’s doable. Thanks.

Thanks for that suggestion. I am notoriously bad at Automator / Apple Script. But it’s certainly an option.

Thanks for that suggestion. I have not looked in detail (in a hurry right now) but it seems like this would put each graph on a separate page (not side by side). I will look into it more.

Thanks for this suggestion. I think this is closest to what I was hoping for (barring an actual app that can do this). ImageMagick is the piece that I was missing.

It is also possible to create a basic HTML file with a 2 x N table and a corresponding <IMG> in each cell. First convert PDFs to SVG or PNG of course.

Then use your favorite browser

1 Like

Thank you - yes. I have been coming around to that solution as well.

I’m thinking ghostscript for the conversion, but perhaps there is a Julia package that would be more reliable than running a shell script.

Surely there are many ways to batch-convert image files. One of them on Mac is GraphicConverter by Lemke Soft. It is not free, but IMO is worth every cent of it’s price tag.

Still one more non-julian way is ImageJ/Fiji, which is scriptable in many languages (Java, Python…) and should be able to read PDFs

A GDAL linked against Poppler would let you read pdf directly as bit maps.

I had trouble installing that (M1 mac), apparently because of a mismatch between the binaries and the apple silicon (via macports).

You could make that app with GLMakie and flip through the image pairs using a button or so. I actually like image comparison better if the same canvas is flipped back and forth between two images, because then you can pick up on the smallest differences.

1 Like

Could you explain more how this would work with PDF files? Or are you thinking of a solution where I first convert to a bitmap format?

I have not been able to figure out how to load a PDF into an image format.
ImageMagick does not work for me (Apple Silicon) because of

Thank you.

Ah I assumed that loading PDFs as bitmaps worked because you marked the CairoMakie version as the solution.