3 Replies Latest reply on Mar 9, 2017 8:02 AM by sashidhark35364535

    Postscript name

    sashidhark35364535

      Hi  All,

       

      I am trying to replace paragraph styles font by postscript name.  Showing error "'postscriptName' is a read only property". Is anyone have a JS code for this?

       

      Thanks,

      /Sdhar/

        • 1. Re: Postscript name
          Kasyan Servetsky Level 5

          You can do this using the reference to the font object like so:

          Main();
          
          function Main() {
              var doc = app.activeDocument;
              var parStyle = doc.paragraphStyles.item("Body");
              var newFont = doc.fonts.item("Myriad Pro\tBold");
              parStyle.appliedFont = newFont;
          }
          

          or, alternatively, font string:

          Main();
          
          function Main() {
              var doc = app.activeDocument;
              var parStyle = doc.paragraphStyles.item("Body");
              parStyle.appliedFont = "Myriad Pro\tBold";
          }
          

           

          08-03-2017 19-43-09.png

          Note the tab in between the font family name and style.

           

          — Kas

          • 2. Re: Postscript name
            Laubender Adobe Community Professional & MVP

            sashidhark35364535  wrote

             

            Hi  All,

             

            I am trying to replace paragraph styles font by postscript name.  Showing error "'postscriptName' is a read only property". Is anyone have a JS code for this?

             

            Thanks,

            /Sdhar/

            Hi Sdhar,

            what does that exactly mean?

             

            Do you have a list (maybe two columns in an Excel file) showing PostScript names of font files:

            column 1 is before, column 2 is the replacement ?


            And you want to check what paragraph style of a given document is using what font (and what PostScript name goes with that) and replace that with an available font identified by its PostScript name?

             

            FWIW: To replace fonts in InDesign documents, the fonts must be installed in the system or at least available to InDesign.

             

            Check the following arrays:

             

            app.fonts.everyItem.getElements();
            

             

            app.documents[0].fonts.everyItem().getElements();
            

             

            app.documents[0].allParagraphStyles;
            

             

            Loop the arrays to analyze if a given font is there or used. Build a control structure for given fonts and fonts you have to substitute.

            The code fragment below is just for reference, not a full script to do anything but writing information to the JavaScript Console of the ESTK:

             

            var allParaStylesOfDoc = app.documents[0].allParagraphStyles;
            var allParaStylesLength = allParaStylesOfDoc.length;
            
            // Write used postscriptNames to JavaScript console of the ESTK:
            for(var n=1;n<allParaStylesLength;n++)
            {
            $.writeln(n+"\t"+allParaStylesOfDoc[n].appliedFont.postscriptName);
            }
            

             

            One workaround—if the fonts are not installed—is to export IDMS snippets and replace the names in the snippets' XML. Also rename the paragraph style names in the XML. Then place the snippet with the renamed styles and replace the old styles with the new styles.

             

            Regards,
            Uwe

            • 3. Re: Postscript name
              sashidhark35364535 Level 1

              Thanks Kasyan and Laubender for your prompt reply.

               

              Actually I am trying to replace paragraph style font by its postscript name not by font name since I have postscript name list. It shows me error "'postscriptName' is a read only property"".

               

              Or can we apply font by its postscript name in InDesign file having postscript font name as a content?

              example:

               

              Times-Roman

              Times-Bold

              Times-Italic

              Times-Bold Italic

               

              Need to select above text line by line and apply font by selected postscript name.

              Times     Roman

              Times     Bold

              Times     Italic

              Times     Bold Italic

               

              Thanks,

              --Sdhar--