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

New To ExtendScript

Guest
Oct 26, 2016 Oct 26, 2016

I am new to ExtendScript. Im still trying to wrap my mind around the Indesign Object Model among other things. Im just fiddling around here trying to do simple tasks. Im having trouble exporting a pdf. Can anyone help me troubleshoot this script?

Main();

// If you want the script to be un-doable, comment out the line above, and remove the comment from the line below

// app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");

function Main() {

  // Check to see whether any InDesign documents are open.

  // If no documents are open, display an error message.

  if (app.documents.length > 0) {

  var myDoc = app.activeDocument;

         myDoc.asynchronousExportFile(PDF,/Users/greer/Desktop/test.pdf,false,SmallestFileSize);

  // Do something here

  alert("Finished!");

  }

  else {

  // No documents are open, so display an error message.

  alert("No InDesign documents are open. Please open a document and try again.");

  }

}

TOPICS
Scripting
640
Translate
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
Guide ,
Oct 27, 2016 Oct 27, 2016

HI,

Line11 is wrong.. have to use quotes for path..please look the below thread..so you got some ideas how to perform

Re: cancelTask() & cancelAllTask()

Script only runs in the Extendscript toolkit

Re: Download PDF Document

Translate
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
Advisor ,
Oct 27, 2016 Oct 27, 2016

Here's a tid bit i came across on here. It will allow you to define your Presets and location.

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

var myFileLocation = Folder.selectDialog("/Volumes/"); // Change this to your FOlder location

    myFolder = new Folder ([myFileLocation]);

    myFolderContents = myFolder.getFiles("*.indd"); // array

    myFileAmount = (myFolderContents.length - 1);

    // ===== Open, Export as PDF, and Close files ===== \\ 

    for (i = myFileAmount; i >= 0; i--)

    { 

    app.open(File (myFolderContents));

    app.activeDocument.exportFile(

      ExportFormat.pdfType, 

      new File(myFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0] + ".pdf"),

      false, 

      myPDFExportPreset

      );

    app.activeDocument.close(SaveOptions.no);

    } 

Translate
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 ,
Oct 27, 2016 Oct 27, 2016
LATEST

The problem is that you use strings for the document and the preset, where you should use file and preset objects. The correct form of your export statement is as follows:

myDoc.asynchronousExportFile (ExportFormat.PDF_TYPE, File ('/Users/greer/Desktop/test.pdf'), false, app.pdfExportPresets.item('[Smallest File Size]'))

Peter

Translate
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