Photoshop: Please add option to extract the text from PSD files

  • 1
  • Problem
  • Updated 7 days ago
  • (Edited)
Please add the option to extract the text from Photoshop files, (text layer) with the all formatting like font, font size as well as color (with all properties). export version can be html, xml
Photo of Praful Sawant

Praful Sawant

  • 2 Posts
  • 0 Reply Likes

Posted 1 year ago

  • 1
Photo of David Converse

David Converse

  • 939 Posts
  • 274 Reply Likes
This can almost certainly be done with a script. I've considered writing one to process thousands of files but just haven't had enough time. It would be easier without preserving formatting (which can require diving into Action Manager) but the text itself is easy.
Photo of Praful Sawant

Praful Sawant

  • 2 Posts
  • 0 Reply Likes
We are looking for the multiples files with preserving formatting, please suggest 
Photo of David Converse

David Converse

  • 939 Posts
  • 274 Reply Likes
This script will not preserve formatting, ExtendScript supports saving plain text but not RTF or Word. You MIGHT be able to export to pdf and save formatting, I don't know.

Place this in Photoshop scripts folder and it will export the text layers of all open files to a text file in tab-delimited format.

#target photoshop
textCopier();
function textCopier(){
    if(documents.length > 0){
        var originalDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.ERROR;
        try{
            var fleLogFile = new File('~/Desktop/textExport.txt').saveDlg('Create New Log File', '*.txt');
            fleLogFile.open('w:');
            for(var j = 0; j < documents.length; j++){
                var docRef = documents[j];
                var exportLine = docRef.name;
                for(var i = 0; i < docRef.artLayers.length; i++){
                    var LayerRef = docRef.artLayers[i];
                    if(LayerRef.kind == LayerKind.TEXT){
                        var layerText = LayerRef.textItem.contents;
                        layerText = layerText.replace('\r', '\t');
                        exportLine = exportLine + '\t' + layerText;
                        }
                    }
                fileWriter();
                }
            function fileWriter(){
                fleLogFile.writeln(exportLine);
                exportLine = '';
                }
            fleLogFile.close();
            }
        catch(e){
            alert(e + e.line);
            }
        app.displayDialogs = originalDialogMode;
        }
    }

Photo of pankaj gaikwad

pankaj gaikwad

  • 2 Posts
  • 0 Reply Likes
How can i add this script to photoshop script folder??
Photo of David Converse

David Converse

  • 939 Posts
  • 274 Reply Likes
This version will work if called in an Action, you can run a batch from Bridge. You may need to edit the replace lines. This will place each text layer contents on its own line with the filename. Between the two, it should be good samples of how to extract text to a file.

#target photoshop
textCopier2();
function textCopier2(){
    if(documents.length > 0){
        var originalDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.ERROR;
        try{
            var fleLogFile2 = new File('~/Desktop/textExport2.txt');
            fleLogFile2.open('a:');
            for(var j = 0; j < documents.length; j++){
                var docRef = documents[j];
                var exportLine = docRef.name;
                for(var i = 0; i < docRef.artLayers.length; i++){
                    var LayerRef = docRef.artLayers[i];
                    if(LayerRef.kind == LayerKind.TEXT){
                        var layerText = LayerRef.textItem.contents;
                        layerText = layerText.replace('\r', ',');
                        layerText = layerText.replace(/,/g, '\r' + exportLine + '\t');
                        exportLine = exportLine + '\t' + layerText;
                        fileWriter2();
                        }
                    }
                }
            function fileWriter2(){
                fleLogFile2.writeln(exportLine);
                exportLine = docRef.name;
                }
            fleLogFile2.close();
            }
        catch(e){
            alert(e + e.line);
            }
        app.displayDialogs = originalDialogMode;
        }
    }



Photo of pankaj gaikwad

pankaj gaikwad

  • 2 Posts
  • 0 Reply Likes
How can i add this script to photoshop script folder??
Photo of David Converse

David Converse

  • 933 Posts
  • 270 Reply Likes
Save it as a plain text file with ".jsx" file extension. Photoshop stores scripts in different places depending on operating system.

https://community.adobe.com/t5/photoshop/how-to-import-a-new-script-into-photoshop/td-p/10086058?pag...