PDFs With Password

Script for Adobe Illustrator

Batch convert art and images to password-protected PDFs.

  • Creates PDFs from vector art or raster images
  • Variation available to disallow print, edit, or copy
  • Adapt open source to customize or create other scripts
Download
PDFs With Password

Download
PDFs No Print Or Edit

FREE to download
Please make a contribution

Many scripts are free to download thanks to the support of users. Help me keep developing new scripts by supporting my work. Click the button to make a contribution of any amount. Thank you.

How-to Video

How to use the script

Choose a folder of Illustrator files or raster images, and choose a folder to which PDFs are output. Select a PDF preset, and enter the desired password. Click the OK button to proceed. The original version of the script applies the password entered to each PDF saved to the output folder. Without the password, the PDFs cannot be opened and viewed. A variation of the script has security options set to allow viewing, but prevent printing, editing, or copying any content of the PDFs.

Input Folder — select the desired folder to process, which may contain Illustrator artwork or raster images. The script recognizes the extensions ai, eps, gif, jpg, jpeg, pdf, png, psd, tif, and tiff. The script may be edited to recognize others.

Output Folder — the folder to which PDFs are saved.

PDF preset — the PDF preset to use when saving PDFs.

Password — the password required to open the PDFs output by the script, or for the variation of the script, password required to enable print, edit, or copy.

Multi-page PDF

The script saves a separate PDF for each input file. To have all in a single PDF file, use Acrobat to combine the PDFs. However, be sure in the script to leave the password input blank. Otherwise the password must be entered repeatedly, once for every single-page PDFs as they are combined, and once combined, the result does not inherit the prior security anyway. Save yourself the headache and leave the password blank. Then combine PDFs in Acrobat. Go to the File menu, Create, and select Combine Files into a Single PDF. In addition, Windows users may select the desired PDFs in File Explorer, right-click, and choose Combine files in Acrobat. Then use Acrobat to set the desired security options and password. Go to the File menu, Properties, and select the Security tab. Change the Security Method to Password Security. In the dialog window that opens, set the security options and password as desired, which are then in force once the PDF is saved.

Source code

(download button below)

/*

PDFs With Password
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.

*/

(function () {

    var title = "PDFs With Password";

    if (!/illustrator/i.test(app.name)) {
        alert("Script for Illustrator", title, false);
        return;
    }

    // Script variables.
    var doneMessage;
    var error;
    var pdfPreset;
    var progress;

    // Reusable UI variables.
    var g; // group
    var p; // panel
    var w; // window

    // Permanent UI variables.
    var btnCancel;
    var btnFolderInput;
    var btnFolderOutput;
    var btnOk;
    var inpPassword;
    var listPdfPresets;
    var txtFolderInput;
    var txtFolderOutput;

    // CREATE PROGRESS WINDOW

    progress = new Window("palette", "Progress", undefined, {
        "closeButton": false
    });
    progress.t = progress.add("statictext");
    progress.t.preferredSize = [450, -1];
    progress.b = progress.add("progressbar");
    progress.b.preferredSize = [450, -1];
    progress.display = function (message) {
        message && (this.t.text = message);
        this.show();
        this.update();
    };
    progress.increment = function () {
        this.b.value++;
    };
    progress.set = function (steps) {
        this.b.value = 0;
        this.b.minvalue = 0;
        this.b.maxvalue = steps;
    };

    // 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];
    g = p.add("group");
    btnFolderInput = g.add("button", undefined, "Folder...");
    txtFolderInput = g.add("statictext", undefined, "", {
        truncate: "middle"
    });
    txtFolderInput.preferredSize = [350, -1];

    // Panel 'Output'
    p = w.add("panel", undefined, "Output");
    p.margins = [24, 18, 18, 18];
    g = p.add("group");
    btnFolderOutput = g.add("button", undefined, "Folder...");
    txtFolderOutput = g.add("statictext", undefined, "", {
        truncate: "middle"
    });
    txtFolderOutput.preferredSize = [350, -1];

    // Panel 'Options'
    p = w.add("panel", undefined, "Options");
    p.margins = [24, 18, 18, 18];
    g = p.add("group");
    g.alignment = "left";
    g.add("statictext", undefined, "PDF preset:");
    listPdfPresets = g.add("dropdownlist", undefined, app.PDFPresetsList);
    g = p.add("group");
    g.alignment = "left";
    g.margins = [7, 0, 0, 0];
    g.add("statictext", undefined, "Password:");
    inpPassword = g.add("edittext");
    inpPassword.preferredSize = [195, -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;
        }
    };

    btnFolderOutput.onClick = function () {
        var f = Folder.selectDialog();
        if (f) {
            txtFolderOutput.text = f.fullName;
        }
    };

    btnOk.onClick = function () {
        if (!txtFolderInput.text) {
            alert("Select input folder", " ", false);
            return;
        }
        if (!txtFolderOutput.text) {
            alert("Select output folder", " ", false);
            return;
        }
        if (!listPdfPresets.selection) {
            alert("Select a PDF preset", " ", false);
            return;
        }
        w.close(1);
    };

    btnCancel.onClick = function () {
        w.close(0);
    };

    // SHOW THE WINDOW

    if (w.show() == 1) {
        doneMessage = "";
        try {
            process();
            doneMessage = doneMessage || "Done";
        } catch (e) {
            error = error || e;
            doneMessage = "An error has occurred.\nLine " + error.line + ": " + error.message;
        }
        progress.close();
        doneMessage && alert(doneMessage, title, error);
    }

    //====================================================================
    //               END PROGRAM EXECUTION, BEGIN FUNCTIONS
    //====================================================================

    function process() {
        var files;
        var i;
        // Ignore messages when opening documents.
        app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
        progress.display("Reading folder...");
        try {
            // Get files in folder.
            files = new Folder(txtFolderInput.text).getFiles(function (f) {
                if (f instanceof File && !f.hidden) {
                    if (/\.ai|eps|gif|jpg|jpeg|pdf|png|psd|tif|tiff$/i.test(f.name)) {
                        return true;
                    }
                }
                return false;
            });
            if (!files.length) {
                doneMessage = "No files found in selected folder";
                return;
            }
            progress.set(files.length);
            // Get PDF preset to use.
            pdfPreset = listPdfPresets.selection.text;
            // Loop through files array.
            for (i = 0; i < files.length; i++) {
                progress.display(File.decode(files[i].name));
                processFile(files[i]);
                progress.increment();
            }
        } finally {
            app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;
        }
    }

    function processFile(file) {
        var doc;
        var filePdf;
        var saveOptions;
        doc = app.open(file);
        try {
            // IS INPUT FILE AN IMAGE?
            // If so, set artboard to its size.
            // PSD the artboard is set correctly so don't include here.
            if (/\.gif|jpg|jpeg|png|tif|tiff$/i.test(file.name)) {
                doc.artboards[0].artboardRect = doc.pageItems[0].geometricBounds;
            }
            if (/\.eps$/i.test(file.name)) {
                // EPS could be raster or vector.
                // Raster will be one group with one image.
                if (doc.groupItems.length == 1) {
                    if (doc.groupItems[0].rasterItems.length == 1) {
                        doc.artboards[0].artboardRect = doc.groupItems[0].rasterItems[0].geometricBounds;
                    }
                }
            }

            // SAVE PDF

            filePdf = new File(txtFolderOutput.text + "/" + file.name.replace(/\.[^\.]*$/, "") + ".pdf");
            saveOptions = new PDFSaveOptions();
            saveOptions.pDFPreset = pdfPreset;
            // Above sets most options from the selected PDF preset.
            // Here are some other properties. Set as desired.
            saveOptions.preserveEditability = false;
            saveOptions.viewAfterSaving = false;

            // SECURITY OPTIONS

            if (inpPassword.text) {
                // Require a password to open the document.
                saveOptions.requireDocumentPassword = true;
                // A password string to open the document.
                // *** Uncomment if above is 'true' Comment to disable if above is 'false'
                saveOptions.documentPassword = inpPassword.text;
            }

            // ================= IMPORTANT NOTE ==================
            // When using 'document password' (above),
            // the remaining properties have no effect.
            // To instead use 'permission password' (below),
            // enable it and disable document password (above).
            // Then the remaining options are applied to the PDF.
            // ====================================================

            if (inpPassword.text) {
                // Use a password to restrict editing security settings.
                saveOptions.requirePermissionPassword = false;
                // A password string to restrict editing security settings.
                // *** Uncomment if above is 'true'; Comment to disable if above is 'false'
                // saveOptions.permissionPassword = inpPassword.text;
            }

            // PDF security printing permission.
            // *** Uncomment desired choice, leave others commented to
            // *** disable, OR comment all to ignore and use default.
            // *** To disallow printing, choose 'PRINT128NONE'
            // *** (choices 40 vs 128 is the bits encryption; use 128)
            saveOptions.pDFAllowPrinting = PDFPrintAllowedEnum.PRINT128HIGHRESOLUTION;
            // saveOptions.pDFAllowPrinting = PDFPrintAllowedEnum.PRINT128LOWRESOLUTION
            // saveOptions.pDFAllowPrinting = PDFPrintAllowedEnum.PRINT128NONE
            // saveOptions.pDFAllowPrinting = PDFPrintAllowedEnum.PRINT40HIGHRESOLUTION
            // saveOptions.pDFAllowPrinting = PDFPrintAllowedEnum.PRINT40NONE

            // PDF security changes allowed.
            // *** Uncomment desired choice, leave others commented to
            // *** disable, OR comment all to ignore and use default.
            // *** To disallow changes, choose 'CHANGE128NONE'
            // *** (choices 40 vs 128 is the bits encryption; use 128)
            saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE128ANYCHANGES;
            // saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE128COMMENTING
            // saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE128EDITPAGE
            // saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE128FILLFORM
            // saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE128NONE
            // saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE40ANYCHANGES
            // saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE40COMMENTING
            // saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE40NONE
            // saveOptions.pDFChangesAllowed = PDFChangesAllowedEnum.CHANGE40PAGELAYOUT

            // *** Remaining properties are optional. Set true or false
            // *** as desired, or comment any to ignore and use default.
            // Enable copying of text 128-bit.
            saveOptions.enableCopy = true;
            // Enable accessing 128-bit.
            saveOptions.enableAccess = true;

            // SAVE AS PDF
            doc.saveAs(filePdf, saveOptions);
        } finally {
            doc.close(SaveOptions.DONOTSAVECHANGES);
        }
    }

})();
Many scripts are free to download thanks to the support of users. Help me keep developing new scripts by supporting my work. Click the button to make a contribution of any amount. Thank you.
Download
PDFs With Password
Download
PDFs No Print Or Edit

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.