Getting the Physical Length of a Piece of Text (in mm etc.) in Javascript

I'm trying to write a script in Indesign CS5 (Windows) that can measure the physical, 'rendered' length of two pieces of text of similar length (in mm etc.), calculate the average length of the two, and adjust the tracking/horizontal scale of one or both of the pieces of text so that the physical length of both texts are the same.
I need a script because this task must be done thousands of time in a long document.
I'm struggling to find a way to access the 'rendered' length of a piece of text in Javascript.
I know among the attributes of a text box is whether the text has overrun. So I could copy the text to a special text-box, and use a for loop to reduce the dimentions of the text box, 1mm at a time, until the text box overruns, thus determining the length..
I could also get the length of a rendered string using python with it's built in GUI toolkit Tkinter:
http://stackoverflow.com/questions/2922295/calculating-the-pixel-size-of-a-string-with-pyt hon
And then have an indesign script that takes some data from the python script and sets the tracking/horizontal in Indesign with some fudge factors.
Both ideas seem like real kludges.
Any other suggestions?
Many thanks
David

You can simply iterate through each line in text to get the widest line. Something like this:
Main();
function Main() {
    var text = app.selection[0],
    minLength, maxLength, start, end;
    for (var i = 0; i < text.lines.length; i++) {
        start = text.lines[i].characters[0].horizontalOffset,
        end = text.lines[i].characters[text.lines[i].characters.length-1].horizontalOffset;
        if (minLength == undefined || start < minLength) {
            minLength = start;
        if (maxLength == undefined || end > maxLength) {
            maxLength = end;
    var length = maxLength - minLength;
    $.writeln(length);
But this approach seems to be a little less precise than creating outlines since (I guess) it measures up to the beginning of the last character; discretionary hyphens, line brakes, etc. are not included into the measurement.

Similar Messages

  • Is it at all possible to still get the physical cd's for the CS6 from the adobe website with my college student discount?

    I am currently a college student studying photography and my college gives us a free download of Adobe Creative Cloud Master Collection, but once we graduate it will be deleted from our computers. I graduate in May. I am trying to use my student discount to get the the CS6 Master Collection while I still can, but I would like to get the physical CD's to download the programs, and not the Creative Cloud apps simply downloaded over the internet. Is this still possible at all?

    Meagancon it is likely you will be entitled to receive a download.  You are welcome to download and burn the installation files to a DVD.

  • How to get the physical path of my web app root context ?

    Hi,
    I used this code to initialize my LOG4J logger.
            System.out.println(Version + "Servlet context path : " + sctx .getContextPath());
            String path = sctx .getRealPath("/");
            fullyqualifiedlog4jpath = path + "log4j.xml";
            File locallogxml = new File(fullyqualifiedlog4jpath);
            if (locallogxml.exists()) {
                initialized = true;
                DOMConfigurator.configure(fullyqualifiedlog4jpath);
                log = Logger.getLogger(Log4j.class.getName());
                log.info(Version + "Logger initialized");
            else {
                System.out.println(Version + "Unable to locate the log4j.xml file");
            }It works perfectly when running the application with the embedded Jdev11 WLS.
    When deploying the application on a standalone WLS server the path is not returned ;-( I get a null value.
    Does someone has three lines of code which get the physical path of my web app root context?
    Yves

    Changed the methiod used to access log4j.xml.
            FacesContext ctx = FacesContext.getCurrentInstance();
            ServletContext sctx = (ServletContext) ctx.getExternalContext().getContext();
            String contextPath = sctx.getContextPath();
            HttpServletRequest  hsr = (HttpServletRequest)ctx.getExternalContext().getRequest();
            String host = hsr.getServerName();
            int port = hsr.getServerPort();
            try
              String urlstring = "http://" + host + ":" + port + contextPath + "/faces/log4j.xml";
              DOMConfigurator.configure(new URL(urlstring));
              log = Logger.getLogger(Log4j.class.getName());
    .....using the URL s OK.

  • Getting the unscaled length of

    I'm developing a graphing application with FLEX 3 that will
    be embedded into a PDF document (version 9). The graphing SWF is
    pretty much finished, but I want to have greater control over the
    scaling on the axis. If I graph the parametric equations x=cos(t)
    and y=sin(t), the trace of these equations appears as an ellipse.
    Is there some what if getting the unscaled length of the vertical
    axis and the horizontal axis in pixels, so I can compute the exact
    aspect ratio of the axes. If that is known, I can rescale using
    scaleX and scaleY. Can anyone give me pointers?
    dps

    You can simply iterate through each line in text to get the widest line. Something like this:
    Main();
    function Main() {
        var text = app.selection[0],
        minLength, maxLength, start, end;
        for (var i = 0; i < text.lines.length; i++) {
            start = text.lines[i].characters[0].horizontalOffset,
            end = text.lines[i].characters[text.lines[i].characters.length-1].horizontalOffset;
            if (minLength == undefined || start < minLength) {
                minLength = start;
            if (maxLength == undefined || end > maxLength) {
                maxLength = end;
        var length = maxLength - minLength;
        $.writeln(length);
    But this approach seems to be a little less precise than creating outlines since (I guess) it measures up to the beginning of the last character; discretionary hyphens, line brakes, etc. are not included into the measurement.

  • Getting the max length

    i am using pl/sql and i need to do some validation regarding the max length of the string. but the problem is that i have to refer back to the database for the length so that if the database change, my code don't change.
    is there any way to get the max length in the field of the table?
    eg:
    lets say i got a table call Person with column Name(varchar2(66)) and Sex(char(1))
    so how i retrieve the max length of the field Name?
    thanks

    It's quite simple. We can use the PL/SQL %TYPE in our declarations. Check it out...
    SQL> CREATE TABLE small1 (col1 NUMBER, col2 VARCHAR2(3))
      2  /
    Table created.
    SQL>
    SQL> CREATE OR REPLACE PROCEDURE small1_api (pv_string IN VARCHAR2)
      2  AS
      3      l_col2 small1.col2%TYPE;
      4  BEGIN
      5      l_col2 := pv_string;
      6      INSERT INTO small1 (col1, col2)
      7      VALUES (a12.NEXTVAL, l_col2);
      8  EXCEPTION
      9      WHEN value_error THEN
    10          dbms_output.put_line('oops! string is too long');
    11  END;
    12  /
    Procedure created.
    SQL> EXEC small1_api('APC')
    PL/SQL procedure successfully completed.
    SQL> EXEC small1_api('APC4')
    oops! string is too long
    PL/SQL procedure successfully completed.
    SQL>
    SQL> ROLLBACK
      2  /
    Rollback complete.
    SQL> ALTER TABLE small1 MODIFY (col2 VARCHAR2(4))
      2  /
    Table altered.
    SQL> ALTER PROCEDURE  small1_api COMPILE
      2  /
    Procedure altered.
    SQL>
    SQL> EXEC small1_api('APC4')
    PL/SQL procedure successfully completed.
    SQL> EXEC small1_api('APC45')
    oops! string is too long
    PL/SQL procedure successfully completed.
    SQL> Cheers, APC

  • Logging level to get the physical query

    Hi All,
    Can anyone let me know , what log level i have set it up, so that I can get the physical query for BI Answers request.
    Thanks
    S

    hi,
    Logging Levels
    Level 0
    No logging.
    Level 1
    Logs the SQL statement issued from the client application.
    Logs elapsed times for query compilation, query execution, query cache processing, and back-end database processing.
    Logs the query status (success, failure, termination, or timeout). Logs the user ID, session ID, and request ID for each query.
    Level 2
    Logs everything logged in Level 1.
    Additionally, for each query, logs the repository name, business model name, presentation catalog (called Subject Area in Answers) name, SQL for the queries issued against physical databases, queries issued against the cache, number of rows returned from each query against a physical database and from queries issued against the cache, and the number of rows returned to the client application.
    Level 3
    Logs everything logged in Level 2.
    Additionally, adds a log entry for the logical query plan, when a query that was supposed to seed the cache was not inserted into the cache, when existing cache entries are purged to make room for the current query, and when the attempt to update the exact match hit detector fails.
    Do not select this level without the assistance of Technical Support.
    Level 4
    Logs everything logged in Level 3.
    Additionally, logs the query execution plan. Do not select this level without the assistance of Technical Support.
    Level 5
    Logs everything logged in Level 4.
    Additionally, logs intermediate row counts at various points in the execution plan. Do not select this level without the assistance of Technical Support.
    Level 6 and 7
    Reserved for future use.
    Hope this helps,
    cheers,
    vineeth

  • How to get the time length from send record command to record video really?

    I have two buttons. Record/Stop
    I press Record button to record the video and press Stop
    button to stop recording.Now,I spend 1986 ms from press Record
    button to press Stop button.
    But the flv file's length is 1920 or 1910 or 1915 ms.
    So I want to get the time length from send record command to
    record video really.
    Can you give me some suggests.
    Thanks!

    maybe you have lag in publishing.... are you try watch de
    NetStream.liveDelay() method?
    or start counting when NetStream.onStatus has
    "NetStream.Record.Start" and "NetStream.Record.Stop" in information
    objects....

  • How to get the correct length...removing appended extra ascii characters

    I have a table fs_lg_partgroups, having the columns description,subgroupname.
    I have a query like this..
    select description,length(description) from fs_lg_partgroups where subgroupname='FORMULA226';
    Then i got the output as
    formula226 and the length is 42. Even though there are 10 characters only.
    I came to know that some ascii characters are appended to description values, so it is showing the length like this.
    But i don't know how to remove those ASCII characters from description column for all rows to get the exact length.
    Please can u help me..

    If you have used char data type then use varchar2 datatype instead of char datatype for description column.
    Learn about char and varchar2 datatypes here.
    http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96524/c13datyp.htm#7223

  • Any idea how the java application can get the physical memory?

    Hello, everyone
    Any idea how the java application can get the physical memory?
    thanks in advance

    I believe what yo intend to do is forbidden, but here
    my answer.
    when you start your application you can give your VM
    the entire memory of your pc. like this this memory
    is completly under your control.* headdesk *

  • How to get the transport request for a particular standard text?

    Hi,
    i want to know, how we get the transport request which associated for standard text.
    Please note already the standard text is assigned to the TR using RSTXTRAN program.
    i have a std text. i want to find the related TR for that!
    rds,
    Siva.

    Refer the link. It might tellsa about attaching to transport request but using the way you can find also -
    Re: How To Transport STANDARD TEXTS??
    Regards,
    Amit
    Reward all helpful replies

  • Illustrator CS6 has suddenly stopped responding. I can open it but get the revolving icon when I try to use any tools etc. Help

    Illustrator CS6 has suddenly stopped responding. I can open it but get the revolving icon when I try to use any tools etc. Newsgroup User

    Moving this discussion to the Illustrator forum.

  • How to get the real length of a 3D room

    Hi, I want to built a 3d room. When I import a obj file, the vector3f length does not equal to the real length(much longer than the real one), I know there must be relation between them, but how I can get the relation?
    for example:
    T3Droom.setTranslation(new Vector3f(0.7f,1f,0.5f));
    How many metres the 0.7f equals to?
    thanks a lot

    javax.mail.Address[] addrs= m.getFrom();
    Address a = addrs[0];
    if (a instanceof InternetAddress &&
    ((pers = ((InternetAddress)a).getPersonal()) != null)) {
    String addr = ((InternetAddress)a).getPersonal();
    } else
    addr = a.toString();
    this 'getPersonal()' is the thing you need.

  • How can I get the full-length ringtone "Calypso" back?

    I recently updated my iPhone 4 to iOS 5. In iOS 5, Apple truncated the ringtone "Calypso." I would like to have the full-length ringtone back, as it is very special to me. Is there any way to make this happen?
    A solution to this problem will be IMMENSELY appreciated.

    I also had my ringtones...bought in Itunes...wiped out.  So I went ahead and bought a new one.  I synced it with the cable, and it is in the playlist as a ringtone.  But when I go to edit the contact, the ringtone doesn't show up in the list.  However, there is a Buy a Ringtone category at the top of the list. 
    On the upgrade, I lost a number of paid APPS.  I don't know if its a scheme by Apple to make more money on a free upgrade or they just screwed up everyone with this.

  • [JS][CC] How can I get the last visible character in an overflowed Text Frame?

    Hello
    I'm new in InDesign scripting in javascript. I would like to know if there is a way to get the position of the last character in a Text Frame that is overflowed? I need this because I want to calculate how many characters are hidden (overflowing text) via script.
    I've searched in the forums about this but what I find is always a script for alerting if there's overset text or not.
    I'd really appreciate any help!

    Well, let's say that myFrame is an overflowing text frame.
    So, the last character in that frame would be
    myFrame.characters[-1];
    To calculate the number of overflowing characters, select the
    overflowing text frame, and run this script:
    myFrame = app.selection[0];
    myParentStory = myFrame.parentStory;
    alert("Number of overflowing characters is
    "+myParentStory.characters.itemByRange(myFrame.characters[-1],
    myParentStory.characters[-1]).length-1);
    Ariel

  • Getting jeditorpane to scroll to a piece of text

    I am highlighting text in a JEditorPane and can't figure out how to get the pane to scroll so the hightlighted text is visible.
    Any ideas?
    Thanks

    search -> no answer
    browse main page -> easy answer
    I feel silly. I just modified this a little:
    text.setCaretPosition( text.getDocument().getLength() );
    http://forums.java.sun.com/thread.jsp?forum=57&thread=422783&tstart=0&trange=15

Maybe you are looking for

  • I cant sign in icloud

    why my apple id not support in icloud

  • Weblogic 9.2 error when using spring framework and taglibs.

    I am getting the following error when using spring binding for a command form class. Class ExCommandForm private String firmCode; public String getFirmCode () public void setFirmCode () In my jsp I have the following <spring:bind path="exCommandForm.

  • SAP GTS------- SAPPI with Seeburger BIC----- ATLAS using with SAP PI

    Hi All, I have scenario this SAP GTS----->SAPPI with Seeburger BIC--->ATLAS(German customs system) 1)Inbound flow: SAP GTS will send the customs declaration message to ATLAS(German customs system) 2)outbound flow: response messages from ATLAS(German

  • Copy control from Invoice to Credit Memo request

    Hii All We have a requirement where when we create an credit memo request with reference to the invoice we want that PO number in the invoice should be copied to the credit memo request. Can this be done through copy control or some user exit needs t

  • SREL_GET_NEXT_RELATIONS

    Hi, I found tutorial <i>Getting IDocs linked to Application documents (By Kevin Wilson)</i> http://www.erpgenie.com/sapedi/idoc_abap.htm and I try to use SREL_GET_NEXT_RELATIONS FModule to get IDOC number having accountancy document numbers generated