What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

How to convert multiple jpegs in 1000 folders into 1000 pdfs with one click


Marko1976

Member
Messages
10
Likes
1
Hello

How to convert multiple jpegs in 1000 folders into 1000 pdfs with one click?

I have 1000 folders, every one of them contains 100 images in jpeg format.

I want to have 1000 pdfs, and every one of them must be named after the its own folder, and have 100 pages, made of jpegs from inside of same folder.

Any idea how to make this in photoshop?

Thak you...

Marko
 

Paul MR

The Script Master
Messages
382
Likes
206
You could try this...
Code:
#target photoshop;
app.displayDialogs = DialogModes.NO;
var topLevel = Folder.selectDialog("Please select top level folder"); 
if(topLevel != null ){
var folders =[];
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var z in folders){
Files = folders[z].getFiles("*.jpg");
createPresentation(folders[z]);
Files=[];
    }
}
function createPresentation(Dir){    
    var d = new ActionDescriptor();  
    var list = new ActionList();   
    for(var a=0;a<Files.length;a++) list.putPath(Files[a]);      
    d.putList(stringIDToTypeID("filesList"), list);      
    d.putPath(stringIDToTypeID("to"), new File(Dir + "/" + decodeURI(Dir.name) + ".pdf"));     
    d.putBoolean(stringIDToTypeID("includeAnnotations"), true);   
    d.putEnumerated(stringIDToTypeID("backgroundColor"), stringIDToTypeID("backgroundColor"), stringIDToTypeID("white"));  
    d.putBoolean(stringIDToTypeID("autoAdvance"), true);  
    d.putInteger(stringIDToTypeID("autoAdvanceSeconds"), 5);  
    d.putBoolean(stringIDToTypeID("loop"), true);  
    d.putEnumerated(stringIDToTypeID("transition"), stringIDToTypeID("transition"), stringIDToTypeID("random"));  
    d.putBoolean(stringIDToTypeID("presentation"), true);  
    var d1 = new ActionDescriptor();  
    d1.putString(stringIDToTypeID("pdfPresetFilename"), "High Quality Print");  
    d1.putBoolean(stringIDToTypeID("pdfPreserveEditing"), true);  
    d1.putBoolean(stringIDToTypeID("pdfViewAfterSave"), false);  
    d1.putInteger(stringIDToTypeID("pdfCompressionType"), 7);  
    d.putObject(stringIDToTypeID("as"), stringIDToTypeID("photoshopPDFFormat"), d1);  
    executeAction(stringIDToTypeID("PDFExport"), d, DialogModes.NO);
};
function FindAllFolders( srcFolderStr, destArray) {
    var fileFolderArray = Folder( srcFolderStr ).getFiles();
    for ( var i = 0; i < fileFolderArray.length; i++ ) {
        var fileFoldObj = fileFolderArray[i];
        if ( fileFoldObj instanceof File ) {            
        } else {
         destArray.push( Folder(fileFoldObj) );
        FindAllFolders( fileFoldObj.toString(), destArray );
        }
    }
    return destArray;
}
 

Paul MR

The Script Master
Messages
382
Likes
206
Copy and paste the code into a plain text editor
Save the file with a ".jsx" extension
Copy this file to the relevant folder...
PC:- C:/Program Files/Adobe/Adobe Photoshop CS#/Presets/Scripts/
Mac:- [hard drive]/Applications/Adobe Photoshop CS#/Presets/Scripts/

Restart Photoshop


To use:-
File - scripts - yourFileName.jsx
It will then prompt for you top level folder.
Sit back and watch it go through all the folders creating your pdf's
Good luck.
 

Marko1976

Member
Messages
10
Likes
1
I made it, but when I click on it in Photoshop - file -scripts - It show this:

Screenshot 2020-07-16 at 17.54.05.png

Something wrong when I copy the code?
 

Paul MR

The Script Master
Messages
382
Likes
206
That error is caused by you NOT using a plain text editor! It has put control characters into the file.
Use a text editor that does plain text and you should be good. I am on Windows so do not know what you have to use on a Mac. Maybe someone will jump in and let you know?
 

thebestcpu

Guru
Messages
2,994
Likes
2,760
That error is caused by you NOT using a plain text editor! It has put control characters into the file.
Use a text editor that does plain text and you should be good. I am on Windows so do not know what you have to use on a Mac. Maybe someone will jump in and let you know?
On a Mac the plain text editor is TextEdit
 

Marko1976

Member
Messages
10
Likes
1
Yes, I used Textedit on Mac... Any idea for the solution? Is there any online plain text editor?
 

thebestcpu

Guru
Messages
2,994
Likes
2,760
Note that in Preferences of TextEdit, there is a choice. Try changing preference to "Plain Text" before going after another text editor.
Just a suggestion
John Wheeler

Screen Shot 2020-07-16 at 2.30.01 PM.png
 

Marko1976

Member
Messages
10
Likes
1
Thanx, in the meantime I tried with online editor and it works...

Anyway - the thing is working OK - but there is one error - the pages in the pdf for every file aren't OK - they are somehow mixed - I want to keep the alphabetical/numbered order of scanned pages, maybe some addition to the code is missing for this?

Screenshot 2020-07-16 at 22.32.36.png
 

Marko1976

Member
Messages
10
Likes
1
Just one more thing - I also want to keep the resolution of the fils the same as they are in jpeg... That means, when i zoom in in the pdf, I want the images to be sharp the same as in the jpegs - and if there is an option, the whole pdf file I want it to be the similar or same size as the jpegs combined...

:)

Thank you for help..
 

Paul MR

The Script Master
Messages
382
Likes
206
Photoshop may not be the best to create PDF's Acrobat may be better. There is a forum on Adobe ...
Acrobat forum

I think I have fixed the sort problem and set the quality to maximum (10).
So this is the best I can get :slap:

Here is the new code...
Code:
#target photoshop;
app.displayDialogs = DialogModes.NO;
Array.prototype.humanSort = function() {  
  return this.sort(function(a, b) {
    aa = a.split(/(\d+)/);
    bb = b.split(/(\d+)/);

    for(var x = 0; x < Math.max(aa.length, bb.length); x++) {
      if(aa[x] != bb[x]) {
        var cmp1 = (isNaN(parseInt(aa[x],10)))? aa[x] : parseInt(aa[x],10);
        var cmp2 = (isNaN(parseInt(bb[x],10)))? bb[x] : parseInt(bb[x],10);
        if(cmp1 == undefined || cmp2 == undefined)
          return aa.length - bb.length;
        else
          return (cmp1 < cmp2) ? -1 : 1;
      }
    }
    return 0;
  });
}
var topLevel = Folder.selectDialog("Please select top level folder"); 
if(topLevel != null ){
var folders =[];
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
alert(folders.length);
for(var z =0;z<folders.length;z++){
files = folders[z].getFiles("*.jpg");
filelist=[];
for(var f in files){ filelist.push(decodeURI(files[f])); }
filelist.humanSort();
createPresentation(folders[z]);
files=[];
filelist=[];
    }
}
function createPresentation(Dir){    
    var d = new ActionDescriptor();  
    var list = new ActionList();   
    for(var h=1;h<filelist.length;h++) list.putPath(File(filelist[h]));      
    d.putList(stringIDToTypeID("filesList"), list);      
    d.putPath(stringIDToTypeID("to"), new File(Dir + "/" + decodeURI(Dir.name) + ".pdf"));     
    d.putBoolean(stringIDToTypeID("includeAnnotations"), true);   
    d.putEnumerated(stringIDToTypeID("backgroundColor"), stringIDToTypeID("backgroundColor"), stringIDToTypeID("white"));  
    d.putBoolean(stringIDToTypeID("autoAdvance"), true);  
    d.putInteger(stringIDToTypeID("autoAdvanceSeconds"), 5);  
    d.putBoolean(stringIDToTypeID("loop"), true);  
    d.putEnumerated(stringIDToTypeID("transition"), stringIDToTypeID("transition"), stringIDToTypeID("random"));  
    d.putBoolean(stringIDToTypeID("presentation"), true);  
    var d1 = new ActionDescriptor();  
    d1.putString(stringIDToTypeID("pdfPresetFilename"), "High Quality Print");  
    d1.putBoolean(stringIDToTypeID("pdfPreserveEditing"), true);  
    d1.putBoolean(stringIDToTypeID("pdfViewAfterSave"), false);  
    d1.putInteger(stringIDToTypeID("pdfCompressionType"), 10);  
    d.putObject(stringIDToTypeID("as"), stringIDToTypeID("photoshopPDFFormat"), d1);  
    executeAction(stringIDToTypeID("PDFExport"), d, DialogModes.NO);
};
function FindAllFolders( srcFolderStr, destArray) {
    var fileFolderArray = Folder( srcFolderStr ).getFiles();
    for ( var i = 0; i < fileFolderArray.length; i++ ) {
        var fileFoldObj = fileFolderArray[i];
        if ( fileFoldObj instanceof File ) {            
        } else {
         destArray.push( Folder(fileFoldObj) );
        FindAllFolders( fileFoldObj.toString(), destArray );
        }
    }
    return destArray;
}
 

Marko1976

Member
Messages
10
Likes
1
Thank you - now the order is OK...

Also the size is perfect - small...

So I will use this code when need smal size pdfs...

But sorry to ask - I would also want to have the code for the best possible resolution, like the same which is in jpegs, I want sharpness when zoom, like this:

Thi is original jpeg:

And this is zoomed pdf (it is blured):

I would be very happy if you can make also that one...:)

Marko

Screenshot 2020-07-20 at 08.37.06.png

Screenshot 2020-07-20 at 08.37.25.png
 

Paul MR

The Script Master
Messages
382
Likes
206
I could only find one section that might affect the resolution, and have implimented it in this code, lets hope it works, it suppose to stop downsampling.

Code:
#target photoshop;
app.displayDialogs = DialogModes.NO;
Array.prototype.humanSort = function() {  
  return this.sort(function(a, b) {
    aa = a.split(/(\d+)/);
    bb = b.split(/(\d+)/);

    for(var x = 0; x < Math.max(aa.length, bb.length); x++) {
      if(aa[x] != bb[x]) {
        var cmp1 = (isNaN(parseInt(aa[x],10)))? aa[x] : parseInt(aa[x],10);
        var cmp2 = (isNaN(parseInt(bb[x],10)))? bb[x] : parseInt(bb[x],10);
        if(cmp1 == undefined || cmp2 == undefined)
          return aa.length - bb.length;
        else
          return (cmp1 < cmp2) ? -1 : 1;
      }
    }
    return 0;
  });
}
var topLevel = Folder.selectDialog("Please select top level folder"); 
if(topLevel != null ){
var folders =[];
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var z =0;z<folders.length;z++){
files = folders[z].getFiles("*.jpg");
filelist=[];
for(var f in files){ filelist.push(decodeURI(files[f])); }
filelist.humanSort();
createPresentation(folders[z]);
files=[];
filelist=[];
    }
}
function createPresentation(Dir){    
    var d = new ActionDescriptor();  
    var list = new ActionList();   
    for(var h=1;h<filelist.length;h++) list.putPath(File(filelist[h]));      
    d.putList(stringIDToTypeID("filesList"), list);      
    d.putPath(stringIDToTypeID("to"), new File(Dir + "/" + decodeURI(Dir.name) + ".pdf"));     
    d.putBoolean(stringIDToTypeID("includeAnnotations"), true);   
    d.putEnumerated(stringIDToTypeID("backgroundColor"), stringIDToTypeID("backgroundColor"), stringIDToTypeID("white"));  
    d.putBoolean(stringIDToTypeID("autoAdvance"), true);  
    d.putInteger(stringIDToTypeID("autoAdvanceSeconds"), 5);  
    d.putBoolean(stringIDToTypeID("loop"), true);  
    d.putEnumerated(stringIDToTypeID("transition"), stringIDToTypeID("transition"), stringIDToTypeID("random"));  
    d.putBoolean(stringIDToTypeID("presentation"), true);  
    var d1 = new ActionDescriptor();  
    d1.putString(stringIDToTypeID("pdfPresetFilename"), "High Quality Print");  
    d1.putBoolean(stringIDToTypeID("pdfPreserveEditing"), true);  
    d1.putBoolean(stringIDToTypeID("pdfViewAfterSave"), false);  
    d1.putInteger(stringIDToTypeID("pdfCompressionType"), 10);  
    d1.putEnumerated( stringIDToTypeID( "pdfDownSample" ), stringIDToTypeID( "pdfDownSample" ), charIDToTypeID( "None" ));
    d.putObject(stringIDToTypeID("as"), stringIDToTypeID("photoshopPDFFormat"), d1);  
    executeAction(stringIDToTypeID("PDFExport"), d, DialogModes.NO);
};
function FindAllFolders( srcFolderStr, destArray) {
    var fileFolderArray = Folder( srcFolderStr ).getFiles();
    for ( var i = 0; i < fileFolderArray.length; i++ ) {
        var fileFoldObj = fileFolderArray[i];
        if ( fileFoldObj instanceof File ) {            
        } else {
         destArray.push( Folder(fileFoldObj) );
        FindAllFolders( fileFoldObj.toString(), destArray );
        }
    }
    return destArray;
}
 

Top