Feature Request - Options for Generating Bookmarks

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

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

Post Reply
Puffolino
User
Posts: 137
Joined: Wed Feb 09, 2011 1:06 pm

Feature Request - Options for Generating Bookmarks

Post by Puffolino » Fri Apr 06, 2018 5:09 pm

I'd like to have more options to control bookmarks when creating them from text.
1. Very often I get leading and trailing spaces which could be automatically trimmed
2. It also happens, that multiple spaces are seen within the text, so another option would be fine to reduce these to a single space
3. sometimes, two headings are combined to a single bookmark entry, like "1.0 Headline 1.1 Sub headline ". Not sure, if such effects could be eliminated as well

I made a workaround for cases 1 and 2 by writing a javascript code. It's not perfect as I saw I need to start it multiple times because it reduces only one occurence of multiple spaces each time. Another point is, that "Undefined" appears at the end of the console output - don't know, why this will be displayed.

Code: Select all

function OptimizeBookmark(bkm,depth)
{	
	if (depth>0 && bkm.name.length>0)
	{
		bkm.name=bkm.name.trim().replace(/ {2,}/," ");
		var z=bkm.name.substring(0,1);
		console.println(z+": "+bkm.name);
	}

	if (bkm.children != null)
		for (var i = 0; i < bkm.children.length; i++) 
			OptimizeBookmark(bkm.children[i],depth+1); 
} 

console.clear(); console.show();
console.println("Optimizing bookmarks...");

OptimizeBookmark(this.bookmarkRoot,0);
console.println("All done.");

User avatar
TrackerSupp-Daniel
Site Admin
Posts: 2401
Joined: Wed Jan 03, 2018 6:52 pm

Re: Feature Request - Options for Generating Bookmarks

Post by TrackerSupp-Daniel » Fri Apr 06, 2018 6:13 pm

Hello Puffolino,

Hello, I believe these options already exist, take a look in the bookmarks from page text menu:
Image

Beyond that I'll answer by point:
1. The leading and trailing spaces are likely caused by the font type/size also being applied to said spaces, if you can ensure that there are no spaces in the text itself, this should not occur.
2. I am not an expert, but I believe as many PDF softwares do not have a true "Space" character, there is no way of determining how many "spaces" exist between point A and B, In turn causing it to read out exactly what has been interpreted on our end from the document in question. Again this will be solved by removing unnecessary characters.
3. Please follow this KB for detailed instructions for how to avoid this kind of problem. https://www.tracker-software.com/knowle ... the-Editor

Regarding the Undefined issue in JS, this is a common printout when there is not other output for the JS console, If you setup the code to record and print information from the console you should find this issue disappears. Nonetheless, it is also easily ignored.
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

User avatar
Ovg
User
Posts: 238
Joined: Tue Sep 05, 2017 4:56 pm
Location: Moscow

Re: Feature Request - Options for Generating Bookmarks

Post by Ovg » Fri Apr 06, 2018 6:30 pm

Puffolino wrote:
"it reduces only one occurence of multiple spaces each time."

Change

Code: Select all

bkm.name=bkm.name.trim().replace(/ {2,}/," ");

to

Code: Select all

bkm.name=bkm.name.trim().replace(/ {2,}/g," ");
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 8.0 (Build 333.0) / W7 x64 SP1

User avatar
TrackerSupp-Daniel
Site Admin
Posts: 2401
Joined: Wed Jan 03, 2018 6:52 pm

Re: Feature Request - Options for Generating Bookmarks

Post by TrackerSupp-Daniel » Fri Apr 06, 2018 6:35 pm

Thanks for sharing your knowledge Ovg!
What would I do without you?
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

User avatar
Ovg
User
Posts: 238
Joined: Tue Sep 05, 2017 4:56 pm
Location: Moscow

Re: Feature Request - Options for Generating Bookmarks

Post by Ovg » Fri Apr 06, 2018 6:40 pm

:oops:
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 8.0 (Build 333.0) / W7 x64 SP1

User avatar
TrackerSupp-Daniel
Site Admin
Posts: 2401
Joined: Wed Jan 03, 2018 6:52 pm

Re: Feature Request - Options for Generating Bookmarks

Post by TrackerSupp-Daniel » Fri Apr 06, 2018 6:55 pm

:)
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

Puffolino
User
Posts: 137
Joined: Wed Feb 09, 2011 1:06 pm

Re: Feature Request - Options for Generating Bookmarks

Post by Puffolino » Sat Apr 07, 2018 8:59 am

Thanks for the quick responses!

I did find the formatting dialog and that's the place where the additional functions (trimming, space eliminating, evtl. regular expressions in search/replace) could be added.

I didn't know about the 'g' thing - just downloaded the javascript pdf api but didn't find enough information how to include regular expressions into the scripts. Anyhow, the javascript interface looks very promising, I like to have such a feature!

Cheers,
Michael

User avatar
Ovg
User
Posts: 238
Joined: Tue Sep 05, 2017 4:56 pm
Location: Moscow

Re: Feature Request - Options for Generating Bookmarks

Post by Ovg » Sat Apr 07, 2018 9:15 am

2Puffolino

For Regex look at:
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 8.0 (Build 333.0) / W7 x64 SP1

Puffolino
User
Posts: 137
Joined: Wed Feb 09, 2011 1:06 pm

Re: Feature Request - Options for Generating Bookmarks

Post by Puffolino » Sat Apr 07, 2018 10:25 am

Thanks, I knew regular expressions before but had no idea about javascript nor their flags '/i' '/g' etc.

Puffolino
User
Posts: 137
Joined: Wed Feb 09, 2011 1:06 pm

Re: Feature Request - Options for Generating Bookmarks

Post by Puffolino » Mon Apr 09, 2018 11:04 am

My code works nearly perfect now, it removes line feeds as well as heading, trailing and multiple spaces and detects combined bookmarks ("1.2 Title 1.2.1 Subtitle") and try to split them to seperate bookmarks ("1.2 Title" and "1.2.1 Subtitle").

I wasn't able to copy the link reference from the "1.2 Title" bookmark to the new child, so clicking on this bookmark fails.

Because these are my first steps using javascript together with PDF's, I'm still a novice. So, I was wondering why a change of the value in the button definition (cExec: "OptimizeAllBookmarks(0);") did not work until restarting the PDF-XChange Editor program and I would be happy if a script file could be added to the plugin folder and assigned to a button for global usage.

Code: Select all

app.addToolButton({   
 cName: "ToolOptBookmarks",   
 oIcon: oIcon,   
 cExec: "OptimizeAllBookmarks(0);",
 cTooltext: "Optimize Bookmarks",   
 cLabel: " ",
 nPos: 2
});

function OptimizeBookmark(bkm,depth)
{	
	if (depth>0 && bkm.name.length>0)
	{
		bkm.name=bkm.name.trim().replace(/\n/g," ").replace(/ {2,}/g," ");
		//var z=bkm.name.substring(0,1);
		//if (z.length>0 && "0123456789.".search(z)>-1) console.println("Zahl");
		var z=bkm.name.search(/ \d+\.\d+/);
		//console.println(z+": "+bkm.name);
		if (z>1)
		{	var s=bkm.name.substring(z);
			console.println(z+": "+bkm.name);
			bkm.name=bkm.name.substring(0,z);
			bkm.createChild(s);
		}
	}

	if (bkm.children != null)
		for (var i = 0; i < bkm.children.length; i++) 
			OptimizeBookmark(bkm.children[i],depth+1); 
} 

function OptimizeAllBookmarks(view)
{
	console.clear();
	if (view) console.show();
	console.println("Optimizing bookmarks...");
	
	OptimizeBookmark(this.bookmarkRoot,0);
	
	console.println("All done.");
}

User avatar
TrackerSupp-Daniel
Site Admin
Posts: 2401
Joined: Wed Jan 03, 2018 6:52 pm

Re: Feature Request - Options for Generating Bookmarks

Post by TrackerSupp-Daniel » Wed Apr 11, 2018 5:43 pm

Hello puffolino,
This article might help, it allows you to create a button in the Editor UI from JS
https://www.tracker-software.com/knowle ... the-Editor
Sadly I don't know enough JS myself to help troubleshoot beyond this...
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

User avatar
Ovg
User
Posts: 238
Joined: Tue Sep 05, 2017 4:56 pm
Location: Moscow

Re: Feature Request - Options for Generating Bookmarks

Post by Ovg » Wed Apr 11, 2018 6:27 pm

change

Code: Select all

oIcon: oIcon,
with something like

Code: Select all

oIcon: util.iconStreamFromImage("/C/My Documents/My nice icon.ico"),
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 8.0 (Build 333.0) / W7 x64 SP1

User avatar
TrackerSupp-Daniel
Site Admin
Posts: 2401
Joined: Wed Jan 03, 2018 6:52 pm

Re: Feature Request - Options for Generating Bookmarks

Post by TrackerSupp-Daniel » Wed Apr 11, 2018 6:45 pm

8)
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

Puffolino
User
Posts: 137
Joined: Wed Feb 09, 2011 1:06 pm

Re: Feature Request - Options for Generating Bookmarks

Post by Puffolino » Thu Apr 12, 2018 7:16 am

Many thanks, have no problems to create the toolbar icon (found here), I was to lazy to add the inline icon definition, sorry that I've confused everyone :roll:

My problem is to copy a link location from one bookmark to a newly created one (bkm.createChild) . So clicking on the newly created bookmark does nothing. I think, I found something here, which could help me to solve my problem, but actually I wasn't able to read the expression from the actual bookmark to "transfer" it to the children.

User avatar
TrackerSupp-Daniel
Site Admin
Posts: 2401
Joined: Wed Jan 03, 2018 6:52 pm

Re: Feature Request - Options for Generating Bookmarks

Post by TrackerSupp-Daniel » Mon Apr 16, 2018 5:44 pm

Hi puffolino,
Glad that's one thing solved,
as for copying and creating a child, Could you post your JS so far for that command in here so everyone is able to take a look at it and work on a resolution together for you?
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

Puffolino
User
Posts: 137
Joined: Wed Feb 09, 2011 1:06 pm

Re: Feature Request - Options for Generating Bookmarks

Post by Puffolino » Wed Apr 25, 2018 8:46 pm

Here's my actual code:

Code: Select all


// Button and it's parameter ('0') is kept in cache - to change the console output for debuggig, the editor has to be restarted before the modified script (parameter '1') is executed
app.addToolButton({   
 cName: "ToolOptBookmarks",   
 oIcon: oIcon,   
 cExec: "OptimizeAllBookmarks(0);",
 cTooltext: "Optimize Bookmarks",   
 cLabel: " ",
 nPos: 1
});

function OptimizeBookmark(bkm,depth)
{	
	if (depth>0 && bkm.name.length>0)
	{
		bkm.name=bkm.name.trim().replace(/\n/g," ").replace(/ {2,}/g," ");
		//var z=bkm.name.substring(0,1);
		//if (z.length>0 && "0123456789.".search(z)>-1) console.println("number");
		var z=bkm.name.search(/ \d+\.\d+/);
		//console.println(z+": "+bkm.name);
		if (z>1)
		{	var s=bkm.name.substring(z);
			console.println(z+": "+bkm.name);
			bkm.name=bkm.name.substring(0,z);
			bkm.createChild(s);
		}
	}

	if (bkm.children != null)
		for (var i = 0; i < bkm.children.length; i++) 
			OptimizeBookmark(bkm.children[i],depth+1); 
} 

function OptimizeAllBookmarks(view)
{
	console.clear();
	if (view) console.show();
	console.println("Optimizing bookmarks...");
	
	OptimizeBookmark(this.bookmarkRoot,0);
	
	console.println("All done.");
}


User avatar
TrackerSupp-Daniel
Site Admin
Posts: 2401
Joined: Wed Jan 03, 2018 6:52 pm

Re: Feature Request - Options for Generating Bookmarks

Post by TrackerSupp-Daniel » Thu Apr 26, 2018 12:14 am

it has just occurred to me that I've neglected to share the JS API reference with you, it may help out a bit:

Looking at the "children" command as detailed in here, I don't know for sure but believe you may want to try using nLevel instead of depth for that specific instance of it.

Hth
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

Puffolino
User
Posts: 137
Joined: Wed Feb 09, 2011 1:06 pm

Re: Feature Request - Options for Generating Bookmarks

Post by Puffolino » Thu Apr 26, 2018 6:45 am

Thanks, the API documentation is fine.
But it seems there's no option to read the "action" of a bookmark (there are only properties like "color" and "name"). Maybe there's this is a given restriction but I can't image why this should be.

BTW "depth" or "nLevel" are just variable names, so no problem here...

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13413
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Feature Request - Options for Generating Bookmarks

Post by Tracker Supp-Stefan » Thu Apr 26, 2018 11:41 am

Hello Puffolino,

As you have probably noticed - those are all the properties and methods available through JS for Bookmarks:
JS_Bookmark.png
JS_Bookmark.png (6.86 KiB) Viewed 785 times
I'd assume the main reason for only those being available are security related.

Regards,
Stefan

Post Reply