📜 ⬆️ ⬇️

Photoshop Scripting to automate the printing of large-circulation printing products

Hello. I would like to share the experience of 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 pieces) of already printed documents. It is necessary to print them in certain places in a certain font with their serial number in a given format (or any string formed by a certain algorithm).
To make it clearer, I will give an example.

Source Image:
image

What should happen:
image

and such - 100,000 documents. Obviously, it is quite difficult to master such a volume manually, so you need to look for automation possibilities.
')
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, we merge, and Corel generates the necessary number of sheets with the necessary content. It seems that everything is nothing, but all the sheets should be in memory, and this says that the resource intensity of the task increases with the number of printed products. Who cares, here's a link to the video - Numbering in Corel Draw . Of course, there are macros in Corel, but I'm not as familiar with Corel as with Photoshop, so Photoshop 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 a jsx extension.
For successful execution of this script, it is necessary to have in the open form a photoshop project with text layers,
whose names are text1, text2, text3, and text4.

The script is controlled from the ExtendScript Toolkit program.
Please note that in the upper left corner of the ExtendScript Toolkit window, you need to select Adobe Photoshop, otherwise the script will not run.

I hasten to note the fact that the script does not in any way pretend to be a role model, was written in a hurry and shows only the possibility of automating the process described above.

Useful information is that instead
 changeTextByLayerName("text4", a); 

can be used
 changeTextByLayerName("text4", "000" + a); 

which clearly demonstrates the possibility of type casting and string concatenation.

Photoshop Scripting documentation is available here .

Thank you for your attention, I hope my decision will be useful to the public.

Source: https://habr.com/ru/post/165517/


All Articles