4 Replies Latest reply on Nov 3, 2009 5:54 AM by Techi Panda

    Read EPS File in JScript

    Techi Panda Level 2

      Hi scripters

       

      I am placing EPS file as inline object into indesign via JScript,

       

      doc = app.activeDocument;

      doc.pages.item(0).place(File("D:\\auto\\Chapter-3\\fig1.eps")

       

      here while i am placing the EPS files into indesign inline object i want to read the BoundingBox values stored in the EPS files. It is possbile to read EPS files in JScript?

       

      thanks in advance

       

      regards

      a r u l

        • 1. Re: Read EPS File in JScript
          [Jongware] Most Valuable Participant
          It is possbile to read EPS files in JScript?

           

          JScript is not supported by InDesign. I'll kindly assume you meant "Javascript", but be aware that JScript is not Javascript.

           

          It's possible to read any kind of file with Javascript. Any file at all. This snippet

           

          epsFile = File("D:\\auto\\Chapter-3\\fig1.eps");
          if (epsFile.open("r") == false)
          {
          alert ("Why don't you try an existing file?");
          exit(0);
          }
          do
          {
          someLine = epsFile.readln();
          if (someLine.indexOf ('BoundingBox') > 0)
            break;
          } while(epsFile.eof == false);
          epsFile.close();

           

          reads text lines until it runs out of text lines or encounters one with the exact phrase 'BoundingBox'.

          However, Javascript does not automagically know what it's reading. EPSs may contain binary information, so you can't use plain text reading functions. So you need to read binary code -- and for that, you need the exact binary file format of an EPS.

          In addition, you need to parse the context of the string 'BoundingBox' as well. It might appear in a text ("This image shows a BoundingBox of ..") or a comment ("%%This image does not have a BoundingBox"), or with extra parameters or parameters missing.

           

          Long story short, "yes, it is possible to read EPS files".

          • 2. Re: Read EPS File in JScript
            Techi Panda Level 2

            HI Jongware

             

            thanks a lot for your reply, I am sorry for my post i used JScript its Javascript, I just want  to get the boundingbox values from the eps file, the line as follows:

             

            %%BoundingBox: 0 0 61 28

             

            I want to get the values 0 0 61 28, this values will change for each files? i think i am detailed about my need.

             

            thanks

             

            regards

            a r  u l

            • 3. Re: Read EPS File in JScript
              [Jongware] Most Valuable Participant

              Search the forum for "MathType". There is a script somewhere that places MathType equations, and I'm pretty sure it adjusts the placement by inspecting its Bounding box.

              1 person found this helpful
              • 4. Re: Read EPS File in JScript
                Techi Panda Level 2

                Hi scripters

                 

                finally I read the EPS file

                 

                here is my code

                 

                main();
                exit();
                function main() {
                var myFile = File("D:/auto/Figure/eqn/eqn01.eps"); 
                var ok = myFile.open ("r");
                if (!ok) {
                $.writeln (myFile.error)
                }
                do{
                    myLine = myFile.readln();
                    var re = new RegExp("%%Baseline: [0-9]+");
                    mys=myLine.match(re);
                     if (mys!=null)
                     {
                     var myst= mys+"";
                     alert(myst.split("%%Baseline: ")[1]);
                          }

                }
                while(myFile.eof == false);
                   myFile.close();
                }