Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Read EPS File in JScript

Participant ,
Aug 05, 2009 Aug 05, 2009

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

TOPICS
Scripting
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 05, 2009 Aug 05, 2009
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);
e
...
Translate
Community Expert ,
Aug 05, 2009 Aug 05, 2009
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".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 05, 2009 Aug 05, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2009 Aug 05, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 03, 2009 Nov 03, 2009
LATEST

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();
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines