How to remove menuitem buttons from menutoolbar

Product: PDFtron Demo

We want to remove flatten and copy buttons from the menu toolbar on annotation selection. For that, we have followed your PDFTron approach.
It is working fine for the English language but how can we handle it for other localized languages?

Code we used:

 func toolManager(_ toolManager: PTToolManager,
                     shouldShowMenu menuController: UIMenuController,
                     forAnnotation annotation: PTAnnot?,
                     onPageNumber pageNumber: UInt) -> Bool {
        if let menuItems = menuController.menuItems {
            menuController.menuItems = removeAnnotationItems(menuItems)
        }
        return  true
    }

private func removeAnnotationItems(_ items: [UIMenuItem]) -> [UIMenuItem] {
    return  items.filter { $0.title != "Flatten" && $0.title != "Copy"}
}

Can you please share a way to remove buttons from the menu toolbar for other languages too?

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi there,
The best approach to remove menu items that isn’t affected by localization is to check the action of the UIMenuItem against a known selector. The actions for the “Flatten” and “Copy” menu items aren’t currently part of the public API, but we have exposed them for you - the next experimental nightly build of the iOS SDK will have these selector-actions:

#selector(PTAnnotEditTool.flattenSelectedAnnotations(_:))
#selector(PTAnnotEditTool.copySelectedAnnotations(_:))

We’ll let you know when the build is available for you to use.

1 Like

Thanks, @dluco , It is working fine in the nightly build.

  1. Can you make other buttons like delete and style etc also public? So we can add or remove them as per our requirements.
  2. And One more question in the same context.
    Is there any way to show menu buttons icons instead of showing titles in menutoolbar like Web and Android?

Hi @rankit.agarwal,

A different approach which should work for you would be to use the localized strings themselves inside your implementation of removeAnnotationItems:

private func removeAnnotationItems(_ items: [UIMenuItem]) -> [UIMenuItem] {
    let styleStringLocalized = PTLocalizedString("Style", nil)
    return  items.filter { $0.title != styleStringLocalized }
}

This uses the PTLocalizedString API to localize the string you’re comparing.

Does that work for you?

We do not currently support showing icons instead of text in the menu toolbar on iOS.

1 Like

Yes it is working, Thanks @Jamie_Dassoulas

Hi @rankit.agarwal,

Great, we’re glad to hear this is working for you.
As always please get in touch with any other questions or issues and we will try to help in any way we can.

1 Like