Skip to main content
August 26, 2009
Question

[CS3] [JS] Export PDF to the same folder as the InDesign file

  • August 26, 2009
  • 5 replies
  • 4413 views

Hi,

I have written a JavaScript to export an InDesign file to a PDF file.

The exporting works fine when exporting to a specific folder, but I want the script to export the PDF to the SAME folder as the InDesign file.

For example, if the Indesign file is in a folder called "Owner's Manuals", I want the script to save the PDF into the same "Owner's Manuals" folder.

At the moment I have:

var myFolder = Folder.selectDialog ('Choose a Folder');

but this dialog defaults to the Desktop every time, forcing me to click 6-7 times to locate the relevant folder where I want the PDF to be saved, which is a waste of time.

I want the script to do something like the following:

"Find out the location of this InDesign file, and export the PDF to the same folder"

I have searched this forum, as well as the Scripting Reference, but without any luck.

Any suggestions are greatly appreciated.

Thanks.

This topic has been closed for replies.

5 replies

Participant
October 26, 2017

Hi, I realise that this is an old post, but using the script below I have this working, which is great!

My only problem is that I cannot change the setting from "Press Quality" to "Smallest File Size"

var myDoc = app.activeDocument;

var myFolderName = myDoc.filePath;

//Apply a name to the PDF file based on the INDD file, but without the .indd extension

var myDocumentName =  myDoc.name.slice (0, -5);

var myFilePath = myFolderName + "/" + myDocumentName + ".pdf";

var myFile = new File(myFilePath);

//Do not open the PDF Export dialog box. Set "false" to "true" if you want the dialog box.

myDoc.exportFile(ExportFormat.pdfType, myFile, false, "Press Quality");

Can anyone help or explain why this would be?

Thanks

Chris

Anantha Prabu G
Legend
October 26, 2017

Hi Chris,

Try this,

var myPDFExportPreset = app.pdfExportPresets.item("[Smallest File Size]"); // Change myPDFpreset to the name of the preset you want to use

var myDoc = app.activeDocument;

var myFolderName = myDoc.filePath;

//Apply a name to the PDF file based on the INDD file, but without the .indd extension

var myDocumentName =  myDoc.name.slice (0, -5);

var myFilePath = myFolderName + "/" + myDocumentName + ".pdf";

var myFile = new File(myFilePath);

//Do not open the PDF Export dialog box. Set "false" to "true" if you want the dialog box.

myDoc.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);

Thanks,

Prabu G

Design smarter, faster, and bolder with InDesign scripting.
Participant
October 26, 2017

That worked a charm

Thanks so much!

August 26, 2009

Thank you to all for your help.

The script now works great!

Peter Kahrel
Community Expert
Community Expert
August 26, 2009

This line:

pdf = File (String (app.documents[0].fullName).replace (/\.indd$/, ".pdf"));

returns a file object you can export to. Its name is the full path name of the active document with the .indd extension replaced with .pdf.

Peter

interesting_Flower157F
Inspiring
August 26, 2009

This is the script that i use, let me know if you would like the .jsx version so you can edit it.

UI might be in danish, don't remember.

http://www.nobrainer.dk/eksporter-pdf-ved-indesign/

--

Thomas B. Nielsen

http://www.nobrainer.dk

Adobe-InDesign_CS4
Inspiring
August 26, 2009

Dear MN1958,

    I read your msg,

Here get the File path and pass this path in to Export PDF time.

Here the below Script

//========================== Export PDF ================================//

var myDoc = app.activeDocument;

var myDocName = myDoc.name;

var myFolder = myDoc.filePath;

var myBaseName=myDocName.split(".indd")[0];

var t1 = String(myFolder);
var t2= t1.split("/");
for(var i=0; i<t2.length-1; i++)
{
Final  = Final+t2+"/";
}

var ExPDFs= File(Final+myBaseName + ".pdf");
pdfPreset = app.pdfExportPresets.item("Sample");
myDoc.exportFile(ExportFormat.pdfType, ExPDFs, false, pdfPreset);

myDoc.close(SaveOptions.NO);

//========================== End  - Export PDF Script ================================//

Please use the above script and enjoy....

Thanks & Regards

T.R.Harihara SudhaN

August 26, 2009

Thanks for your suggestion, but it did not work.

After tinkering with the script, I came up with a simple solution that does the job:

var myDoc = app.activeDocument;

var myFolderName = myDoc.filePath;

//Apply a name to the PDF file based on the INDD file, but without the .indd extension

var myDocumentName =  myDoc.name.slice (0, -5);

var myFilePath = myFolderName + "/" + myDocumentName + ".pdf";

var myFile = new File(myFilePath);

//Do not open the PDF Export dialog box. Set "false" to "true" if you want the dialog box.

myDoc.exportFile(ExportFormat.pdfType, myFile, false, "Press Quality");

Adobe-InDesign_CS4
Inspiring
August 26, 2009

Hi

  Please another another one time check it out..

//Do not open the PDF Export dialog box. Set "false" to "true" if you want the dialog box.

myDoc.exportFile(ExportFormat.pdfType, myFile, false, "Press Quality");

Instead I used

var ExPDFs= File(Final+myBaseName + ".pdf");
pdfPreset = app.pdfExportPresets.item("Sample");

myDoc.exportFile(ExportFormat.pdfType, ExPDFs, false, pdfPreset);

Here I think u made mistake in "pdfPreset " passing argument...

I used Sample -> PDF Preset name, but u passing PDF Preset is directly [Press Quality]... thats all.

Then how come u say this script is not working....like that?.

I used this script in my Projects U know?.

Please try to reveal and check throughly after that U say the word "Thanks for your suggestion, but it did not work."

"......"

OK.