0

Is there a script or quick shortcut to save a file as a Pdf (as a copy)?

I find myself making small edits to a file, and need to save each change as a separate copy, and it takes 5 steps to save each and every time:

  1. Click save as (there is a shortcut for that)
  2. Uncheck "Layers" which also automatically checks the "As a copy"
  3. select Photoshop PDF from the dropdown (highly annoying to select from the list)
  4. Navigate to the correct path, as for some reason it doesn't save the last path
  5. Click yes to 3 more dialogs that pop up

Does anyone know of any way to do this more efficiently?

1

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()                  
2
  • If you don't change the file name when you're creating the action, it shouldn't be saving that option and just use the default location and file name. The default location and name should be the current folder of the opened file and the original file name with a PDF extension. I take advantage of this feature all the time for batch saving jpeg files. Apr 8 at 19:14
  • @LightBender it's true that one can use File>Automate>Batch.. for dynamic renaming with prefix suffix etc while using action but I'd still prefer above script over action since with just a little modification on script, You can achieve much more dynamic results!
    – Mr.Online
    Apr 11 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.