Highlighted

Save as new File name, on button click?

New Here ,
Jul 28, 2020

Copy link to clipboard

Copied

I am currently running 3 scripts on my save button that execute before the

Execute menue item > File> PDF>Save As

 

I want to be able set up script that will change the name of the original file for the user - so that they don't save their new .pdf over the template on accident. 

 

currently my save button runs these scripts before the "execute menue item" 
//locks the page
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
this.getField(fname).readonly = true; // makes all fields readonly
}

//deletes my template 

for (var p=this.numPages-1; p>=0; p--) {
for (var n=0; n<this.getPageNumWords(p); n++) {
if (this.getPageNthWord(p, n) == "Template") {
this.deletePages(p);
break;
}
}
}

 

//hides all my buttons

for (var i=0; i<this.numFields; i++) {

var f = this.getField(this.getNthFieldName(i));

if (f==null) continue;

if (f.type=="button") f.display = display.hidden;

}

Then executes my save as request. 

 

Im hoping the code would go here. To change the name and then save as - instead. 

 

I have this so far: 

// Split Path into an array so it is easy to work with
var aMyPath = this.path.split("/);

// Remove old file name
aMyPath.pop();

// Add new file name
aMyPath.push("NewFileName.pdf");

// Put path back together and save
this.saveAs(aMyPath.join("/"));

 

Currently, everything runs but the file isn't saving under a new name. 

Or is there a way to just push a suggested name into the save as?
Thanks everyone! 

TOPICS
Create PDFs, Edit and convert PDFs, How to, PDF forms

Views

23

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Save as new File name, on button click?

New Here ,
Jul 28, 2020

Copy link to clipboard

Copied

I am currently running 3 scripts on my save button that execute before the

Execute menue item > File> PDF>Save As

 

I want to be able set up script that will change the name of the original file for the user - so that they don't save their new .pdf over the template on accident. 

 

currently my save button runs these scripts before the "execute menue item" 
//locks the page
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
this.getField(fname).readonly = true; // makes all fields readonly
}

//deletes my template 

for (var p=this.numPages-1; p>=0; p--) {
for (var n=0; n<this.getPageNumWords(p); n++) {
if (this.getPageNthWord(p, n) == "Template") {
this.deletePages(p);
break;
}
}
}

 

//hides all my buttons

for (var i=0; i<this.numFields; i++) {

var f = this.getField(this.getNthFieldName(i));

if (f==null) continue;

if (f.type=="button") f.display = display.hidden;

}

Then executes my save as request. 

 

Im hoping the code would go here. To change the name and then save as - instead. 

 

I have this so far: 

// Split Path into an array so it is easy to work with
var aMyPath = this.path.split("/);

// Remove old file name
aMyPath.pop();

// Add new file name
aMyPath.push("NewFileName.pdf");

// Put path back together and save
this.saveAs(aMyPath.join("/"));

 

Currently, everything runs but the file isn't saving under a new name. 

Or is there a way to just push a suggested name into the save as?
Thanks everyone! 

TOPICS
Create PDFs, Edit and convert PDFs, How to, PDF forms

Views

24

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 28, 2020 0
New Here ,
Jul 28, 2020

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 28, 2020 0