Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to combin to scripts

Status
Not open for further replies.

acevans

Technical User
Apr 9, 2003
78
US
I have 2 scripts that I use ALOT. I usually run one right after the other. One turns my illustrator project into the smallest pdf for ease of emailing. Then I run the second one and add the words PRINT before the extension which is high quality with crop marks and bleeds if necessary. Is there a way to combine the 2 into 1 script that will do both?

/**********************************************************

Save as PDFs smalles file size without name.js

DESCRIPTION

This sample gets files specified by the user from the
selected folder and batch processes them and saves them
as PDFs in the user desired destination with the same
file name.

**********************************************************/

// Main Code [Execution of script begins here]

// uncomment to suppress Illustrator warning dialogs
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;

// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PDF', '~' );

// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = "*.ai"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );

// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );

if ( files.length > 0 )
{
// Get the destination to save the files
destFolder = sourceFolder;
for ( i = 0; i < files.length; i++ )
{
sourceDoc = app.open(files); // returns the document object

// Call function getNewName to get the name and file to save the pdf
targetFile = getNewName();

// Call function getPDFOptions get the PDFSaveOptions for the files
pdfSaveOpts = getPDFOptions( );

// Save as pdf
sourceDoc.saveAs( targetFile, pdfSaveOpts );

sourceDoc.close();
}
alert( 'Files are saved as PDF in ' + destFolder );
}
else
{
alert( 'No matching files found' );
}
}

/*********************************************************

getNewName: Function to get the new file name. The primary
name is the same as the source file.

**********************************************************/

function getNewName()
{
var ext, docName, newName, saveInFile, docName;
docName = sourceDoc.name;
ext = '.pdf'; // new extension for pdf file
newName = "";

for ( var i = 0 ; docName != "." ; i++ )
{
newName += docName;
}
newName += ext; // full pdf name of the file

// Create a file object to save the pdf
saveInFile = new File( destFolder + '/' + newName );


return saveInFile;
}

/*********************************************************

getPDFOptions: Function to set the PDF saving options of the
files using the PDFSaveOptions object.

**********************************************************/

function getPDFOptions()
{ var NamePreset = '[Smallest File Size]';

// Create the PDFSaveOptions object to set the PDF options
var pdfSaveOpts = new PDFSaveOptions();

// Setting PDFSaveOptions properties. Please see the JavaScript Reference
// for a description of these properties.
// Add more properties here if you like
pdfSaveOpts.acrobatLayers = true;
pdfSaveOpts.colorBars = false;
pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
pdfSaveOpts.compressArt = true; //default
pdfSaveOpts.embedICCProfile = false;
pdfSaveOpts.enablePlainText = true;
pdfSaveOpts.generateThumbnails = true; // default
pdfSaveOpts.optimization = true;
pdfSaveOpts.pageInformation = false;
pdfSaveOpts.pDFPreset = NamePreset;

// uncomment to view the pdfs after conversion.
// pdfSaveOpts.viewAfterSaving = true;


return pdfSaveOpts;
}


/**********************************************************

Export to PDFs.jsx

DESCRIPTION

This sample gets files specified by the user from the
selected folder and batch processes them and saves them
as PDFs.

Edits by Patrick Mineault:
- only .ai files processed
- files saved in same folder as the input files
- export files have name (oldname)_export.pdf
- PDF settings: non-editable / acrobatLayers=false
for maximum compatibility with Preview

**********************************************************/

// Main Code [Execution of script begins here]

// uncomment to suppress Illustrator warning dialogs
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;

// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator .ai files you want to convert to PDF');

// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = "*.ai"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );

// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );

if ( files.length > 0 )
{
// Get the destination to save the files
//destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PDF files.', '~' );
destFolder = sourceFolder;
for ( i = 0; i < files.length; i++ )
{
sourceDoc = app.open(files); // returns the document object

// Call function getNewName to get the name and file to save the pdf
targetFile = getNewName();

// Call function getPDFOptions get the PDFSaveOptions for the files
pdfSaveOpts = getPDFOptions( );

// Save as pdf
sourceDoc.saveAs( targetFile, pdfSaveOpts );

sourceDoc.close();
}
alert( 'Files are saved as PDF in ' + destFolder );
}
else
{
alert( 'No matching files found' );
}
}

/*********************************************************

getNewName: Function to get the new file name. The primary
name is the same as the source file.

**********************************************************/

function getNewName()
{
var ext, docName, newName, saveInFile, docName;
docName = sourceDoc.name;
ext = ' - PRINT.pdf'; // new extension for pdf file
newName = "";

for ( var i = 0 ; docName != "." ; i++ )
{
newName += docName;
}
newName += ext; // full pdf name of the file

// Create a file object to save the pdf
saveInFile = new File( destFolder + '/' + newName );

return saveInFile;
}

/*********************************************************

getPDFOptions: Function to set the PDF saving options of the
files using the PDFSaveOptions object.

**********************************************************/

function getPDFOptions()
{ var NamePreset = 'Print with Bleeds';

// Create the PDFSaveOptions object to set the PDF options
var pdfSaveOpts = new PDFSaveOptions();

// Setting PDFSaveOptions properties. Please see the JavaScript Reference
// for a description of these properties.
// Add more properties here if you like
pdfSaveOpts.acrobatLayers = true;
pdfSaveOpts.colorBars = false;
pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
pdfSaveOpts.compressArt = true; //default
pdfSaveOpts.embedICCProfile = false;
pdfSaveOpts.enablePlainText = true;
pdfSaveOpts.generateThumbnails = true; // default
pdfSaveOpts.optimization = true;
pdfSaveOpts.pageInformation = true;
pdfSaveOpts.pDFPreset = NamePreset;

// uncomment to view the pdfs after conversion.
// pdfSaveOpts.viewAfterSaving = true;


return pdfSaveOpts;
}
Thanks for all your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top