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

Can anyone write me a Photoshop Script to incremental save a PDF.

Explorer ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

Hi I often use scripts to save out PNGs or JPGs from actions that will save a incremental number each time a save occoures.. so if I have a document open and run the save it is docName_000 at the end.. if I save again it is docName_001.

 

These are the setting I use in the PDF file...

Untitled-1.jpg

Here is my current PNG Incremental Save Script

 

var saveFolder = new Folder( "d:\\pathto\\SaveDir" );
var saveExt = 'png';  
var saveSufixStart = '_';  
var saveSufixLength = 3;  
// End of user options   
  
var docName = decodeURI ( activeDocument.name );  
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];  
var saveName = docName[ 1 ]; // activeDocument name with out ext  
var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix  
  
var saveNumber = files.length + 1;  
//alert("New file number: " + zeroPad( saveNumber, saveSufixLength ));  
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );  
saveAsPNG(saveFile, 9);  
  
function zeroPad ( num, digit ) {   
   var tmp = num.toString();   
   while (tmp.length < digit) { tmp = "0" + tmp;}   
   return tmp;  
}

function saveAsPNG(saveFile, quality) { 
    pngOpts = new PNGSaveOptions();
    pngOpts.compression = quality; //0-9
    pngOpts.interlaced = false;
    activeDocument.saveAs(File(saveFile), pngOpts, true); 
}

Thanks.. I hope one of the more skilled peeps around here will be able to revamp this script to incrmental save a PDF file using the provided setting.

 

Thanks in advance

--Me

TOPICS
Actions and scripting , Windows

Views

124

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Oct 28, 2022 Oct 28, 2022

@abUSER23 – Please test with care and compare to your manual saves to ensure that all settings are correct:

 

var saveFolder = new Folder( "d:\\pathto\\SaveDir" );
var saveExt = 'pdf';  
var saveSufixStart = '_';  
var saveSufixLength = 3;  
// End of user options   
  
var docName = decodeURI ( activeDocument.name );  
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];  
var saveName = docName[ 1 ]; // activeDoc
...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 28, 2022 Oct 28, 2022

Copy link to clipboard

Copied

LATEST

@abUSER23 – Please test with care and compare to your manual saves to ensure that all settings are correct:

 

var saveFolder = new Folder( "d:\\pathto\\SaveDir" );
var saveExt = 'pdf';  
var saveSufixStart = '_';  
var saveSufixLength = 3;  
// End of user options   
  
var docName = decodeURI ( activeDocument.name );  
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];  
var saveName = docName[ 1 ]; // activeDocument name with out ext  
var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix  
  
var saveNumber = files.length + 1;  
//alert("New file number: " + zeroPad( saveNumber, saveSufixLength ));  
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );  
saveAsPDF("High Quality Print", false, false, 7, "U.S. Web Coated (SWOP) v2", false, "CGATS TR 001", saveFile, true, true, false, false); 
  
function zeroPad ( num, digit ) {   
   var tmp = num.toString();   
   while (tmp.length < digit) { tmp = "0" + tmp;}   
   return tmp;  
}

function saveAsPDF(pdfPresetFilename, pdfPreserveEditing, pdfOptimizeForWeb, pdfCompressionType, pdfDestinationProfileDescription, pdfIncludeProfile, pdfOutputConditionIdentifier, in2, copy, lowerCase, layers, embedProfiles) {
	function s2t(s) {
        return app.stringIDToTypeID(s);
    }
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	descriptor2.putString( s2t( "pdfPresetFilename" ), pdfPresetFilename );
	descriptor2.putBoolean( s2t( "pdfPreserveEditing" ), pdfPreserveEditing );
	descriptor2.putBoolean( s2t( "pdfOptimizeForWeb" ), pdfOptimizeForWeb );
	descriptor2.putEnumerated( s2t( "pdfDownSample" ), s2t( "pdfDownSample" ), s2t( "none" ));
	descriptor2.putInteger( s2t( "pdfCompressionType" ), pdfCompressionType );
	descriptor2.putEnumerated( s2t( "pdfColorConversion" ), s2t( "pdfColorConversion" ), s2t( "name" ));
	descriptor2.putString( s2t( "pdfDestinationProfileDescription" ), pdfDestinationProfileDescription );
	descriptor2.putBoolean( s2t( "pdfIncludeProfile" ), pdfIncludeProfile );
	descriptor2.putString( s2t( "pdfOutputConditionIdentifier" ), pdfOutputConditionIdentifier );
	descriptor.putObject( s2t( "as" ), s2t( "photoshopPDFFormat" ), descriptor2 );
	descriptor.putPath( s2t( "in" ), in2 );
	descriptor.putInteger( s2t( "documentID" ), 862 );
	descriptor.putBoolean( s2t( "copy" ), copy );
	descriptor.putBoolean( s2t( "lowerCase" ), lowerCase );
	descriptor.putBoolean( s2t( "layers" ), layers );
	descriptor.putBoolean( s2t( "embedProfiles" ), embedProfiles );
	descriptor.putEnumerated( s2t( "saveStage" ), s2t( "saveStageType" ), s2t( "saveSucceeded" ));
	executeAction( s2t( "save" ), descriptor, DialogModes.NO );
}

 

Votes

Translate

Translate

Report

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