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!

Replies

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

  • Hi just did some research and don't really understand how Postscript can help solve this PDFKit issue. It's more of a UIKit thing that's stopping me from overriding the menu, everything else is fine.

Add a Comment