PDF viewer


#1

Has someone implemented a pdf viewer in his JUCE project? What solution did you choose?
I need to view a pdf in a component. I cannot use an external application here.

Out of curiosity, I see that the web component can view pdf. Why cannot we have this feature separately?


#2

Rendering a PDF via WebBrowserComponent is a hack since not all native web backends (which is all WebBrowserComponent is) necessarily support PDF viewing. That’s (almost definitely) why it’s not an official feature.

PDF parsing and rendering is complicated, and AFAIK there aren’t any good framework solutions for displaying them in JUCE. I ran into this roadblock myself a while back and ended up exporting parts as SVG graphics and interleaving it with text from the PDF since I had full control of the document (it was an about document). It was extremely awful and I don’t recommend it.


#3

Have you considered using a NSImageView inside a NSViewComponent, on OSX, to display the pdf pages?


#4

You can also use CoreGraphics to open and display pdf documents. On Windows there is no such functionality i’m afraid.
https://developer.apple.com/documentation/coregraphics/cgpdfdocument?language=objc


#5

I can display the PDF in a JUCE component now, thanks to the NSViewComponent.
But that does not fit what I need, as the component cannot be overlayed by any JUCE drawing, and I need to draw on top of it. This is for music sheet annotations.
I could maybe convert a NSImage to a juce::Image. It seems there is no tool for that in JUCE. Any idea?


#7
https://forum.juce.com/t/nsimage-to-juce-image

#8

Some years ago I was looking into this as well for sheet music display.
I came across the MuPDF software as a possible option to integrate with a Juce application: https://mupdf.com/
Maybe that is also an option (I think they have an open source and a commercial license)…


#9

Thanks, yes, I saw it a while ago, and since I had compilation errors, I called Next. But I just gave it another try. The errors actually got fixed easy and it seems to do the job, and since it gives me the pixel data, it can easily be used with JUCE.

I am doing nicely on OSX now, using native tools. But I will have to go Windows at some point. MuPdf seems to be the best option.

Edit: it seems to be lacking documentation regarding the use of the libraries.