PDFView highlight button doing nothing & can't override

Hi everyone,

I'm trying to make a custom highlight functionality in PDFKit's PDFView on iOS 16. I've tried everything recommended online, and it seems like there's no way to fully override the menu and remove the normal "Highlight" action which actually does nothing if you tap it.

I'd be okay with being able to either remove the base Highlight action because I'm able to add my own, or figure out how to handle a tap on that button. Here's what I've tried, and the result:

override func buildMenu(with builder: UIMenuBuilder) {
        super.buildMenu(with: builder)

        builder.remove(menu: .application)
        builder.remove(menu: .lookup)
        builder.remove(menu: .learn)
        builder.remove(menu: .find)
        builder.remove(menu: .file)
        builder.remove(menu: .edit)
        builder.remove(menu: .services)

        if #available(iOS 16.0, *) {
            builder.remove(menu: .document)
        }

        let highlightAction = UIAction(title: "Highlight 2", attributes: []) { _ in
                 print("This works")
            }
        }

        let highlightMenu = UIMenu(title: "Highlight 2", options: [.displayInline], children: [highlightAction])

        builder.remove(menu: .standardEdit)
        builder.remove(menu: .share)
        builder.remove(menu: .toolbar)
        builder.remove(menu: .text)
        builder.remove(menu: .font)
        builder.remove(menu: .format)
        builder.remove(menu: .transformations)
        builder.remove(menu: .preferences)
        builder.remove(menu: .window)
        builder.remove(menu: .view)
        
        builder.replaceChildren(ofMenu: .root, from: { _ in [highlightAction] })
    }

Please help!

Hi,

PostScript is a stack based programming language. Might be you should try to solve it in PostScript level 3 itself.

Search online for "Postscript Primer" or "Postscript Language Reference".

PDF is a PostScript level 3 dialect.

regards, Joël

PDFView highlight button doing nothing & can't override
 
 
Q