Skip to content

Instantly share code, notes, and snippets.

@nukleas
Created May 4, 2012 20:20
Show Gist options
  • Save nukleas/2597470 to your computer and use it in GitHub Desktop.
Save nukleas/2597470 to your computer and use it in GitHub Desktop.
inCopy Instant PDF Export
//Instant PDF Export
//Written by Nukleas
//
//
myStory = app.activeDocument.name; // Pulls the name of the document
myStory = myStory.split(/[\s.]+/); // Trims the stuff after the . or spaces, which is usually junk like [Pr] or .icml
app.layoutPDFExportPreferences.viewPDF = true //Force view PDF after export (Galley)
app.galleyPDFExportPreferences.viewPDF = true //Force view PDF after export (Galley)
myTypeNumber=app.documents.item(0).windows.item(0).viewTab; //This checks which view tab (Galley, Story, Layout) and sets that value to myTypeNumber
if(myTypeNumber==1699504505){// If it's layout, (The data comes in as a number. It's somewhere in the Help...Object Model Viewer, and don't ask me how they decided that.) then
myType="layout"; //Add "layout" to the filename.
}
else{
myType="galley"; // or else you're in Story or Galley view, so it'll be called "galley"
}
myFilePath="/"+myStory[0]+"-"+myType+".pdf"; // Sets up filepath. You can edit the beginning part if you have a certain locale you want to keep your PDFs
var pdfFile = new File(myFilePath);
document.exportFile(ExportFormat.PDF_TYPE, pdfFile); //And Finally, Export!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment