Photoshop Scripting to automate printing of large-scale printing products
- Tutorial
Hello. I would like to share my experience in automating the process of printing a large number of documents from Adobe Photoshop.
The task is as follows:
there is a large number (in my case - 100,000 pcs.) Of already printed documents. It is necessary to print them in certain places in a specific font, their serial number in a given format (or any line formed by a certain algorithm).
To make it more clear, I will give an example.
Original image:

What should happen:

and such - 100,000 documents. Obviously, it’s quite difficult to handle such a volume manually, so you need to look for automation options.
In the process of finding a solution to the problem of automatic numbering of documents according to a certain algorithm when printing, a method was found that uses Corel Draw and MS Office: we generate a table with the necessary values, merge, and Corel generates the required number of sheets with the desired content. It seems to be all - nothing, but all the sheets should be in memory, and this says that the resource consumption of the task increases with the number of printed items. Who cares, here is the link to the video - Numbering in Corel Draw . Of course, there are macros in Corel, but I'm not familiar with Corel as well as with Photoshop, so it was Photoshop that was chosen to solve the problem.
I will give an example of a script that performs the necessary operations:
Scripts for Adobe Photoshop have the jsx extension.
For successful execution of this script, you must have an open-ended photoshop project with text layers whose
names are text1, text2, text3, and text4.
The script is controlled from the ExtendScript Toolkit.
Please note that in the upper left corner of the ExtendScript Toolkit window you need to select Adobe Photoshop, otherwise the script will not start.
I hasten to note the fact that the script in no way claims to be a role model, was written in haste and shows only the possibility of automating the process described above.
Useful information is that instead of
can be used
which clearly demonstrates the ability to type and concatenate strings.
The documentation for Photoshop Scripting can be found here .
Thank you for your attention, I hope my decision will be useful to the public.
The task is as follows:
there is a large number (in my case - 100,000 pcs.) Of already printed documents. It is necessary to print them in certain places in a specific font, their serial number in a given format (or any line formed by a certain algorithm).
To make it more clear, I will give an example.
Original image:

What should happen:

and such - 100,000 documents. Obviously, it’s quite difficult to handle such a volume manually, so you need to look for automation options.
In the process of finding a solution to the problem of automatic numbering of documents according to a certain algorithm when printing, a method was found that uses Corel Draw and MS Office: we generate a table with the necessary values, merge, and Corel generates the required number of sheets with the desired content. It seems to be all - nothing, but all the sheets should be in memory, and this says that the resource consumption of the task increases with the number of printed items. Who cares, here is the link to the video - Numbering in Corel Draw . Of course, there are macros in Corel, but I'm not familiar with Corel as well as with Photoshop, so it was Photoshop that was chosen to solve the problem.
Decision
I will give an example of a script that performs the necessary operations:
var start1 = 1; //номер, с которого начинать нумерацию
var count = 100000; //общее количество экземпляров
var doc = app.activeDocument;
var layer = doc.layers.getByName("text1");
function changeTextByLayerName(layerName,newText){ //функция изменения содержания текстового слоя по его имени на переданную строку
layer = doc.layers.getByName(layerName);
if(layer.kind == LayerKind.TEXT) layer.textItem.contents = newText; //присваиваем содержимое
}
function printIt(){ //функция отправки на печать
app.bringToFront();
doc.printSettings.flip = false;
doc.printSettings.setPagePosition(DocPositionStyle.SIZETOFIT);
doc.printSettings.negative = false;
doc.printOneCopy();
}
for(a=start1; a<=count; a++){
changeTextByLayerName("text1", a);
changeTextByLayerName("text2", a);
changeTextByLayerName("text3", a);
changeTextByLayerName("text4", a);
$.sleep(2000); //задержка выполнения на 2 секунды, чтобы принтер успел обрабатывать запросы
printIt();
}
Scripts for Adobe Photoshop have the jsx extension.
For successful execution of this script, you must have an open-ended photoshop project with text layers whose
names are text1, text2, text3, and text4.
The script is controlled from the ExtendScript Toolkit.
Please note that in the upper left corner of the ExtendScript Toolkit window you need to select Adobe Photoshop, otherwise the script will not start.
I hasten to note the fact that the script in no way claims to be a role model, was written in haste and shows only the possibility of automating the process described above.
Useful information is that instead of
changeTextByLayerName("text4", a);
can be used
changeTextByLayerName("text4", "000" + a);
which clearly demonstrates the ability to type and concatenate strings.
The documentation for Photoshop Scripting can be found here .
Thank you for your attention, I hope my decision will be useful to the public.