Renaming a pdf file while it is opened

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

plex
User
Posts: 2
Joined: Fri Apr 07, 2017 8:25 am

Renaming a pdf file while it is opened

Post by plex »

Hello Support Team,
sometimes the workflow in our company requires a great deal of renaming pdf files according to the files' contents.
I would be very convenient to do this while the pdf document is opened. Of course I'm aware of the possibility to use
"save as" but that is not what I mean. I do not want to create any copy. Some graphic viewers we are using provide that
feature: Open the file, view it, hit F2 (the typical windows renaming shortcut), type in the new name, close the dialog ...
and that's it. Is there a way to do this in the PDF-XChange Editor or is there a chance that this feature could be implemented?
Greetings from Berlin, Germany
Willy Van Nuffel
User
Posts: 2395
Joined: Wed Jan 18, 2006 12:10 pm

Re: Renaming a pdf file while it is opened

Post by Willy Van Nuffel »

Please read the information in this topic:

https://forum.pdf-xchange.com/ ... 62&t=27839
plex
User
Posts: 2
Joined: Fri Apr 07, 2017 8:25 am

Re: Renaming a pdf file while it is opened

Post by plex »

Thank you for the valuable information. I haven't thought of the windows preview pane so that's a really good tip.
The only thing a need to know now is how to register/activate manually the Shell Extension of PDF-XChange.
On one of our computers the preview doesn't work.
Any instructions available?
User avatar
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK

Re: Renaming a pdf file while it is opened

Post by Will - Tracker Supp »

Hi plex,

Thanks for the post - Please see here:
https://www.pdf-xchange.com/knowle ... xtensions-

Thanks for the link Willy :)
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
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß

Re: Renaming a pdf file while it is opened

Post by yogi108 »

plex wrote:Hello Support Team,
sometimes the workflow in our company requires a great deal of renaming pdf files according to the files' contents.
I would be very convenient to do this while the pdf document is opened. Of course I'm aware of the possibility to use
"save as" but that is not what I mean. I do not want to create any copy. Some graphic viewers we are using provide that
feature: Open the file, view it, hit F2 (the typical windows renaming shortcut), type in the new name, close the dialog ...
and that's it. Is there a way to do this in the PDF-XChange Editor or is there a chance that this feature could be implemented?
Greetings from Berlin, Germany
Hi,

Here is some peace of Javascript code you can adapt and connect to a button.
I havn't seen any possibility to delete a file via Javascript, so instead of deleting
it alerts you with the path and file to be deleted. Anyway, at the moment
it fits my needs.

If a document is created new without saving (extracting pages etc.) it is different in handling
because there is no path at the beginning, but also no "deleting" - no real file exists.

If a file exists, the file will be saved in the same path with the new name and an alert pops up
with the name of the file to be deleted. The original is closed and the new file is opened instead.

All this behaviour can be changed but the deleting is not possible ....
Tested as good as possible but no special check vor valid names etc., no warranty and I do not guarantee that it works.

Here we go:

Code: Select all


app.addToolButton({   
 cName: "5",   
 // oIcon: oIcon2,
 cExec: "rename_doc();",   
 cTooltext: "Aktives Dokument umbenennen",   
 cLabel: " ",
 nPos: -1
});


function rename_doc()
{
var box;
var bDelete;
var myDocPath;

if (this.numPages==undefined)
{
	app.alert("Kein aktives Dokument!",2);
	return;
}

box=app.alert("Aktives Dokument umbenennen?",2,2,"Umbenennen");
if(box==4){ 

	var cFile = app.response("Neuer Name:","Umbenennen"); // should have filename only including extension pdf
	// app.response(cQuestion,cTitle,cDefault,bPassword,cLabel);
	var strNewPath;

	if (cFile==null || cFile=="")
	{
		app.alert("Abbruch!",2);
		return;
	}

	if (this.documentFileName=="") // not yet saved! No deleting required
	{
		bDelete=false;
		// Acquire path for current document
		var oRetn = app.browseForDoc({
		cFilenameInit: cFile, // will be ok in the next build .122, at the moment no name is in the getbox
		bSave: true,
		});
		if ( typeof oRetn != "undefined" )
		{
			strNewPath = oRetn.cPath; 
		} else return;

	} else 
	{
		// has a Name, delete afterwards
		bDelete=true;
		// Acquire path from current document 
		myDocPath = this.path; 
		// break into an array of path components 
		var aPathComps = myDocPath.split("/"); 
		// var pathRoot = aPathComps[1]; // second element 
		var myFilename = aPathComps[aPathComps.length-1]; // Last element
		// First pop the old file name off the end 
		aPathComps.pop(); 
		// Next, add the new file name to the end of the array 
		aPathComps.push(cFile); 
		// Put the path back together as a string 
		strNewPath = aPathComps.join("/");
	}
		
	// console.println(strNewPath);
	var ret=this.saveAs({
		cPath: strNewPath,
		bPromptToOverwrite: true // if exists ask for overwriting
	});
	
	if (bDelete==true)
	{
		this.closeDoc(); // schliessen
		app.alert("Löschen von Hand: " + myDocPath);
		// delete myDocPath
		
	}
	app.openDoc(strNewPath);
   
   
} 
else if(box==false){ 

	app.alert("Abbruch!");

} 

}

greetings from Austria,
"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
Giraffe
User
Posts: 192
Joined: Sun Feb 03, 2008 6:13 pm
Location: Northampton, England

Re: Renaming a pdf file while it is opened

Post by Giraffe »

Will - Tracker Supp wrote:Hi plex,

Thanks for the post - Please see here:
https://www.pdf-xchange.com/knowle ... xtensions-

Thanks for the link Willy :)
Interesting - I didn't know about this.
Just tried it and got an error message on the second command. I was due to ...Win32 folder not being there! I made a new folder, copied the .dll to it, ran the command again a registration succeeded.

Thank you.
User avatar
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK

Re: Renaming a pdf file while it is opened

Post by Will - Tracker Supp »

Thanks for that Yogi! That works beautifully!
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
User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß

Re: Renaming a pdf file while it is opened

Post by yogi108 »

it was just a nice to have button :-)
"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
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK

Re: Renaming a pdf file while it is opened

Post by Will - Tracker Supp »

:D
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