0% found this document useful (0 votes)
112 views

Batch Export .Ai Files To PDF

This document provides a JavaScript script to batch export Illustrator .ai files in a folder to PDF format. The script allows selecting a source folder of .ai files, opens each file, saves it as a PDF with the same name plus an '_export' suffix in the same folder, and configures the PDF settings for compatibility. Instructions are given to save the script in Illustrator and run it to convert multiple files at once.

Uploaded by

eranhyzo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Batch Export .Ai Files To PDF

This document provides a JavaScript script to batch export Illustrator .ai files in a folder to PDF format. The script allows selecting a source folder of .ai files, opens each file, saves it as a PDF with the same name plus an '_export' suffix in the same folder, and configures the PDF settings for compatibility. Instructions are given to save the script in Illustrator and run it to convert multiple files at once.

Uploaded by

eranhyzo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Batch export .

ai files to pdf
March 2020 update: several blog readers have said that this works up to Illustrator CC
2018. Let me  know if you have success on newer Illustrator versions.

Every time I send a copy of the current version of a manuscript to contributors, I have to
export .ai files to .pdf (they can’t read .ai) for all of the figures that have changed and
that takes a very annoying 5 minutes every day since I have a bunch of plots. And so as
a true scientist, I spent several hours trying to find a solution.

There’s a .jsx hidden far inside the Illustrator example scripts folder that does the job;
it’s called Save to PDFs, and it simply saves all files in a given folder matching a mask
to pdfs. I tweaked it a little so it would ask less questions and just export all the ai files
in a folder to (aifilename)_export.pdf, with the settings set up so the pdfs read correctly
in the Preview Mac application (and other non-Adobe pdf readers). Here is the script:

1 /**********************************************************
2  
ADOBE SYSTEMS INCORPORATED
3 Copyright 2005-2006 Adobe Systems Incorporated
4 All Rights Reserved
5  
6 NOTICE:  Adobe permits you to use, modify, and
7 distribute this file in accordance with the terms
8 of the Adobe license agreement accompanying it.
If you have received this file from a source
9 other than Adobe, then your use, modification,
10 or distribution of it requires the prior
11 written permission of Adobe.
12  
13 *********************************************************/
14  
15 /**********************************************************
16  
Export to PDFs.jsx
17
 
18 DESCRIPTION
19  
20 This sample gets files specified by the user from the
21 selected folder and batch processes them and saves them
22 as PDFs.
23  
Edits by Patrick Mineault:
24  - only .ai files processed
25  - files saved in same folder as the input files
26  - export files have name (oldname)_export.pdf
27  - PDF settings: non-editable / acrobatLayers=false
28       for maximum compatibility with Preview
29  
**********************************************************/
30
 
31 // Main Code [Execution of script begins here]
32  
33 // uncomment to suppress Illustrator warning dialogs
34 // app.userInteractionLevel =
UserInteractionLevel.DONTDISPLAYALERTS;
35
36  
var destFolder, sourceFolder, files, fileType, sourceDoc,
37 targetFile, pdfSaveOpts;
38  
39 // Select the source folder.
40 sourceFolder = Folder.selectDialog( 'Select the folder with
41 Illustrator .ai files you want to convert to PDF');
42  
// If a valid folder is selected
43 if ( sourceFolder != null )
44 {
45     files = new Array();
46     fileType = "*.ai"; //prompt( 'Select type of Illustrator files
47 to you want to process. Eg: *.ai', ' ' );
48  
    // Get all files matching the pattern
49     files = sourceFolder.getFiles( fileType );
50  
51     if ( files.length > 0 )
52     {
53         // Get the destination to save the files
        //destFolder = Folder.selectDialog( 'Select the folder
54 where you want to save the converted PDF files.', '~' );
55         destFolder = sourceFolder;
56         for ( i = 0; i <
57 files.length; i++ )
58         {
            sourceDoc = app.open(files[i]); // returns the document
59 object
60  
61             // Call function getNewName to get the name and file to
62 save the pdf
63             targetFile = getNewName();
64  
65             // Call function getPDFOptions get the PDFSaveOptions
for the files
66             pdfSaveOpts = getPDFOptions( );
67  
68             // Save as pdf
69             sourceDoc.saveAs( targetFile, pdfSaveOpts );
70  
71             sourceDoc.close();
        }
72         alert( 'Files are saved as PDF in ' + destFolder );
73     }
74     else
75     {
76         alert( 'No matching files found' );
    }
77 }
78  
79 /*********************************************************
80  
81 getNewName: Function to get the new file name. The primary
82 name is the same as the source file.
83  
**********************************************************/
84  
85 function getNewName()
{
86     var ext, docName, newName, saveInFile, docName;
87     docName = sourceDoc.name;
88     ext = '_export.pdf'; // new extension for pdf file
89     newName = "";
90  
91     for ( var i = 0 ; docName[i] != "." ; i++ )
    {
92         newName += docName[i];
93     }
94     newName += ext; // full pdf name of the file
95  
96     // Create a file object to save the pdf
97     saveInFile = new File( destFolder + '/' + newName );
98  
    return saveInFile;
99 }
10  
0 /*********************************************************
10  
1 getPDFOptions: Function to set the PDF saving options of the
10 files using the PDFSaveOptions object.
2  
**********************************************************/
10
3  
function getPDFOptions()
10 {
4     // Create the PDFSaveOptions object to set the PDF options
10     var pdfSaveOpts = new PDFSaveOptions();
5  
10     // Setting PDFSaveOptions properties. Please see the JavaScript
Reference
6     // for a description of these properties.
10     // Add more properties here if you like
7     pdfSaveOpts.acrobatLayers = false;
10     pdfSaveOpts.colorBars = false;
8     pdfSaveOpts.colorCompression =
CompressionQuality.AUTOMATICJPEGHIGH;
10     pdfSaveOpts.compressArt = true; //default
9     pdfSaveOpts.embedICCProfile = true;
11     pdfSaveOpts.enablePlainText = true;
0     pdfSaveOpts.generateThumbnails = true; // default
    pdfSaveOpts.optimization = true;
11     pdfSaveOpts.pageInformation = false;
1     pdfSaveOpts.preserveEditability = false;
11  
2     return pdfSaveOpts;
11 }
3
11
4
11
5
11
6
11
7
11
8
11
9
12
0
12
1
12
2
12
3
12
4
12
5
12
6
12
7
12
8
12
9
13
0
13
1
13
2
13
3
13
4
13
5
13
6

Save this as Export to PDFs.jsx and inside Illustrator run it by selecting File > Scripts >
Other Scripts (or press Ctrl+F12 if the keyboard shortcuts are set to default). The rest
should be pretty obvious.

JavaScript

// Main Code [Execution of script begins here]


// uncomment to suppress Illustrator warning dialogs

// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts, folderName;

var fullPath = "";

var finalSlash;

// Select the source folder.

sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator .ai files you want to
convert to PDF');

f = find_files(sourceFolder);

You might also like