Skip to content

Instantly share code, notes, and snippets.

@Pastez
Last active February 13, 2024 05:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Pastez/55398b9d60faa015c3cf to your computer and use it in GitHub Desktop.
Save Pastez/55398b9d60faa015c3cf to your computer and use it in GitHub Desktop.
Adobe Illustrator script that replace text with text from array. Script then creates outlines of that text and save it as pdf file in provided directory. Greate for wedding invitation :).
/*
do What The Fuck you want to Public License
Version 1.0, August 2015
Copyright (C) 2015 Tomasz Kwolek.
www.pastez.com
www.cheerapp.pl
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Ok, the purpose of this license is simple
and you just
DO WHAT THE FUCK YOU WANT TO.
*/
var textToReplace = prompt('text to replace')
var names = ['a', 'b', 'c'];
var file = new File().openDlg();
var destFolder = Folder.selectDialog( 'Select the folder where you want to save PDF files.', '~' );
var doc = open(file);
for (i = 0; i < doc.textFrames.length; i++)
{
contentString = doc.textFrames[i].contents;
if (contentString.indexOf(textToReplace) != -1)
{
for(var idx = 0; idx < names.length; idx++)
{
doc.textFrames[i].contents = names[idx];
doc.textFrames[i].createOutline();
targetFile = new File(destFolder + '/' + names[idx] + '.pdf');
pdfSaveOpts = getPDFOptions();
doc.saveAs(targetFile, pdfSaveOpts);
undo();
}
}
}
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
function getPDFOptions()
{
var pdfSaveOpts = new PDFSaveOptions();
pdfSaveOpts.acrobatLayers = false;
pdfSaveOpts.colorBars = false;
pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
pdfSaveOpts.compressArt = true;
pdfSaveOpts.embedICCProfile = true;
pdfSaveOpts.enablePlainText = true;
pdfSaveOpts.generateThumbnails = false;
pdfSaveOpts.optimization = true;
pdfSaveOpts.pageInformation = false;
return pdfSaveOpts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment