How to get the Core Graphics Context (CGContext) to show a PDF in an iOS app?

I am using the CoreGraphics to show a PDF in an iOS app. I can get a pointer to the PDF file

CGPDFDocumentRef pdfDocument = CGPDFDocumentCreateWithURL(pdfURL);

I am struggling with

void paint(juce::Graphics& g) override
{
    if (pdfDocument != nullptr){
        CGContextRef context = juce::Graphics::getInternalContext(g).getCGContext();
        // the error is
        // Call to non-static member function without an object argument
        
        // I also tried
        CGContextRef context = g.getInternalContext().getCGContext();
        // the error is
        // No member named 'getCGContext' in 'juce::LowLevelGraphicsContext'
    }

I’d appreciate any help

I think using an UIComponent might help.

You can get the UIView from getView(), you just need to cast it properly.

And on macOS the NSViewComponent also exists.

2 Likes

It would be cool if there were a cross-platform way to view PDF’s… would help immensely with getting the Plugin documentation in front of the users eyeballs.

Although I suppose a WebView would suffice … I guess the way to do this in a cross-platform manner would be to see how much of a PDF the WebView can render …

1 Like

What I usually do is

juce::URL manualURL ("https://myawesomecompany.com/manuals/1.0.4/plugin.pdf");
manualURL.launchInDefaultBrowser();

That also helps me to have the manual in one place and up to date.

3 Likes

The use case in my scenario is seeing the music score. I will have a look at WebView. If you find anything related to Core Graphics on iOS, I’d appreciate it

Create an Objective-C class that extends UIView in a .mm file. Inside its drawRect method you can obtain the CGContext and then call drawPDFPage. Stick this UIView inside of a JUCE UIViewComponent and add that to your UI.

2 Likes