• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to truncate the file name in this script

Explorer ,
Nov 29, 2018 Nov 29, 2018

Copy link to clipboard

Copied

I found this "oldie but goodie" script and it is performing very well except the name of the PDF it produces includes the .indd

for example Test.indd will create a PDF named Test.indd.pdf

how do i rework this so it will produce a name like Test.pdf

thank you

scott

//ExportPDF_in_Foreground.jsx 

//Uwe Laubender 

/**

* @@@BUILDINFO@@@ ExportPDF_in_Foreground.jsx !Version! Wed Jun 23 2010 17:08:10 GMT+0200

*/ 

//DESCRIPTION:PDF-Export in foreground (old school like in InDesign CS4) 

 

if(app.documents.length>0){ 

    var d=app.activeDocument; 

    }; 

else{ 

    alert("Please open a document to execute export to pdf. Script will be aborted."); 

    exit(); 

    } 

if(d.saved == false){ 

    alert("Save your document first before executing export to pdf. Script will be aborted."); 

    exit(); 

    }; 

 

var pdfPath = Folder.selectDialog("Folder to save LOW RES pdf:"); 

var pdfName = d.name+"_LOW.pdf"; 

 

var userDefFileName = prompt("File name:",pdfName,undefined); 

 

if(userDefFileName == null){ 

    exit(); 

    }; 

 

var pdfFullName = pdfPath+"/"+userDefFileName; 

 

if(File(pdfFullName).exists){ 

    c=confirm("The PDF-file \""+userDefFileName+"\" is already existing. Do you want to overwrite it?",true,undefined); 

    if (c==0){exit()};   

    }; 

//Error-handling if PDF file override is on and PDF is already opened in an PDF reader app: 

try{ 

d.exportFile(ExportFormat.PDF_TYPE,File(pdfFullName),true,undefined,undefined); 

}catch(e){ 

    alert("Error:\r"+e.message+"\r\r(Line "+ e.line+" in script code.)"); 

    exit(); 

    };   

TOPICS
Scripting

Views

705

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
community guidelines
Contributor ,
Nov 29, 2018 Nov 29, 2018

Copy link to clipboard

Copied

Hi,

     Replace ".indd" to "" or get substring from the name.

//ExportPDF_in_Foreground.jsx

//Uwe Laubender

/**

* @@@BUILDINFO@@@ ExportPDF_in_Foreground.jsx !Version! Wed Jun 23 2010 17:08:10 GMT+0200

*/

//DESCRIPTION:PDF-Export in foreground (old school like in InDesign CS4)

if(app.documents.length>0){

    var d=app.activeDocument;

    };

else{

    alert("Please open a document to execute export to pdf. Script will be aborted.");

    exit();

    }

if(d.saved == false){

    alert("Save your document first before executing export to pdf. Script will be aborted.");

    exit();

    };

var pdfPath = Folder.selectDialog("Folder to save LOW RES pdf:");

var docName = d.name;

docName = docName.substring(0, docName.lastIndexOf(".indd"))

var pdfName = docName + "_LOW.pdf";

var userDefFileName = prompt("File name:",pdfName,undefined);

if(userDefFileName == null){

    exit();

    };

var pdfFullName = pdfPath+"/"+userDefFileName;

if(File(pdfFullName).exists){

    c=confirm("The PDF-file \""+userDefFileName+"\" is already existing. Do you want to overwrite it?",true,undefined);

    if (c==0){exit()};  

    };

//Error-handling if PDF file override is on and PDF is already opened in an PDF reader app:

try{

d.exportFile(ExportFormat.PDF_TYPE,File(pdfFullName),true,undefined,undefined);

}catch(e){

    alert("Error:\r"+e.message+"\r\r(Line "+ e.line+" in script code.)");

    exit();

    };  

Votes

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
community guidelines
Community Expert ,
Nov 29, 2018 Nov 29, 2018

Copy link to clipboard

Copied

I see the script asking the name of the pdf file in a prompt with a pre populated name, that name also does not match with what you mentioned. If the document name is Test.indd, the suggested name is Test.indd_LOW.pdf.

Now if you want the suggested name to be just Test.pdf

Change the following line of code to the one mentioned below it

var pdfName = d.name+"_LOW.pdf";          //Replace this line with the one below it

var pdfName = d.name.substring(0, d.name.indexOf("."))+"_LOW.pdf";

-Manan

Votes

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
community guidelines
Community Expert ,
Nov 30, 2018 Nov 30, 2018

Copy link to clipboard

Copied

Hi Manan,

better use this:

var pdfName = d.name.replace(/\.indd$/i,"") + "_LOW.pdf" ;

Imagine what will happen to a PDF exported from a document that is named like that:

my.indd-doc-opened-with-CC-2019.indd

Result string wth your suggestion:

my_LOW.pdf

Regards,
Uwe

Votes

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
community guidelines
Community Expert ,
Nov 30, 2018 Nov 30, 2018

Copy link to clipboard

Copied

LATEST

Hi Uwe,

Sure, i did not think of this use case. This solution would be better, you never know how someone would name his files, better to make the solution as robust as it gets. I admire the amount of thought you put towards seemingly simple problems and come up with use cases most of the people miss out.

Thanks,

-Manan

Votes

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
community guidelines
Community Expert ,
Nov 30, 2018 Nov 30, 2018

Copy link to clipboard

Copied

@Js1212  wrote

I found this "oldie but goodie" script and it is performing very well except the name of the PDF it produces includes the .indd

for example Test.indd will create a PDF named Test.indd.pdf

…   

Hi @Js1212 ,

I did that on purpose!

To indicate the origin of the PDF. 🙂

Best,
Uwe

Votes

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
community guidelines