Images To PDF
Script for Adobe Photoshop
The script reads a folder of images and creates a single PDF with page for each image found in the selected folder.
- Create PDF proofs of images
- Include subfolders
- Choose PDF preset
- Adapt open source to customize or create other scripts
Many scripts are free to download thanks to the support of users. Help me keep developing new scripts by supporting my work. Click any one of the buttons below to make a contribution of any amount. Thank you.
THIS IS AN AD. Beware of anything in the ad artwork that resembles a 'DOWNLOAD' button meant to confuse you into thinking it downloads something from this website. It does not.
How to use the script
The interface has two sections: Input and Output. Set desired options then click the OK button to begin.
Section 1: Input
Folder — select a folder of images that are added to the output PDF.
Include subfolders — if enabled, images in all subfolders are included.
Section 2: Output
PDF preset — the preset used to output the PDF. The list of preset names is compiled by reading the user app data folder / Adobe / Adobe PDF / Settings. The list does not include the built-in PDF presets, only those added by the user. If the list is empty, create a PDF preset configured as desired. If a PDF preset is not selected in the list, the script uses values manually set in the script code, which is well-commented and may be adjusted to suit any user’s needs. See the source code comments for more details.
File — the PDF file to create. Default is the name and location of the input folder, once the input folder is selected. Click the button File... to set a different name and/or select a different location.
Source code
(download button below)
/*
Images To PDF
Copyright 2022 William Campbell
All Rights Reserved
https://www.marspremedia.com/contact
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//@target photoshop
(function () {
app.displayDialogs = DialogModes.ERROR;
var title = "Images To PDF";
// Script variables
var abort;
var filePdf;
var pdfPresetNames;
var working;
// Reusable UI variables
var g; // group
var p; // panel
var w; // window
// Permanent UI variables
var btnCancel;
var btnFileOutput;
var btnFolderInput;
var btnOk;
var cbIncludeSubfolders;
var listPdfPresets;
var txtFileOutput;
var txtFolderInput;
// SETUP
// Get PDF preset names.
pdfPresetNames = loadPdfPresets();
// CREATE WORKING WINDOW
working = new Window("palette", undefined, undefined, {
closeButton: false
});
working.preferredSize = [300, 80];
working.add("statictext");
working.t = working.add("statictext");
working.add("statictext");
working.display = function (message) {
this.t.text = message || "Working... Please wait...";
this.show();
app.refresh();
};
// CREATE USER INTERFACE
w = new Window("dialog", title);
w.alignChildren = "fill";
// Panel 'Input'
p = w.add("panel", undefined, "Input");
p.margins = [24, 18, 18, 18];
p.alignChildren = "left";
g = p.add("group");
btnFolderInput = g.add("button", undefined, "Folder...");
txtFolderInput = g.add("statictext", undefined, "", {
truncate: "middle"
});
txtFolderInput.preferredSize = [250, -1];
cbIncludeSubfolders = p.add("checkbox", undefined, "Include subfolders");
// Panel 'Output'
p = w.add("panel", undefined, "Output");
p.margins = [24, 18, 18, 18];
p.alignChildren = "left";
g = p.add("group");
g.alignment = "left";
g.add("statictext", undefined, "PDF preset:");
listPdfPresets = g.add("dropdownlist", undefined, pdfPresetNames);
g = p.add("group");
btnFileOutput = g.add("button", undefined, "File...");
txtFileOutput = g.add("statictext", undefined, undefined, {
truncate: "middle"
});
txtFileOutput.preferredSize = [250, -1];
// Action buttons
g = w.add("group");
g.alignment = "center";
btnOk = g.add("button", undefined, "OK");
btnCancel = g.add("button", undefined, "Cancel");
// Panel Copyright
p = w.add("panel");
p.add("statictext", undefined, "Copyright 2022 William Campbell");
// UI EVENT HANDLERS
btnFolderInput.onClick = function () {
var f = Folder.selectDialog();
if (f) {
txtFolderInput.text = f.fullName;
filePdf = new File(f.path + "/" + f.name + ".pdf");
txtFileOutput.text = filePdf.fullName;
}
};
btnFileOutput.onClick = function () {
var f;
if (!filePdf) {
alert("Select input folder", " ", false);
return;
}
f = filePdf.saveDlg();
if (f) {
filePdf = f;
txtFileOutput.text = filePdf.fullName;
}
};
btnOk.onClick = function () {
if (!txtFolderInput.text) {
alert("Select input folder", " ", false);
return;
}
if (!txtFileOutput.text) {
alert("Select output file", " ", false);
return;
}
w.close(1);
};
btnCancel.onClick = function () {
w.close(0);
};
// SHOW THE WINDOW
if (w.show() == 1) {
try {
process();
alert(abort || "Done", title, false);
} catch (e) {
alert("An error has occurred.\nLine " + e.line + ": " + e.message, title, true);
}
}
//====================================================================
// END PROGRAM EXECUTION, BEGIN FUNCTIONS
//====================================================================
function getFiles(folder, subfolders, extensions) {
// folder = folder object, not folder name.
// subfolders = true to include subfolders.
// extensions = string, extensions to include.
// Combine multiple extensions with RegExp OR i.e. jpg|psd|tif
// extensions case-insensitive.
// extensions undefined = any.
// Ignores hidden files and folders.
var f;
var files;
var i;
var pattern;
var results = [];
if (extensions) {
pattern = new RegExp("\." + extensions + "$", "i");
} else {
// Any extension.
pattern = new RegExp(
"\.8PBS|AFX|AI|ARW|BLZ|BMP|CAL|CALS|CIN|CR2|CRW|CT|DCM|DCR|DCS|DCX|DDS|" +
"DIB|DIC|DNG|DPX|EPS|EPSF|EXR|FFF|FIF|GIF|HDP|HDR|HEIC|HEIF|ICB|ICN|ICO|" +
"ICON|IIQ|IMG|J2C|J2K|JIF|JIFF|JP2|JPC|JPE|JPEG|JPF|JPG|JPS|JPX|JXR|KDK|" +
"KMZ|KODAK|MOS|MRW|NCR|NEF|ORF|PAT|PBM|PCT|PCX|PDD|PDF|PDP|PEF|PGM|PICT|" +
"PMG|PNG|PPM|PS|PSB|PSD|PSDC|PSID|PVR|PXR|RAF|RAW|RLE|RSR|SCT|SRF|TGA|TIF|" +
"TIFF|TRIF|U3D|VDA|VST|WBMP|WDP|WMP|X3F$", "i");
}
files = folder.getFiles();
for (i = 0; i < files.length; i++) {
f = files[i];
if (!f.hidden) {
if (f instanceof Folder && subfolders) {
// Recursive (function calls itself).
results = results.concat(getFiles(f, subfolders, extensions));
} else if (f instanceof File && pattern.test(f.name)) {
results.push(f);
}
}
}
return results;
}
function loadPdfPresets() {
var files;
var i;
var names;
files = new Folder(Folder.userData + "/Adobe/Adobe PDF/Settings").getFiles("*.joboptions");
names = [];
for (i = 0; i < files.length; i++) {
names.push(File.decode(files[i].name).replace(/\.joboptions$/i, ""));
}
return names;
}
function pdfSaveOptions() {
var o = new PDFSaveOptions();
if (listPdfPresets.selection) {
// Use PDF preset.
o.presetFile = listPdfPresets.selection.text;
} else {
// Set properties using values enabled below.
// o.PDFCompatibility = PDFCompatibility.PDF13;
// o.PDFCompatibility = PDFCompatibility.PDF14;
// o.PDFCompatibility = PDFCompatibility.PDF15;
// o.PDFCompatibility = PDFCompatibility.PDF16;
// o.PDFCompatibility = PDFCompatibility.PDF17;
o.PDFCompatibility = PDFCompatibility.PDF17;
o.PDFStandard = PDFStandard.NONE;
// o.PDFStandard = PDFStandard.PDFX1A2001;
// o.PDFStandard = PDFStandard.PDFX1A2003;
// o.PDFStandard = PDFStandard.PDFX32002;
// o.PDFStandard = PDFStandard.PDFX32003;
// o.PDFStandard = PDFStandard.PDFX42008;
o.colorConversion = true; // convert to destinationProfile
o.description = ""; // description of the save options in use
o.destinationProfile = "sRGB IEC61966-2.1";
// o.downSample = PDFResample.NONE;
// o.downSample = PDFResample.PDFAVERAGE;
// o.downSample = PDFResample.PDFSUBSAMPLE;
o.downSample = PDFResample.PDFBICUBIC;
o.downSampleSize = 150; // pixels per inch desired
o.downSampleSizeLimit = 150; // only images pixels per inch greater than this value
o.embedColorProfile = false;
o.embedThumbnail = true;
// o.encoding = PDFEncoding.NONE;
// o.encoding = PDFEncoding.PDFZIP;
o.encoding = PDFEncoding.JPEG;
// o.encoding = PDFEncoding.PDFZIP4BIT;
// o.encoding = PDFEncoding.JPEGHIGH;
// o.encoding = PDFEncoding.JPEGMEDHIGH;
// o.encoding = PDFEncoding.JPEGMED;
// o.encoding = PDFEncoding.JPEGMEDLOW;
// o.encoding = PDFEncoding.JPEGLOW;
// o.encoding = PDFEncoding.JPEG2000HIGH;
// o.encoding = PDFEncoding.JPEG2000MEDHIGH;
// o.encoding = PDFEncoding.JPEG2000MED;
// o.encoding = PDFEncoding.JPEG2000MEDLOW;
// o.encoding = PDFEncoding.JPEG2000LOW;
// o.encoding = PDFEncoding.JPEG2000LOSSLESS;
o.jpegQuality = 8; // range 0 to 12
o.optimizeForWeb = true;
// o.tileSize = null; // integer value JPEG2000 compression only
}
// These properties set either way.
o.alphaChannels = false;
o.annotations = false;
o.convertToEightBit = true;
o.layers = false;
o.preserveEditing = false; // true retains Photoshop data
o.spotColors = false;
o.view = false; // true opens PDF in Acrobat after saving it
return o;
}
function presentationOptions() {
var o = new PresentationOptions();
o.PDFFileOptions = pdfSaveOptions();
o.presentation = false;
// Remainder have no effect when presentation is false
if (o.presentation) {
o.autoAdvance = true;
o.includeFilename = false;
o.interval = 5;
o.loop = false;
// o.magnification = MagnificationType.ACTUALSIZE;
o.magnification = MagnificationType.FITPAGE;
// o.transistion = TransitionType.BLINDSHORIZONTAL;
// o.transistion = TransitionType.BLINDSVERTICAL;
// o.transistion = TransitionType.DISSOLVE;
// o.transistion = TransitionType.BOXIN;
// o.transistion = TransitionType.BOXOUT;
// o.transistion = TransitionType.GLITTERDOWN;
// o.transistion = TransitionType.GLITTERRIGHT;
// o.transistion = TransitionType.GLITTERRIGHTDOWN;
o.transistion = TransitionType.NONE;
// o.transistion = TransitionType.RANDOM;
// o.transistion = TransitionType.SPLITHORIZONTALIN;
// o.transistion = TransitionType.SPLITHORIZONTALOUT;
// o.transistion = TransitionType.SPLITVERTICALIN;
// o.transistion = TransitionType.SPLITVERTICALOUT;
// o.transistion = TransitionType.WIPEDOWN;
// o.transistion = TransitionType.WIPELEFT;
// o.transistion = TransitionType.WIPERIGHT;
// o.transistion = TransitionType.WIPEUP;
}
return o;
}
function process() {
var files;
app.displayDialogs = DialogModes.NO;
working.display();
try {
// Get files in folder.
files = getFiles(new Folder(txtFolderInput.text), cbIncludeSubfolders.value);
if (!files.length) {
abort = "No files found in selected folder";
return;
}
// Make presentation (multi-page PDF of the images)
app.makePDFPresentation(files, filePdf, presentationOptions());
} finally {
working.close();
app.displayDialogs = DialogModes.ERROR;
}
}
})();
Images To PDF
License details included in download
For help installing scripts, see How to Install and Use Scripts in Adobe Creative Cloud Applications.
Also available for hire to program custom solutions. Contact William for more information.
IMPORTANT: by downloading any of the scripts on this page you agree that the software is provided without any warranty, express or implied. USE AT YOUR OWN RISK. Always make backups of important data.