PDF Proof

JavaScript for Adobe InDesign

The purpose of the script is twofold:

1. Export a proof PDF of an InDesign document. Not that it’s tough to do without a script, using PDF Presets, but I wanted the exported file named a particular way for proofs, and always named the same way. I got tired of doing it manually each time.

2. Share this tool of convenience (and consistency) with other users. If you want proofs named differently, it’s easy to edit this simple script so it names exported PDFs however suits your needs. The script also serves as a template to create other scripts that export PDFs of InDesign documents. The script can export using different properties by altering the process() function, where all PDF Export Preference properties are listed. Also, further options are easily added to the interface.

  • Choice of resolution
  • Pages or spreads
  • Adds suffix “_proof” to PDF file name
  • Replaces spaces with underscores to make file name web-friendly
  • Adapt open source to create other scripts
PDF Proof screen
Download
PDF Proof

You decide. Reward the author an
amount the solution is worth to you.

Instructions for use

The interface is single section with two options: a choice of Resolution, and the choice Pages or Spreads. Set the desired resolution, and whether to export in pages or in spreads, then click the OK button to begin. The PDF is exported in the background. That’s all there is to it.

Source code

(download button below)

/*
PDF Proof
Copyright 2021 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 indesign

(function () {

    var title = "PDF Proof";

    // Script variables.
    var doc;
    var i;

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

    // Permanent UI variables.
    var btnCancel;
    var btnOk;
    var rb072;
    var rb096;
    var rb120;
    var rb150;
    var rbPages;
    var rbSpreads;

    // SETUP

    // Check for valid doc.
    if (!app.documents.length) {
        alert("Open a document.", title, false);
        return;
    }
    doc = app.activeDocument;
    if (!doc.saved) {
        // Doc is untitled or converted.
        alert("Save document first.", title, false);
        return;
    }
    // Check for overset text.
    for (i = 0; i < doc.stories.length; i++) {
        if (doc.stories[i].overflows) {
            if (!confirm("Document contains overset text.\nContinue?", true, title)) {
                return;
            }
            break;
        }
    }
    // Check for links missing or modified.
    for (i = 0; i < doc.links.length; i++) {
        if (doc.links[i].status !== LinkStatus.NORMAL) {
            if (!confirm("Links are missing or modified.\nContinue?", true, title)) {
                return;
            }
            break;
        }
    }

    // CREATE USER INTERFACE

    w = new Window("dialog", title);
    w.alignChildren = "fill";

    // Options.
    p = w.add("panel");
    p.alignChildren = "center";
    p.margins = [24, 24, 24, 18];
    p.spacing = 24;
    // Resolution.
    g = p.add("group");
    g.margins = [0, -3, 0, 0];
    g.add("statictext", undefined, "Resolution:");
    g = g.add("group");
    g.margins = [0, 3, 0, 0];
    rb072 = g.add("radiobutton", undefined, "72");
    rb096 = g.add("radiobutton", undefined, "96");
    rb120 = g.add("radiobutton", undefined, "120");
    rb150 = g.add("radiobutton", undefined, "150");
    // Pages or spreads.
    g = p.add("group");
    rbPages = g.add("radiobutton", undefined, "Pages");
    rbSpreads = g.add("radiobutton", undefined, "Spreads");

    // Action Buttons
    g = w.add("group");
    g.alignment = "center";
    btnOk = g.add("button", undefined, "OK");
    btnCancel = g.add("button", undefined, "Cancel");

    // SET DEFAULT VALUES

    rb072.value = true;
    rbPages.value = true;

    // UI ELEMENT EVENT HANDLERS

    btnOk.onClick = function () {
        w.close(1);
    };

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

    // DISPLAY THE DIALOG

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

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

    function process() {
        // var doc script global
        //
        var compression;
        var docBaseName;
        var filePdf;
        var folder;
        var pdfFileName;
        var resolution;

        // Preserve preferences.
        var preserve = {
            pdfExportPreferences: app.pdfExportPreferences.properties
        };

        try {
            app.pdfExportPreferences.properties = {
                "acrobatCompatibility": AcrobatCompatibility.ACROBAT_8,
                "bleedBottom": 0,
                "bleedInside": 0,
                "bleedMarks": false,
                "bleedOutside": 0,
                "bleedTop": 0,
                "colorBars": false,
                "colorBitmapCompression": BitmapCompression.AUTO_COMPRESSION,
                "colorBitmapSampling": Sampling.BICUBIC_DOWNSAMPLE,
                "colorBitmapSamplingDPI": 72,
                "colorTileSize": 128,
                "compressTextAndLineArt": true,
                "compressionType": PDFCompressionType.COMPRESS_STRUCTURE,
                "cropImagesToFrames": true,
                "cropMarks": false,
                "effectivePDFDestinationProfile": "sRGB IEC61966-2.1",
                "effectivePDFXProfile": PDFProfileSelector.USE_NO_PROFILE,
                "exportAsSinglePages": false,
                "exportGuidesAndGrids": false,
                "exportLayers": false,
                "exportNonprintingObjects": false,
                "exportReaderSpreads": false,
                "exportWhichLayers": ExportLayerOptions.EXPORT_VISIBLE_LAYERS,
                "generateThumbnails": true,
                "grayTileSize": 128,
                "grayscaleBitmapCompression": BitmapCompression.AUTO_COMPRESSION,
                "grayscaleBitmapSampling": Sampling.BICUBIC_DOWNSAMPLE,
                "grayscaleBitmapSamplingDPI": 72,
                "includeBookmarks": true,
                "includeHyperlinks": true,
                "includeICCProfiles": ICCProfiles.INCLUDE_ALL,
                "includeSlugWithPDF": false,
                "includeStructure": true,
                "interactiveElementsOption": InteractiveElementsOptions.APPEARANCE_ONLY,
                "monochromeBitmapCompression": MonoBitmapCompression.CCIT4,
                "monochromeBitmapSampling": Sampling.BICUBIC_DOWNSAMPLE,
                "monochromeBitmapSamplingDPI": 600,
                "omitBitmaps": false,
                "omitEPS": false,
                "omitPDF": false,
                "openInFullScreen": false,
                "optimizePDF": true,
                "pageInformationMarks": false,
                "pageRange": PageRange.ALL_PAGES,
                "pdfColorSpace": PDFColorSpace.RGB,
                "pdfDestinationProfile": "sRGB IEC61966-2.1",
                "pdfDisplayTitle": PdfDisplayTitleOptions.DISPLAY_FILE_NAME,
                "pdfMagnification": PdfMagnificationOptions.FIT_PAGE,
                "pageMarksOffset": 0.125,
                "pdfMarkType": MarkTypes.DEFAULT_VALUE,
                "pdfPageLayout": PageLayoutOptions.SINGLE_PAGE,
                "pdfXProfile": PDFProfileSelector.USE_NO_PROFILE,
                "printerMarkWeight": PDFMarkWeight.P25PT,
                "registrationMarks": false,
                "standardsCompliance": PDFXStandards.NONE,
                "subsetFontsBelow": 100,
                "thresholdToCompressColor": 72,
                "thresholdToCompressGray": 72,
                "thresholdToCompressMonochrome": 600,
                "useDocumentBleedWithPDF": false,
                "useSecurity": false,
                "viewPDF": false
            };
            // 72 and 96 quality minimum.
            // 120 and 150 quality medium.
            compression = CompressionQuality.MINIMUM;
            resolution = 72;
            if (rb096.value) {
                resolution = 96;
            } else if (rb120.value) {
                compression = CompressionQuality.MEDIUM;
                resolution = 120;
            } else if (rb150.value) {
                compression = CompressionQuality.MEDIUM;
                resolution = 150;
            }
            app.pdfExportPreferences.properties = {
                colorBitmapQuality: compression,
                colorBitmapSamplingDPI: resolution,
                grayscaleBitmapQuality: compression,
                grayscaleBitmapSamplingDPI: resolution,
                thresholdToCompressColor: resolution,
                thresholdToCompressGray: resolution,
                exportReaderSpreads: rbSpreads.value
            };
            // Base name is file name less extension.
            docBaseName = doc.name.replace(/\.[^\.]+$/, "");
            // Replace spaces with underscore.
            pdfFileName = docBaseName.replace(/ /g, "_");
            // Add suffix "_proof" unless already present.
            if (!/proof/.test(pdfFileName)) {
                pdfFileName += "_proof";
            }
            // Add extension.
            pdfFileName += ".pdf";
            // Export.
            folder = doc.filePath;
            filePdf = new File(folder.fullName + "/" + pdfFileName);
            doc.asynchronousExportFile(ExportFormat.PDF_TYPE, filePdf);
        } finally {
            // Restore preferences.
            app.pdfExportPreferences.properties = preserve.pdfExportPreferences;
        }
    }

})();
Download
PDF Proof

License details included in download

For help installing scripts, see How to Install and Use Scripts in Adobe Creative Cloud Applications.

IMPORTANT: by downloading the script you agree that the software is provided without any warranty, express or implied. USE AT YOUR OWN RISK. Always make backups of important data.