PDF - > TIF 150PPP批处理脚本

时间:2013-06-28 11:41:49

标签: javascript batch-file photoshop

我在制作用于批量转换pdf到150ppp TIF文件的photoshop脚本时遇到了一些问题。任何人都可以帮我解决这个问题吗?

这是我目前的代码:

//  Auto 150PPP PDF -> TIFF
//  info: Converts PDFs to 150PPP TIFS


//----------------------------------------------------INIT0----------------------------------------------------

// enable double clicking from the 
// Macintosh Finder or the Windows Explorer
#target photoshop

// brings PS to the front
app.bringToFront();

//----------------------------------------------------SETUP----------------------------------------------------

// A list of file extensions to skip, keep them lower case
    gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" );

//input folder
    var inputFolder = Folder.selectDialog("Directorio de entrada");

//output folder
    var outputFolder = Folder.selectDialog("Directorio de salida");

//----------------------------------------------------MAIN----------------------------------------------------
//opens Input dir
    OpenFolder();

// show the path to an output folder (debug)
// alert(outputFolder);

function OpenFolder() {
        var filesOpened = 0;
        var fileList = inputFolder.getFiles();
        for ( var i = 0; i < fileList.length; i++ ) {
                //testing PS file compatibility
                if ( fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese( fileList[i], gFilesToSkip )) {
                        open( fileList[i] );
                        filesOpened++;

                        //------------------------------------OPERATIONS------------------------------------

                        //debug
                        alert(outputFolder);
                        alert(fileList[i]);

                        //just getting filename w/o extension
                        //var fileNameNoExtension = docRef.name;
                        //var docRef = activeDocument;
                        //fileNameNoExtension = fileNameNoExtension.split( "." );
                        //if ( fileNameNoExtension.length > 1 ) {
                        //fileNameNoExtension.length--;
                        //}
                        //fileNameNoExtension = fileNameNoExtension.join(".");
                        //
                        //var fileNameWithoutExtension = fileList[i].split('.').pop();

                        //var currentFile = fileList[i]
                        //var fileNameWithoutExtension = currentFile.substr(0, file.lastIndexOf('.'));

                        app.displayDialogs = DialogModes.NO;

                        //-------------------- Opens current input file
                        var id5 = charIDToTypeID( "Opn " );
                            var desc2 = new ActionDescriptor();
                            var id6 = charIDToTypeID( "As  " );
                                var desc3 = new ActionDescriptor();
                                var id7 = charIDToTypeID( "Nm  " );
                                desc3.putString( id7, fileList[i] );
                                var id8 = charIDToTypeID( "Crop" );
                                var id9 = stringIDToTypeID( "cropTo" );
                                var id10 = stringIDToTypeID( "boundingBox" );
                                desc3.putEnumerated( id8, id9, id10 );
                                var id11 = charIDToTypeID( "Rslt" );
                                var id12 = charIDToTypeID( "#Rsl" );
                                desc3.putUnitDouble( id11, id12, 150.000000 );
                                var id13 = charIDToTypeID( "Md  " );
                                var id14 = charIDToTypeID( "ClrS" );
                                var id15 = charIDToTypeID( "ECMY" );
                                desc3.putEnumerated( id13, id14, id15 );
                                var id16 = charIDToTypeID( "Dpth" );
                                desc3.putInteger( id16, 8 );
                                var id17 = charIDToTypeID( "AntA" );
                                desc3.putBoolean( id17, true );
                                var id18 = stringIDToTypeID( "suppressWarnings" );
                                desc3.putBoolean( id18, false );
                                var id19 = charIDToTypeID( "fsel" );
                                var id20 = stringIDToTypeID( "pdfSelection" );
                                var id21 = stringIDToTypeID( "page" );
                                desc3.putEnumerated( id19, id20, id21 );
                                var id22 = charIDToTypeID( "PgNm" );
                                desc3.putInteger( id22, 1 );
                            var id23 = charIDToTypeID( "PDFG" );
                            desc2.putObject( id6, id23, desc3 );
                            var id24 = charIDToTypeID( "null" );
                            desc2.putPath( id24, new File( fileList[i] ) );
                        executeAction( id5, desc2, DialogModes.NO );

                        //-------------------- Saves current input file
                        var id25 = charIDToTypeID( "save" );
                            var desc4 = new ActionDescriptor();
                            var id26 = charIDToTypeID( "As  " );
                                var desc5 = new ActionDescriptor();
                                var id27 = charIDToTypeID( "BytO" );
                                var id28 = charIDToTypeID( "Pltf" );
                                var id29 = charIDToTypeID( "IBMP" );
                                desc5.putEnumerated( id27, id28, id29 );
                                var id30 = charIDToTypeID( "LZWC" );
                                desc5.putBoolean( id30, true );
                            var id31 = charIDToTypeID( "TIFF" );
                            desc4.putObject( id26, id31, desc5 );
                            var id32 = charIDToTypeID( "In  " );
                            desc4.putPath( id32, new File( outputFolder ) );
                            var id33 = charIDToTypeID( "Cpy " );
                            desc4.putBoolean( id33, true );
                            var id34 = charIDToTypeID( "Lyrs" );
                            desc4.putBoolean( id34, false );
                            var id35 = charIDToTypeID( "EmbP" );
                            desc4.putBoolean( id35, false );
                        executeAction( id25, desc4, DialogModes.NO );

                        // =======================================================
                        var id36 = charIDToTypeID( "Cls " );
                            var desc6 = new ActionDescriptor();
                            var id37 = charIDToTypeID( "Svng" );
                            var id38 = charIDToTypeID( "YsN " );
                            var id39 = charIDToTypeID( "N   " );
                            desc6.putEnumerated( id37, id38, id39 );
                        executeAction( id36, desc6, DialogModes.NO );

                        // Alert and show the document name
                        //alert(app.activeDocument.name);

                        // Cloes the file without saving
                        //app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

                }

        }
        return filesOpened;
}

//----------------------------------------------------FUNC----------------------------------------------------

//check the compatibility of a given input file
function IsFileOneOfThese( inFileName, inArrayOfFileExtensions ) {
    var lastDot = inFileName.toString().lastIndexOf( "." );
    if ( lastDot == -1 ) {
        return false;
    }
    var strLength = inFileName.toString().length;
    var extension = inFileName.toString().substr( lastDot + 1, strLength - lastDot );
    extension = extension.toLowerCase();
    for (var i = 0; i < inArrayOfFileExtensions.length; i++ ) {
        if ( extension == inArrayOfFileExtensions[i] ) {
            return true;
        }
    }
    return false;
}

提前致谢!

wtf代表着“你的帖子主要是代码......等等等等”的预先要求?哈哈,我不知道还有什么可以解释的。我认为帖子很明确,但如果不是让我知道的话。

1 个答案:

答案 0 :(得分:0)

为什么要与VBS等挣扎?

这样的事情怎么样?

@rem  PDF2TIFF.cmd
@echo off
setlocal
for %%i in (*.pdf) do call :convert "%%~i"
endlocal
goto :EOF

:convert
set cn=%~n1
gswin32c -sDEVICE=pdfwrite -dSAFER -o %cn%.%%02d.pdf "%~1"|gsar -F -ud
@if errorlevel 1 @goto CrashMeNow
for %%e in (%cn%.??.pdf) do @set last=%%e
del %last%
del "%~1"
nconvert -o %cn%.tif -out tiff -rmeta -xall -multi -c 2 -dpi 150 -grey 8 -floyd -sharpen 20 -D -v %cn%*.pdf
@if errorlevel 1 @goto CrashMeNow
goto :EOF

:CrashMeNow
@echo %date% %time%  Intentionally terminating %0 ...
endlocal
exit /b 255

你需要下载GhostScript和NConvert,两者都是免费软件。