Custom tools/icons in toolbars in submenus  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

HQue
User
Posts: 22
Joined: Fri Mar 14, 2025 2:34 pm

Custom tools/icons in toolbars in submenus

Post by HQue »

Hello there, ,

could someone tell me what I would have to change in cParent and cRbParent in addSubMenu() and addMenuItem() in a custom tool in order to get my icon/tool displayed here:
Format - Text Editing Tools
image.png

Code: Select all

app.addSubMenu({ cName: "symbolsTR", cUser: "Alpha", cParent: "-", cRbParent: "Format", bNewRbGroup: true, nRbGroupStyle: 2 });

app.addMenuItem( {
	cName: "alpha",
	cUser: "Alpha",
	oIcon: alphaIcon,
	cTooltext: "",
        cParent: "Format",
        cRbParent: "rbar.format.properties", // add to comment tools on home ribbon
	cEnable: "event.rc = (this.selectedAnnots?.length)",
	cExec: "executeAlphaFct(this)"
});

Thanks in advance!

Niklas
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11586
Joined: Wed Jan 03, 2018 6:52 pm

Re: Custom tools/icons in toolbars in submenus

Post by Daniel - PDF-XChange »

Hello, HQue

I am unsure if this is possible, given the context sensitivity of the Format ribbons, and their lack of presence when the corresponding tools are not in use... I have asked the Dev team for details on if and how this is possible, and will let you know as soon as I have heard back from them.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
HQue
User
Posts: 22
Joined: Fri Mar 14, 2025 2:34 pm

Re: Custom tools/icons in toolbars in submenus

Post by HQue »

That would be great, thank you!!
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11586
Joined: Wed Jan 03, 2018 6:52 pm

Re: Custom tools/icons in toolbars in submenus

Post by Daniel - PDF-XChange »

Hello, HQue

I am sorry to say that they have confirmed this. At the moment there is no way to define the dynamic "Format" tabs, as a target for JS button placement. You will need to use a different, "static" Ribbon tab to store those buttons.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
HQue
User
Posts: 22
Joined: Fri Mar 14, 2025 2:34 pm

Re: Custom tools/icons in toolbars in submenus

Post by HQue »

Okay, that's a pitty but thanks a lot for the answer and the time for investigating!
User avatar
Jordan - PDF XChange
Site Admin
Posts: 266
Joined: Mon Jul 03, 2023 3:10 pm

Custom tools/icons in toolbars in submenus

Post by Jordan - PDF XChange »

:)
Best regards,
Jordan
HQue
User
Posts: 22
Joined: Fri Mar 14, 2025 2:34 pm

Re: Custom tools/icons in toolbars in submenus

Post by HQue »

Hello Daniel, hello Jordan

I would have another question related to the placements of menus.
I want to have my custom dynamic stamp tool placed next to the standard stamp icon with these seperator lines and as a large icon.
image.png

How can I do that?

So far my code looks like this:

Code: Select all

// This adds a menu item
app.addSubMenu({ cName: "addTools", cUser: "Add-in Tools", cParent: "Tools", nPos: 0, cRbParent:"-" });
app.addMenuItem({
    cName: "stamp",
    cUser: ("Stamp", 'Dynamischer Stempel'),
    cTooltext: ("Add stamp", 'Dynamischer Stempel'),
    cParent: "parents",
    cRbParent: "rbar.home.comment", // add to comment tools on home ribbon
    cEnable: true,
    cExec: "executeStampFct(this)",
    oIcon: stampIconLarge,
});

But I can not find any ressources on how to get:
- seperator lines
- large icons
- positioning

Any help on this one would be great!!
You do not have the required permissions to view the files attached to this post.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: Custom tools/icons in toolbars in submenus

Post by Stefan - PDF-XChange »

Hello HQue,

You can enter the customize toolbar mode (right click any toolbar area and select the last option in the drop down menu), and you should then be able to move your icon from the "Add on tools" tab to any of the other tabs.

I do not believe you can do it via JS code directly through, but it is possible with the UI.

Kind regards,
Stefan
HQue
User
Posts: 22
Joined: Fri Mar 14, 2025 2:34 pm

Re: Custom tools/icons in toolbars in submenus

Post by HQue »

Hi Stefan,
Thanks for your answer.

I would be quite surprised if there were no possibility to control this JavaScript.
The big advantage would be that if we share the tool in the office, everyone would already have it in the correct location.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11586
Joined: Wed Jan 03, 2018 6:52 pm

Re: Custom tools/icons in toolbars in submenus

Post by Daniel - PDF-XChange »

Hello, HQue

Sadly, at the moment, there is no way to add divider lines to the UI via JS, nor any way to define the size of the icon on the toolbar. This may come along in the future, but for now I am sorry to say it is not possible.

Regarding position, you have found the options to place it on a specific tab/toolbar, as well as define its position relative to other JS items on that same toolbar (it is not possible to control this position relative to standard tools). "nPos:" and "cRbParent:"

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
HQue
User
Posts: 22
Joined: Fri Mar 14, 2025 2:34 pm

Re: Custom tools/icons in toolbars in submenus

Post by HQue »

Alright, thanks for the reply!
Thanks that would be nice indeed
Mathew
User
Posts: 645
Joined: Thu Jun 19, 2014 7:30 pm

Re: Custom tools/icons in toolbars in submenus

Post by Mathew »

Sorry for my belated response - I don't check posts very often.
HQue wrote: Fri Jun 06, 2025 8:42 am Hello Daniel, hello Jordan

I would have another question related to the placements of menus.
I want to have my custom dynamic stamp tool placed next to the standard stamp icon with these seperator lines and as a large icon.
image.png


How can I do that?
Hi Niklas,

Something like this?

Code: Select all

// new sub-menu in the Home ribbon
app.addSubMenu({
    cName: "myStampTools",
    cParent: "-",
    cRbParent: "Home", // add to home ribbon
    nRbPos: "rbar.home.links",
    bPrepend: true, // put it in front of the links sub-menu
    bNewRbGroup: true, // this is a new button group
    nRbGroupStyle: 4, // large button, layout left-to-right
});
// this actually adds the menu item. Use the above cName as the cRbParent
app.addMenuItem({
    cName: "stampAdd",
    cUser: "Stamp!",
    cTooltext: "Add stamp",
    cEnable: true,
    cExec: "executeStampFct(this)",
    oIcon: stampIconLarge,
// for the classic menu
    cParent: "cmd.tools.markup",
    nPos: "Annots:Tool:InkMenuItem",
// for the ribbon
    cRbParent: "myStampTools", // add to home ribbon
    nRbSepStyle: 2
});
// add separator for classic menu only, not for Ribbon UI. To not add separator in Ribbon UI we specify "-" for cRbParent.
app.addMenuItem( {
    cName: "-",
    cParent: "cmd.tools.markup",
    nPos: "stampAdd",
    cRbParent: "-",
    cExec: "" }
);
I've attached Tracker's published examples of adding ribbon menu items, and all the various options:
js_addRbMenuExample.zip
and more on it in the forum here viewtopic.php?p=184605#p184605 and here viewtopic.php?t=44829
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11586
Joined: Wed Jan 03, 2018 6:52 pm

Custom tools/icons in toolbars in submenus

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
HQue
User
Posts: 22
Joined: Fri Mar 14, 2025 2:34 pm

Re: Custom tools/icons in toolbars in submenus

Post by HQue »

Hi Mathew,

this is HUGE! Thank you!

Do you know by any chance how to add that icon to the "Home" ribbon and also to the "Annotations" ribbon as well?
Apparently, this does the job only for either one location or the other.

Code: Select all

// Add to home
// ---------------------
// new sub-menu in the Home ribbon
app.addSubMenu({
    cName: "dyn. Stempel",
    cParent: "-",
    cRbParent: "Home", // add to home ribbon
    nRbPos: "rbar.home.links",
    bPrepend: true, // put it in front of the links sub-menu
    bNewRbGroup: true, // this is a new button group
    nRbGroupStyle: 4, // large button, layout left-to-right
});
// this actually adds the menu item. Use the above cName as the cRbParent
app.addMenuItem({
    cName: "dynStamp",
    cUser: "Prüfstempel",
    cTooltext: "Add stamp",
    cEnable: true,
    cExec: "executeStampFct(this)",
    oIcon: stampIconLarge,
// for the classic menu
    cParent: "cmd.tools.markup",
    nPos: "Annots:Tool:InkMenuItem",
// for the ribbon
    cRbParent: "dyn. Stempel", // add to home ribbon
    nRbSepStyle: 2
});
// add separator for classic menu only, not for Ribbon UI. To not add separator in Ribbon UI we specify "-" for cRbParent.
app.addMenuItem( {
    cName: "-",
    cParent: "cmd.tools.markup",
    nPos: "dynStamp",
    cRbParent: "-",
    cExec: "" }
);
And I want to add it next to the normal stamp icon in "Annotations" > "Drawing", too.
image.png
You do not have the required permissions to view the files attached to this post.
Mathew
User
Posts: 645
Joined: Thu Jun 19, 2014 7:30 pm

Re: Custom tools/icons in toolbars in submenus  SOLVED

Post by Mathew »

HQue wrote: Mon Jul 28, 2025 7:47 am Do you know by any chance how to add that icon to the "Home" ribbon and also to the "Annotations" ribbon as well?

And I want to add it next to the normal stamp icon in "Annotations" > "Drawing", too.
image.png
I think the first step to adding items to the ribbon is to run the following (from the examples published by Tracker):

Code: Select all

/************************************************************************
	To see the actual Classic/Ribbon UI structure you may use the 
	following script:
************************************************************************/

	function FancyMenuList(m, nLevel) {
	     var s = "";
	     for (var i = 0; i < nLevel; i++) s += "  ";
	     var n = m.cName;  
	     if (n == "") n = "-----"
	     console.println(s + n);
	     if (m.oChildren != null)
	         for (var i = 0; i < m.oChildren.length; i++)
	             FancyMenuList(m.oChildren[i], nLevel + 1);
	}
	var m = app.listMenuItems(); 	//to get list of items inside ClassicUI.MenuBar or inside the RibbonUI, 
	                             	//  also the optional cName parameter can be used to get items-list of certain menu/toolbar/tab
	//var m = app.listToolbarButtons(); 	// to get list of items inside the Addon toolbar
    
	for (var i = 0; i < m.length; i++) FancyMenuList(m[i], 0);
Save the output from that as a text file so it's easier to find out what names to use for each of the ribbon or menu items. Looking down that output, and searching for "stamp", we find:

Code: Select all

...
    rbar.comment.drawing.part1
      cmd.tool.annot.stamp
        cmd.stampsList
        cmd.view.stamps
    rbar.comment.drawing.part2
      Annots:Tool:InkMenuItem
        cmd.toolStylesList
        cmd.view.commentStyles
      cmd.tool.annot.eraser
...
So if you want it after "cmd.view.stamps" you'd want to put it before "rbar.comment.drawing.part2". Looking up higher, we can see this is all part of the "rbar.comment.drawing" sub-menu so, add the following lines after the ones you already have (I commented out the oIcon line so I could test it):

Code: Select all

app.addSubMenu({
    cName: "dyn.Stempel.1",
    cParent: "-",
    cRbParent: "rbar.comment.drawing", // add to comment ribbon drawing sub-menu
    nRbPos: "rbar.comment.drawing.part2",
    bPrepend: true, // put it in front
    bNewRbGroup: true, // this is a new button group
    nRbGroupStyle: 4, // large button, layout left-to-right
});
// this actually adds the menu item. Use the above cName as the cRbParent
app.addMenuItem({
    cName: "dynStamp",
    cUser: "Prüfstempel",
    cTooltext: "Add stamp",
    cEnable: true,
    cExec: "executeStampFct(this)",
//    oIcon: stampIconLarge,
// set the previously defined sub-menu as the parent
    cParent: "dyn.Stempel.1",
    nRbSepStyle: 2
});
Last edited by Mathew on Tue Jul 29, 2025 8:36 pm, edited 1 time in total.
User avatar
Dimitar - PDF-XChange
Site Admin
Posts: 2432
Joined: Mon Jan 15, 2018 9:01 am

Custom tools/icons in toolbars in submenus

Post by Dimitar - PDF-XChange »

:)
HQue
User
Posts: 22
Joined: Fri Mar 14, 2025 2:34 pm

Re: Custom tools/icons in toolbars in submenus

Post by HQue »

Hi Mathew,
awesome that works but I realised that somehow it is not possible to have the same icon in two different app.addMenuItem() functions
So I just copied the icon and that works now perfectly - thanks a lot!

Code: Select all

// Add to home
// ---------------------
// new sub-menu in the Home ribbon
app.addSubMenu({
    cName: "dyn. Stempel",
    cParent: "-",
    cRbParent: "Home", // add to home ribbon
    nRbPos: "rbar.home.links",
    bPrepend: true, // put it in front of the links sub-menu
    bNewRbGroup: true, // this is a new button group
    nRbGroupStyle: 4, // large button, layout left-to-right
});
// this actually adds the menu item. Use the above cName as the cRbParent
app.addMenuItem({
    cName: "dynStamp",
    cUser: "Prüfstempel",
    cTooltext: "Add stamp",
    cEnable: true,
    cExec: "executeStampFct(this)",
    oIcon: stampIconLarge1,
// for the classic menu
    cParent: "cmd.tools.markup",
    nPos: "Annots:Tool:InkMenuItem",
// for the ribbon
    cRbParent: "dyn. Stempel", // add to home ribbon
    nRbSepStyle: 2
});
// add separator for classic menu only, not for Ribbon UI. To not add separator in Ribbon UI we specify "-" for cRbParent.
app.addMenuItem( {
    cName: "-",
    cParent: "cmd.tools.markup",
    nPos: "dynStamp",
    cRbParent: "-",
    cExec: "" }
);


// Add to Comment
// ---------------------
app.addSubMenu({
    cName: "dyn.Stempel.1",
    cParent: "-",
    cRbParent: "rbar.comment.drawing", // add to comment ribbon drawing sub-menu
    nRbPos: "rbar.comment.drawing.part2",
    bPrepend: true, // put it in front
    bNewRbGroup: true, // this is a new button group
    nRbGroupStyle: 4, // large button, layout left-to-right
});
// this actually adds the menu item. Use the above cName as the cRbParent
app.addMenuItem({
    cName: "dynStamp",
    cUser: "Prüfstempel",
    cTooltext: "Add stamp",
    cEnable: true,
    cExec: "executeStampFct(this)",
    oIcon: stampIconLarge2,
// set the previously defined sub-menu as the parent
    cParent: "dyn.Stempel.1",
    nRbSepStyle: 2
});
Mathew
User
Posts: 645
Joined: Thu Jun 19, 2014 7:30 pm

Re: Custom tools/icons in toolbars in submenus

Post by Mathew »

HQue wrote: Tue Jul 29, 2025 10:37 am awesome that works but I realised that somehow it is not possible to have the same icon in two different app.addMenuItem() functions
So I just copied the icon and that works now perfectly - thanks a lot!
:)

Another way to handle reusing the same icon: If you are using an object to include the icon stream in the code (rather than PXCE's util.iconStreamFromImage ) you may just have to reset it. For example, if using the tool here viewtopic.php?t=42029 you can reset it with:

Code: Select all

stampIconLarge.count = 0;
before the second app.addMenuItem()
User avatar
Dimitar - PDF-XChange
Site Admin
Posts: 2432
Joined: Mon Jan 15, 2018 9:01 am

Custom tools/icons in toolbars in submenus

Post by Dimitar - PDF-XChange »

:)