customizing add-on toolbar

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

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

customizing add-on toolbar

Post by yogi108 »

Hi there,

I wonder if it is possible to customize the toolbar "add-on Tools" without using Javascript - but using scripts from the Javascriopts folder.
Using more Buttons takes in the standard many place.

I tried to use this peace of code:

Code: Select all

var myDoc = app.newDoc();
// import icon (20x20 pixels) from the file specified
myDoc.importIcon("myIcon", "/g/1.jpg", 0);
// convert the icon to a stream.
oIcon = util.iconStreamFromIcon(myDoc.getIcon("myIcon"));
// close the doc now that we have grabbed the icon stream
myDoc.closeDoc(true);

app.addToolButton({
    cName: "TimeStamp",
    oIcon: oIcon,
    cExec: "stamp_datetime()",
    cTooltext: "Datum-Uhrzeit\n1.Seite einfügen\nWassermarke setzen\nSpeichern",
    cEnable: true,
    nPos: -1
});
It works, BUT at the start of the editor there is the flickering for opening the new Doc. It takes also some time ...

Thanks in advance,
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Hello Yogi,

Actually - using scripts in the
C:\Users\<<Windows Username>>\AppData\Roaming\Tracker Software\PDFXEditor\3.0\JavaScripts
Is the preferred method to add those button.

Attached is a file that I use in that location that does add a button and there is no "blink" or slowdown of the Editor when it first loads for me.
Attachments
printAllOpenedDocs.zip
(456 Bytes) Downloaded 138 times
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Tracker Supp-Stefan wrote:Hello Yogi,

Actually - using scripts in the
C:\Users\<<Windows Username>>\AppData\Roaming\Tracker Software\PDFXEditor\3.0\JavaScripts
Is the preferred method to add those button.

Attached is a file that I use in that location that does add a button and there is no "blink" or slowdown of the Editor when it first loads for me.
Hi Stefan,

Thank you for your response.

Your code is working properly, so it is my fault not to explain it in the right way what the problem is.
To have more functions in the toolbar without wasting space it was the idea to have only a button WITHOUT text, only one icon, so there is the need of the icon.

cName will be the text on the toolbarbutton if cLabel is omitted.
If cLabel is filled with a least one character (space preferred), it works good :-)

So the problem arises, because I don´t know another way for creating an Icon Stream object - the way below works, you can test it with your own 20x20 Pixel jpg
in your given path.
But you see the flickering etc. as described in my first post - opening a new doc etc.
Hope it is described well - I´m not a native english speaker ...

Kind Regards

Code: Select all

var myDoc = app.newDoc();
//import icon (20x20 pixels) from the file specified
myDoc.importIcon("myIcon", "/g/1.jpg", 0);
// convert the icon to a stream.
oIcon = util.iconStreamFromIcon(myDoc.getIcon("myIcon"));
// close the doc now that we have grabbed the icon stream
myDoc.closeDoc(true);


app.addToolButton({   
 cName: "unique_name1",   // must be unique
 oIcon: oIcon,   // An Icon Stream object.
 cExec: "printAllOpenedDocs();",   
 cTooltext: "Print All Documents",   // The text to display in the button help text when the mouse is over the toolbutton. The default is not to have a tool tip.
 // if set to be empty, the unique cName will displayed, if set to 1 space, it works without showing text
 cLabel: " ", // A text label to be displayed on the button to the right of the icon. The default is not to have a label
 nPos: 0  
});


function printAllOpenedDocs(){
  var ad = app.activeDocs;
  for (var i = 0; i < ad.length; i++)
  {
    var pp = ad[i].getPrintParams();
    // uncomment the next line to print without dialog for each document
    // pp.interactive = pp.constants.interactionLevel.silent;
    ad[i].print(pp);
  }
}
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Hello yogi108,

I was first looking at page 717 of the JS API file - where it uses just this:

Code: Select all

this.importIcon("myIcon", "/C/temp/myIcon.jpg", 0);
var oIcon = util.iconStreamFromIcon(this.getIcon("myIcon"));
app.addToolButton({ 
But of course - this requires an already opened document unfortunately.

Then I found the code sample on page 101 (which is the addToolButton sample code) -that you seem to be using, and indeed this is done with creating a temporary file to which to load the icon.
I am going to try and see if I can create a PDF file with the icon inside it - and have that saved on the hdd - and then try to open that document (hidden) and load the icon from it - to see if it will behave better.

Regards,
Stefan
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Hi Stefan,
Thank you for having a closer look at this.

Of course the code with

Code: Select all

this.importIcon("myIcon", "/C/temp/myIcon.jpg", 0);
var oIcon = util.iconStreamFromIcon(this.getIcon("myIcon"));
app.addToolButton({
can be used if one dokument is opened at start of the editor, the icon can then be deleted also at the end of the script with

Code: Select all

this.removeIcon("myIcon");
But even a single action "touches" the file and an asterisk will be shown near the documentname indicating that something has been changed.

Maybe your idea with the hidden file is the solution, also for multiple icons to load and use for the buttons.

thanks a lot,
kind regards,
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Hi Stefan,

I had a closer look at the hidden document, just tested a little bit - it seems to be a good solution!
Will try and give later on a report,

Thanks for your help in the right direction and
kind regards
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Hi Stefan et all,

This piece of code with the attachment pdf in the path of XChange Editor/root gives the best results:

Code: Select all

// Javascript file in "path/Javascripts":
var cPath = app.getPath("app","root")+"/icons.pdf"; // for all users
myDoc = app.openDoc({ cPath: cPath, bHidden: true // hidden
});

// convert the icon to a stream.
oIcon = util.iconStreamFromIcon(myDoc.getIcon("drucker1.png"));
// close the doc now that we have grabbed the icon stream
myDoc.closeDoc();


app.addToolButton({   
 cName: "1",   
 oIcon: oIcon,   
 cExec: "printAllOpenedDocs();",   
 cTooltext: "Print All Documents",   
 cLabel: " ",
 nPos: -1  
});


function printAllOpenedDocs(){
  var ad = app.activeDocs;
  for (var i = 0; i < ad.length; i++)
  {
    var pp = ad[i].getPrintParams();
    // uncomment the next line to print without dialog for each document
    // pp.interactive = pp.constants.interactionLevel.silent;
    ad[i].print(pp);
  }
}
The PDF attached shows also the toolbar with/out the mouse over the icon and has as content the short scripts for usage with the Javascript console
for showing/adding/deleting icons:

Code: Select all

// Customize Toolbar
// To use in the Javascript console only:
// Add Icons
this.importIcon("myIcon", "/g/1.jpg", 0);
// list Icons
for (var i = 0; i < this.icons.length; i++) {
console.println("icon[" + i + "]=" + this.icons[i].name);
}
// delete Icons
for ( var i = 0; i < this.icons.length; i++)
this.removeIcon(this.icons[i].name);
If someone knows how to get rid of the space right hand side the button, would be nice.

It would be much easier to handle if possible to just place the icons into the document icon.pdf and in the Javascript
referring to the picture names to get the stream - I got a headache trying this to find out - is there a view where we
can see/edit the icons imported?

Anyway, this got finally a useable solution!
Thanks a lot,
kind regards,
Attachments
icons.pdf
the PDF contains one icon "drucker1.png"
(69.45 KiB) Downloaded 138 times
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Hello yogi108,

Glad to hear that my idea to open the file as hidden worked!

What will happen if you have the
cLabel: ""
(string with null length)?
WIll that help with the space after the image?

Cheers,
Stefan
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Tracker Supp-Stefan wrote:Hello yogi108,

Glad to hear that my idea to open the file as hidden worked!

What will happen if you have the
cLabel: ""
(string with null length)?
WIll that help with the space after the image?

Cheers,
Stefan
Hi Stefan,

Unfortunatley if cLabel = "" (empty string) the cName (unique name) is used beside the icon.

If the parameter cLabel is present AND empty, would be nice to have no text beside - the developers know if it is done easily.

Thanks,
kind regards
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Hi Yogi108,

Ahh - I remember now that you mentioned this in an earlier post as well!
I will check with my colleagues to see if not using cName won't contradict the PDF specification when cLabel is empty - and see what their thoughts are on the subject.

What happens if you do not have the cLabel entry at all? It is optional and if there oIcon parameter, it might not use the cName at all.

Regards,
Stefan
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Hi Stefan,

no cLabel behaves in the same way as used as empty string, cName will be beside the icon ...

kind regards,
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Thanks for the update Yogi!

I have already made a note, and will bring this up on the next meeting!

Cheers,
Stefan
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

It is much better than before now and I can live with it :-)

Thanks a lot,
kind regards
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

:)
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: customizing add-on toolbar

Post by Ivan - Tracker Software »

I have fixed the issue with empty or omitted cLabel. The fix will be available in the next build of the editor.
It works, BUT at the start of the editor there is the flickering for opening the new Doc. It takes also some time ...
You can use another method to add an icon. It requires a bit more preparation, by the way, as you have to export your image to hex data in ARGB format. Here is an example for your "Print All":

Code: Select all

var iconData =
"00000000000000000000000000000000A5A7C1DAFF93B4D2FF93B4D2FF93B4D2FF93B4D2FF93B4D2FF93B4D2FF93B4D2FF93B4D2A3A4C0D90000000000000000"+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF93B4D2FFFFFFFFFFFFFFFFFFFFFFFF"+
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF93B4D200000000000000000000000000000000000000000000000000000000000000000000000000000000"+
"00000000000000000000000000000000FF93B4D2FFFFFFFFFFDDEFFFFFDDEFFFFFDDEFFFFFDDEFFFFFDDEFFFFFDDEFFFFFFFFFFFFF93B4D20000000000000000"+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF93B4D2FFFFFFFFFFE6F3FFFFE6F3FF"+
"FFE6F3FFFFE6F3FFFFE6F3FFFFE6F3FFFFFFFFFFFF93B4D200000000000000000000000000000000000000000000000000000000000000000000000000000000"+
"00000000000000000000000000000000FF93B4D2FFFFFFFFFFEEF7FFFFEEF7FFFFEEF7FFFFEEF7FFFFEEF7FFFFEEF7FFFFFFFFFFFF93B4D20000000000000000"+
"0000000000000000000000000000000000000000000000000000000000000000A5C0C0C0FFB2B2B2FFB2B2B2FFB2B2B2FF93B4D2FFFFFFFFFFF6FBFFFFF6FBFF"+
"FFF6FBFFFFF6FBFFFFF6FBFFFFF6FBFFFFFFFFFFFF93B4D2FFB2B2B2FFB2B2B2FFB2B2B2A3BFBFBF000000000000000000000000000000000000000000000000"+
"FFB2B2B2FFFEFEFEFFFEFEFEFFB2B2B2FFB2B2B2FFB2B2B2FFB2B2B2FFB2B2B2FFB2B2B2FFB2B2B2FF7F9AB2FF4981B3FF4981B3FF4981B3FF4981B3FF4981B3"+
"FF4981B3FF4981B3FF4981B3784882B300000000000000000000000000000000FFB2B2B2FFFCFCFCFFE0E1E2FFB5B5B5FFB8B8B8FFB9B9B9FFBABABAFFBBBBBB"+
"FFBBBBBBFFBBBBBBFF4981B3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4981B300000000000000000000000000000000"+
"FFB2B2B2FFFAFAFAFFFAFAFAFFB0B0B0FFB0B0B0FFB0B0B0FFB0B0B0FFB0B0B0FFB0B0B0FFB0B0B0FF4981B3FFFFFFFFFFC6E4FFFFC6E4FFFFC6E4FFFFC6E4FF"+
"FFC6E4FFFFC6E4FFFFFFFFFFFF4981B300000000000000000000000000000000FFB2B2B2FFF8F8F8FFD3D3D3FFC7C8C8FFB0B0B0FFADADADFFADADADFFADADAD"+
"FFADADADFFADADADFF4981B3FFFFFFFFFFD4EBFFFFD4EBFFFFD4EBFFFFD4EBFFFFD4EBFFFFD4EBFFFFFFFFFFFF4981B300000000000000000000000000000000"+
"FFB2B2B2FFF6F6F6FFD8D9D9FFD8D9D9FFE1E1E1FFE7E7E8FFEAEAEAFFEEEEEEFFEEEEEEFFEEEEEEFF4981B3FFFFFFFFFFE2F1FFFFE2F1FFFFE2F1FFFFE2F1FF"+
"FFE2F1FFFFE2F1FFFFFFFFFFFF4981B300000000000000000000000000000000FFB2B2B2FFF4F4F4FFDEDEDFFFD7D7D8FFB9B9B9FFB2B2B2FF989898FF7D7D7D"+
"FF7D7D7DFF7D7D7DFF4981B3FFFFFFFFFFEFF8FFFFEFF8FFFFEFF8FFFFEFF8FFFFEFF8FFFFEFF8FFFFFFFFFFFF4981B3FF7D7D7DFF7D7D7DFF7D7D7D787D7D7D"+
"FFB2B2B2FFF1F1F1FFF1F1F1FFB6B6B6FF93B4D2FFFFFFFFFF7D7D7DFFFDFDFDFFFDFDFDFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7D"+
"FF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFFFDFDFDFFFDFDFDFF7D7D7DC2B8B8B8FFB2B2B2FFB2B2B2FFB2B2B2FF93B4D2FFFFFFFFFF7D7D7DFFFAFAFA"+
"FFCBCCCEFF828282FF878787FF898989FF8A8A8AFF8C8C8CFF8C8C8CFF8C8C8CFF8C8C8CFF8A8A8AFF898989FF878787FF828282FFCBCCCEFFFAFAFAFF7D7D7D"+
"234949494C4A4A4A4C4A4A4A4C4A4A4AFF93B4D2FFFFFFFFFF7D7D7DFFF6F6F6FFF6F6F6FF7A7A7AFF797979FF797979FF797979FF797979FF797979FF797979"+
"FF797979FF797979FF797979FF797979FF7A7A7AFFF6F6F6FFF6F6F6FF7D7D7D00000000000000000000000000000000FF93B4D2FFFFFFFFFF7D7D7DFFF3F3F3"+
"FFB4B5B5FFA1A2A2FF797979FF747474FF747474FF747474FF747474FF747474FF747474FF747474FF747474FF797979FFA2A3A3FFB4B5B5FFF3F3F3FF7D7D7D"+
"00000000000000000000000000000000C2A4B9CAFF93B4D2FF7D7D7DFFEFEFEFFFBDBEBFFFBDBEBFFFCCCCCDFFD7D7D8FFDBDCDCFFE2E2E2FFE2E2E2FFE2E2E2"+
"FFE2E2E2FFDCDCDCFFD7D7D8FFCCCDCDFFBDBEBFFFBDBEBFFFEFEFEFFF7D7D7D00000000000000000000000000000000234949494C4A4A4AFF7D7D7DFFECECEC"+
"FFC7C7C9FFBCBCBDFF888889FF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF7D7D7DFF888889FFBCBCBDFFC7C7C9FFECECECFF7D7D7D"+
"000000000000000000000000000000000000000000000000FF7D7D7DFFE8E8E8FFE8E8E8FF848484FF4981B3FFFFFFFFFFEDF7FFFFEDF7FFFFEDF7FFFFEDF7FF"+
"FFEDF7FFFFEDF7FFFFFFFFFFFF4981B3FF848484FFE8E8E8FFE8E8E8FF7D7D7D000000000000000000000000000000000000000000000000AB737373FF7D7D7D"+
"FF7D7D7DFF7D7D7DFF4981B3FFFFFFFFFFDBEEFFFFDBEEFFFFDBEEFFFFDBEEFFFFDBEEFFFFDBEEFFFFFFFFFFFF4981B3FF7D7D7DFF7D7D7DFF7D7D7DA8727272"+
"000000000000000000000000000000000000000000000000234949494C4A4A4A4C4A4A4A4C4A4A4AFF4981B3FFFFFFFFFFC8E6FFFFC8E6FFFFC8E6FFFFC8E6FF"+
"FFC8E6FFFFC8E6FFFFFFFFFFFF4981B34C4A4A4A4C4A4A4A4C4A4A4A244747470000000000000000000000000000000000000000000000000000000000000000"+
"0000000000000000FF4981B3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4981B300000000000000000000000000000000"+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000AB49769DFF4981B3FF4981B3FF4981B3FF4981B3FF4981B3"+
"FF4981B3FF4981B3FF4981B3A849759C000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"+
"0000000000000000234949494C4A4A4A4C4A4A4A4C4A4A4A4C4A4A4A4C4A4A4A4C4A4A4A4C4A4A4A4C4A4A4A2447474700000000000000000000000000000000";

var oIcon =
{
//
dataPos: 0,
//
width:	24,
height: 24,
read: function(numBytes)
	{
        var s = iconData.substr(this.dataPos * 2, numBytes * 2);
        this.dataPos += numBytes;
        return s;
	}
};

app.addToolButton({   
 cName: "printAll",   
 oIcon: oIcon,   
 cExec: "printAllOpenedDocs();",   
 cTooltext: "Print All Documents",   
 cLabel: " ",
 nPos: -1  
});

function printAllOpenedDocs(){
  var ad = app.activeDocs;
  for (var i = 0; i < ad.length; i++)
  {
    var pp = ad[i].getPrintParams();
    // uncomment the next line to print without dialog for each document
    // pp.interactive = pp.constants.interactionLevel.silent;
    ad[i].print(pp);
  }
}
P.S. Please note, the Editor has no restriction 20x20 pixels for icons.
P.S.S. As a source, I use editor's icon for reserved function "Print All Documents" which is not yet implemented, unfortunately.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Hi Ivan,

Thanks for your efforts!

Also for the coding, which seems to be a quicker, but also more complex method to reach the goal.
I have no idea - also did a google search! - how to get the hex values in this format from jpg or png files - but don't worry,
I´m not an expert :-)

Also, as I said, I can live with this solution with the hidden doc open and close.

Now I have FOUR (4) buttons, each one has a Javascript associated with and 4 times open/closing the hidden doc.
Is there a way to open only once the hidden document and after the Javascripts closing it?
Something like the first script getting executed, creating public variables for the icons and using the public variables
in the other scripts?

Anyway, it seems to be so fast at the moment because of the hidden feature that I see no delay.

Just want to share because I came over this, if a hidden document is present, it wll be printed also, so
I changed the code a little bit:

Code: Select all

function printAllOpenedDocs(){
  var ad = app.activeDocs;
  for (var i = 0; i < ad.length; i++)
  {
    var pp = ad[i].getPrintParams();
	if (ad[i].hidden==true)
	{
		// nothing to do!
	} else
	{
		// uncomment the next line to print without dialog for each document
		// pp.interactive = pp.constants.interactionLevel.silent;
		ad[i].print(pp);
	}
  }
}

Looking forward to the next release,

kind regards,
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Hello yogi108,

Glad that you are happy with the speed now - but I want the ultimate one - so will check with Ivan on how to get the original ARGB data in the hex format needed.
I have spent some time looking at the options GIMP offers - maybe it will be able to produce the needed icon information but I have not yet succeeded and have other tasks to attend to as well. With the images passed this way there will be no loading of a hidden file and the whole process will be even faster!

I think a single file could have more than one icon embedded inside - so if you manage to create such a file - you can then just read all the icons from one file, and assign them accordingly to your buttons so there will be no loading of 4 document but just 1.

Regards,
Stefan
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Tracker Supp-Stefan wrote:Hello yogi108,

Glad that you are happy with the speed now - but I want the ultimate one - so will check with Ivan on how to get the original ARGB data in the hex format needed.
I have spent some time looking at the options GIMP offers - maybe it will be able to produce the needed icon information but I have not yet succeeded and have other tasks to attend to as well. With the images passed this way there will be no loading of a hidden file and the whole process will be even faster!

I think a single file could have more than one icon embedded inside - so if you manage to create such a file - you can then just read all the icons from one file, and assign them accordingly to your buttons so there will be no loading of 4 document but just 1.

Regards,
Stefan
Hi Stefan,

Of course, sometimes I want also the "best" solution.
I did all the png in one single file, but each of the 4 Javascripts have to open the file hidden and close it.
Because of your input I did now the following addbuttons in one Javascript and it works:

Code: Select all

var cPath = app.getPath("app","root")+"/icons.pdf";
myDoc = app.openDoc({ cPath: cPath, bHidden: true
});

// convert the icon to a stream.
oIcon1 = util.iconStreamFromIcon(myDoc.getIcon("stempel.png"));
oIcon2 = util.iconStreamFromIcon(myDoc.getIcon("printer.png"));
oIcon3 = util.iconStreamFromIcon(myDoc.getIcon("page.png"));
oIcon4 = util.iconStreamFromIcon(myDoc.getIcon("sortieren.png"));

// close the doc now that we have grabbed the icon stream
myDoc.closeDoc();



app.addToolButton({   
 cName: "1",   
 oIcon: oIcon2,
 cExec: "printAllOpenedDocs();",   
 cTooltext: "Drucke alle offenen PDF",   
 cLabel: " ",
 nPos: 3  
});


app.addToolButton({
    cName: "2",
	oIcon: oIcon4,   
    cExec: "ReversePageOrder()",
    cTooltext: "Seitenreihenfolge umkehren",
	cLabel: " ",
    cEnable: true,
    nPos: 1
});

app.addToolButton({
    cName: "3",
	oIcon: oIcon1,
    cExec: "stamp_datetime()",
    cTooltext: "Datum-Uhrzeit\n1.Seite einfügen\nWassermarke setzen\nSpeichern",
	cLabel: " ",
    cEnable: true,
    nPos: 2
});

app.addToolButton({
    cName: "4",
	oIcon: oIcon3,
    cExec: "dblpagenumbers()",
    cTooltext: "A4 quer\nSeitennummerierung links und rechts unten",
	cLabel: " ",
    cEnable: true,
    nPos: 0
});

I already asked if it is possible to put images (jpg, png etc) in the hidden doc to see which images are inside and then
through the Javascript get the pictures and make the stream like
icon = util.iconStreamFromIcon(myDoc.getIcon("stempel.png"));

It would be a nice to have.
But let´s see how the inline version with the aRGB works out.

thanks and
kind regards,
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: customizing add-on toolbar

Post by Ivan - Tracker Software »

I already asked if it is possible to put images (jpg, png etc) in the hidden doc to see which images are inside and then
through the Javascript get the pictures and make the stream like
icon = util.iconStreamFromIcon(myDoc.getIcon("stempel.png"));

It would be a nice to have.
But let´s see how the inline version with the aRGB works out.
As you know, you can add icons to the document using importIcon. Also, you can get a list of existing icons in the document using its property icons.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Hello yogi108,

I managed to make the "include the image in the JS file" method work using only GIMP and a text editor.
Steps to do so:
1 ) Open the image you want in GIMP. I used this file with transparency via an alpha channel:
60x60.png
60x60.png (4.63 KiB) Viewed 6569 times
2 ) Resize the image to the needed size. I used 24x24 px.
3 ) Flip the image vertically
4 ) Go to Color -> Components -> Chanel Mixer... and swap red and blue (set the value for the red channel to 0 red, 0 greed ,100% blue), and for the blue channel the opposite:
chanel_mixer.png
5 ) Go to File -> Export As... and select bmp file format, then select this in the advanced options:
export_bmp.png
export_bmp.png (8.17 KiB) Viewed 6569 times
6 ) Download and install a Hex Editor. I used XVI32 which is free to download and use and does not require installation.
7 ) Open the BMP file in the hex editor. Bytes 10-13 will show the start position from which the actual pixel data starts.
HEX Data.png
8 ) Delete the bytes before the first pixel (Ctrl+ Arrows to select, Ctrl-D to delete in XVI32)
9 ) Select all the rest of the bytes - and via Edit -> Clipboad -> Copy as Hex String you can now get those to a text Editor.
10 ) Remove spaces and break the string up in chunks - and you can then insert it in the sample code Ivan added above.

Please note that we flip the image because BMP pixels are listed from bottom to top and we need them in the JS from top to bottom. We then swap the blue and red channels as in our BMP file the colours are ordered ABGR - and we need ARGB order for the JS.
The above image after 7) shows the start of the pixel data - and because my first two pixels are fully transparent - I am checking the data of the third one in Gimp (right side) with the HEX data in the BMP file. Before taking that shot I did one "undo" in GIMP after exporting the bmp - so that I see the natural colours and be able to compare them with the order produced in the BMP.

It is quite a few steps - but it does work. The attachment below includes the data needed to show a 24x24 pixel image in the Editor interface:
editor_view.png
editor_view.png (8.73 KiB) Viewed 6569 times
Regards,
Stefan
Attachments
24x24.zip
(2.03 KiB) Downloaded 106 times
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: customizing add-on toolbar

Post by Ivan - Tracker Software »

For further ease of adding icons, new build of the Editor implements new function imageStreamFromImage in util object.

So, now your code can look like:

Code: Select all

var cIconsPath = app.getPath("app", "root");
app.addToolButton({
 cName: "1",   
 oIcon: util.imageStreamFromImage(cIconsPath + "/printer.png"),
 cExec: "printAllOpenedDocs();",   
 cTooltext: "Drucke alle offenen PDF",   
 nPos: 3  
});
This method has three parameters:

cDIPath - string - A device-independent path to an image. Supported formats: bmp, jpeg, png, gif, tiff, pxc, dcx, j2k, jbig2, ico.
nPage - integer - (optional, default value 0) A page number in multipaged image (such as tiff).
nFitSize - integer - (optional, defalut value 0) If page width or height is larger than this value, image will be resized to proptionally fit [ nFitSize x nFitSize ]. If not specified, or 0, image will be used as is.

P.S. To get method definition hint, run this method in the console with parameter jshelp. For example, when you run

Code: Select all

util.iconStreamFromImage(jshelp)
you will get the following result:

Code: Select all

Console:Exec:1: HelpError: Help.
Util.iconStreamFromImage:1:Console:Exec
====> cDIPath: string
====> [nPage: integer]
====> [nFitSize: integer]
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Hi there,

off topic:
At the beginning I thought: "buy this product, it seems to fit your needs"
Well, I bought it.
Then after a while I registered here in this forum, and - surprise - it turns out to be not only a helpful community,
but also a competent support from the front to the development.

Thank you all, in representation Stefan and Ivan, for your efforts. Keep this good product running !

back to topic :-)

@Stefan
Wow, you seem to be a technic freak - a little bit complicated, but could be a solution also.

@all
For me it seems the solution from Ivan helps me the most, just having the images in the path and create the Iconstream from there.

I'm waiting eagerly for the next release.

Btw. is there a place to get more information about functions which are not in the ADOBE API?
For further ease of adding icons, new build of the Editor implements new function imageStreamFromImage in util object.
Thanks a lot,
kind regards,
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Hello yogi108,

Thanks for the kind word - I did have a 'technic freak' moment indeed but I wanted to make it work!
It was actually Ivan who told me the specifics of the BMP format before I started reading the specification myself ;)
When he provided his original sample he also did most of those operations with his hex editor - but the license for that is rather expensive, so doing it with free tools required some extra steps.

I think the util.imageStreamFromImage is one of the first, if not the first method that we will add that is not available in Adobe's JS API documentation, and this is one of the few areas where we can add such additions - as they do not affect compatibility with other PDF readers. However in most other areas we won't be able to add our own custom methods.

Regards,
Stefan
huby1691
User
Posts: 3
Joined: Thu May 04, 2017 6:34 am

Re: customizing add-on toolbar

Post by huby1691 »

Hello Stefan,

I have used the new function and I'm very pleased with it.
The only thing I want to point out is that in most times you use a wrong name and so my first attemps failed.

The right name is: util.iconStreamFromImage

Regards,
Peter
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: customizing add-on toolbar

Post by yogi108 »

Hi,

Thanks for clearifying, changed the hidden doc method to

Code: Select all

icon=util.iconStreamFromImage("...");
works well :-)

Thanks a lot,
kind regards
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: customizing add-on toolbar

Post by Tracker Supp-Stefan »

Hi Peter,

Thanks for catching that one up!
Indeed Ivan did list it as iconStreamFromImage - not sure why I typed it otherwise!

Cheers,
Stefan
Puffolino
User
Posts: 317
Joined: Wed Feb 09, 2011 1:06 pm

Re: customizing add-on toolbar

Post by Puffolino »

Ivan - Tracker Software wrote:

Code: Select all

var iconData =
"00123ABC...FFFFFFFF";

var oIcon =
{
dataPos: 0,
width:	24,
height: 24,
read: function(numBytes)
	{
        var s = iconData.substr(this.dataPos * 2, numBytes * 2);
        this.dataPos += numBytes;
        return s;
	}
};

app.addToolButton({   
:
 oIcon: oIcon,   
:
});
That's brilliant!

I am not a javascript expert, but wouldn't it be possible to declare the variable oIcon without using the read loop?
I mean, is it possible to move the iconData definition into the oIcon (something like var oIcon=[0,0,24,24,0,0,0,1,2,3,10,11,12,....,255,255,255];)?
User avatar
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK
Contact:

Re: customizing add-on toolbar

Post by Will - Tracker Supp »

Hi Puffolino,

Try something like this:

Code: Select all

icon = util.iconStreamFromImage("/C/Users/User/Documents/JavaScripts/Bookmark Name to Header/bookmark2-40px.png");

app.addToolButton({
  cName: "bookmarkToHeader",
  cLabel: "Header From Bookmark",
  cExec: "headerBookmark()",
  cToolText: "Adds the name of each bookmark as a header, to the page associated with \nthe bookmark.",
  nPos: -1,
  oIcon: icon
});
It's potentially a much easier solution to work with and works fine for me here. Here's the full script (including icon) that can be placed in the JavaScripts folder and used:
BookmarkHeader.zip
(1.46 KiB) Downloaded 71 times
Cheers,
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.

Best regards

Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Post Reply