On a basic level you could've used Actions to automate these steps, there's one issue though: Action would record an absolute path for your pdf, so having something like "save next to my file" isn't really possible. That's where scripts come to rescue.
You can use a ScriptingListener Plugin to record most of the things you do in PS as code. The generated code is quite ugly but it's not very important. For example, Save As Pdf
generates this:
var desc14 = new ActionDescriptor();
var desc15 = new ActionDescriptor();
desc15.putString( stringIDToTypeID('pdfPresetFilename'), "High Quality Print" );
desc15.putInteger( stringIDToTypeID('pdfCompressionType'), 7 );
desc15.putBoolean( stringIDToTypeID('pdfIncludeProfile'), false );
desc14.putObject( charIDToTypeID('As '), charIDToTypeID('PhtP'), desc15 );
desc14.putPath( charIDToTypeID('In '), new File( "D:/my/path/random_name.pdf" ) );
desc14.putInteger( charIDToTypeID('DocI'), 449 );
desc14.putBoolean( charIDToTypeID('Cpy '), true );
desc14.putBoolean( charIDToTypeID('LwCs'), true );
desc14.putBoolean( charIDToTypeID('Lyrs'), false );
desc14.putEnumerated( stringIDToTypeID('saveStage'), stringIDToTypeID('saveStageType'), stringIDToTypeID('saveSucceeded') );
executeAction( charIDToTypeID('save'), desc14, DialogModes.NO );
All the options that I chose during the save command are written here, for example Lyrs
set to false
is "No Layers"
option. Important bit here is this line:
desc14.putPath( charIDToTypeID('In '), new File( "D:/my/path/random_name.pdf" ) );
if we put out string in there we can specify the path ourselves. To get active document path we can use activeDocument.path
and to get it's name — activeDocument.name
.
Full code wrapped in a function:
function main()
{
// aborting if the active document was never saved
try
{
var path = activeDocument.path
}
catch (e)
{
alert("active document isn't saved, aborting");
return false
}
// fileName without extension
var fileName = activeDocument.name.replace(/\.[^.]+$/g, "")
// saving as pdf with the same filename as active doc to the same folder
var desc = new ActionDescriptor();
var descPDF = new ActionDescriptor();
descPDF.putString(stringIDToTypeID('pdfPresetFilename'), "High Quality Print");
descPDF.putInteger(stringIDToTypeID('pdfCompressionType'), 7);
descPDF.putBoolean(stringIDToTypeID('pdfIncludeProfile'), false);
desc.putObject(charIDToTypeID('As '), charIDToTypeID('PhtP'), descPDF);
desc.putPath(charIDToTypeID('In '), new File(path + "/" + fileName + ".pdf"));
desc.putInteger(charIDToTypeID('DocI'), 449);
desc.putBoolean(charIDToTypeID('Cpy '), true);
desc.putBoolean(charIDToTypeID('LwCs'), true);
desc.putBoolean(charIDToTypeID('Lyrs'), false);
desc.putEnumerated(stringIDToTypeID('saveStage'), stringIDToTypeID('saveStageType'), stringIDToTypeID('saveSucceeded'));
executeAction(charIDToTypeID('save'), desc, DialogModes.NO);
}
main()