Apply different font styles in single text frame

hi all
how can i apply different font styles in a single text frame using indesign script ?
for example :
"dasdnasndasndlasndnasdlasdasdas"
may i know is it possible to do that and how to do that ?
thanks

You can set (as well as read) every single property of any text range with scripts. This is javascript; it assumes you text cursor is inside a frame with some text.
* Setting some specific characters to a color:
app.selection[0].parentStory.characters.itemByRange(5,10).fillColor = "Red";
* Change the font of words:
app.selection[0].parentStory.words[3].appliedFont = "Arial\tBold";
* .. or just the style:
app.selection[0].parentStory.lines[2].fontStyle = "Italic";
* .. or any other attribute (this one requires you to have at least 5 characters selected):
app.selection[0].characters[5].underline = true;
Of course these operations are not limited to something you select; they work the same with any text frames you can refer to.
app.activeDocument.textFrames[1].paragraphs[2].appliedCharacterStyle = "charstyle";

Similar Messages

  • How to give Bold style inside Single Text Frame

    Hi
    I created a text frame with some text in it. It comes in three paragraphs. First para is the title with two words and below two are small description. All the text is kept in single textframe and I need that to be in single frame only. NOW, I need to bold the first para that is the title with two words. How can I write the code to give bold style to the first paragraph inside that frame? Do I need to take different frame? I want all in single actually. Also I want the entire text frame to give my customized text color.
    Hoping a valuable suggestion
    Thanks in advance.
    Regards
    P

    Dave, Good questions(s)!!! Details below...
    It's CS2. I need to put some text in all (many) documents I work regularly. Instead of copying from the previous file or any other source, as the text is same for all, I thought of writing the script with the text itself. Running that will create text frame and write the text. Got almost but was unable to bold the title of the text which I mentioned earlier as a first paragraph with two words.
    Also I couldn't give the my color swatch to the text.
    Here is my script:
    var myTextFrame = app.activeWindow.activePage.textFrames.add()
    var myParagraph = myTextFrame.paragraphs.item(0)
    var myFont = app.fonts.item("Arial")
    myTextFrame.geometricBounds = ["11.2in", "6in","9.57in","0.5in"];
    myTextFrame.contents = "First Paragraph"
    myTextFrame.parentStory.insertionPoints.item(-1).contents = "\r This is Second paragraph.";
    myTextFrame.parentStory.insertionPoints.item(-2).contents = "\r\rHere comes the Third Paragraph with extra para space";
    myParagraph.parentStory.appliedFont = myFont
    myParagraph.parentStory.pointSize = 8
    myParagraph.paragraphs.item(-1).spaceAfter = "0.05in"
    myTextFrame.fit(FitOptions.frameToContent)
    Hope this answers all your questions. Waiting for valuable solution. Have another question will ask after I got this. For now, two questions 1) making bold first two words 2) font color

  • Different fonts in a single text component

    I need to use two different fonts in a text component.
    Note, In the beginning the text component will contain text in font1 and
    in run time i have to insert some strings with font2.
    I think it is not possible with JTextArea.
    Which one is suitable JEditorPane or JTextPane or JTextComponent.

    I think it is not possible with JTextArea.
    Which one is suitable JEditorPane or JTextPane or JTextComponent and how ?
    Thanks
    SENTHIL

  • Can you apply different paragraph styles for each orientation?

    I would like to apply different paragraph styles to the text, depending if it is viewed on portrait or landscape mode, but everytime I change one the other changes automatically. Is there a way to break this link?
    Thanks

    Unfortunately, iBA doesn't provide a lever to pull that can make a particular text style orientation specific.

  • How to apply different CSS styles to different table cells?

    I have an h:dataTable table and I would like to apply different CSS styles to different table cells depending on their content. If I were doing JSP I would probably have a <c:if> test on the cells, and give them a style name depending on contents, and then define the styles in a separate style sheet. Is there a way in JSF to do the equivalent? Thanks.

    mitchgart wrote:
    BalusC wrote:
    How to achieve a cell-specific style is already answered in my 1st reply of this topic.That tells how to apply a style to the text (or other content) inside a cell but not how to apply a style to the <td> as a whole. It would work for something like text font or text color but not cell border.
    I'm thinking I can mark the content somehow and then have javascript traverse the DOM, find marked content, and traverse outward to the enclosing <td>. Is there a better way?BalusC already spoke about rowClasses and columnClass attributes, I assume those are insufficient.
    The Tomahawk dataTable component has the rowStyleClass and rowStyle attributes for assigning CSS to the HTML tr tag. One is allowed to reference the row data variable when assigning values to these. However, see https://issues.apache.org/jira/browse/TOMAHAWK-523 for workarounds to bugs in some implementations.
    The Tomahawk column component has the styleClass and style attributes for assigning CSS to the HTML td tag. These also may reference the row data variable.

  • Scripting Selective XML into a Single Text Frame? (& Some Other Stuff...)

    Hi all, I could use some help (using version CS5.5).
    I want to import (via Javascript) an XML file similar to this:
    <movieRoot>
         <dvds>
              <movie>
                   <title>2001: A Space Odyssey</title>
                   <edition>Special Edition</edition>
                   <features>NOTHING</features>
                   <notes/>
              </movie>
              <movie>
                   <title>Airplane!</title>
                   <edition />
                   <features>Extra Laughs</features>
                   <notes/>
              </movie>
         </dvds>
    </movieRoot>
    I've been able to successfully do this, so no problem there.
    Then I want to dump the child elements under the XML element "<dvds>" into a single text frame that spans 2 columns per page. That's easy enough too, except:
    1) I want to filter the data so that empty elements or whose contents equal "NOTHING" do not appear.
    2) I want to add static text title above some of the elements that remain (outside the XML proper).
    3) Then I want to format the text (using Paragraph Styles).
    Tall order, I know, but I'm keen on figuring it out. I initially created a document using placeholders and used the standard XML Import to populate it with data, which was filtered using scripts to remove extraneous placeholders and static text. It gave me the result I wanted, but as the XML will be regularly updated and since the "filtered" tags result in non-standard XML entries, it means starting over from scratch after every XML update. So I turned to scripting...
    For point #1, I was able to filter properly using a recursive IF statement, tested here using message alerts:
    I've included a bunch of variables for (hopefully) easier viewing.
    var myXMLRoot = myDocument.xmlElements.item(0);  //movieRoot
    var myXMLParent = myXMLRoot.xmlElements.item(0);  //dvds
    var myXMLElement = myXMLParent.xmlElements.item(0);  //movie
    var currElement = myXMLElement.xmlElements.item(0);  //title
    for (i = 0; i < myXMLParent.xmlElements.length; i++)
        myXMLElement = myXMLParent.xmlElements.item(i);
        for (j = 0; j < myXMLElement.xmlElements.length; j++)
            currElement = myXMLElement.xmlElements.item(j);
            if (currElement.contents != "" && currElement.contents != "NOTHING")
                alert (currElement.markupTag.name + ": " + currElement.contents);
    It worked great until I tried to get it into an existing text frame. Since I want all the info in one text frame, placexml was out of the question, and markup worked but overwrote XML tags -- such as assigning the entire text frame to <movie/title> when I wanted it assigned to <dvds> with <movie/title> tags nested within it.
    If you can help me with anything, this is really where I need pointed in the right direction most. But if you're feeling generous or bored...
    Then for points #2 and #3, I want to take what's left ("filtered" XML data) and add additional text and formatting wherever certain tags are found.
    For example, applying the paragraph style "MovieTitles" for any text within <title></title> XML tags; or adding the phrase "Special Features" (with paragraph style "Headers") above any text marked with <features> tags, while the content within those <features> tags applies the paragraph style "NormalText."
    I've got some of this worked out in pieces already, but it generally falls apart because I can't get the tag structure correct in the text frame. I can provide more info as requested. Any help would be mighty appreciated!
    UPDATE: Surprisingly, I've actually had some good success this evening on solving most of these problems. I'll post my results once I've finished up just in case anyone else can be helped by what I've learned.
    One question remains for the moment: I've inserted text within an XML element, but outside of XML tags (e.g., </title>EDITION:<edition>) using "insertTextAsContent":
    [xmlElementHere].insertTextAsContent("EDITION:", XMLElementPosition.beforeElement); 
    Does anyone know a good way to apply a paragraph style to that text without using a find & replace function later (after placing the XML into a text frame)?

    As posted into the other thread:
    Yes, each record will be in its own frame.
    You can use one of a couple solutions to stitch (link) each frame to the other, delete all but the first page and the first merged record, then resize that first merge frame and reflow the entire document.
    https://forums.adobe.com/thread/1341730?start=0&tstart=0
    Please review this thread. There is a couple posts with a script and you would want the last version of that script. You would have to follow the directions, as well as add a column at the beginning of your data and fill it with consecutive numbers.
    Alternatively, there is a free plug-in by Rohiko for stitching merge data frames together, then follow the process above to reflow the document.
    https://www.rorohiko.com/wordpress/indesign-downloads/textstitch/
    Mike

  • Different paragraph styles within a text thread

    Does anybody know if it's possible to apply a different paragraph style to each text box in a text thread? I have three boxes: the first and the last have a small font and I'd like the middle one to have a larger font size.
    If it's not possible, is there an alternative way to do this?
    Thanks,
    Nacho

    Offhand i'd say that what Nacho wants to do will entail having separate text boxes...
    Seems to me that what he's doing is having the text flow from one box to another (column?). Obviously, changing / editing content will cause the text to shift its position.
    Nacho, i think you'll have to do one of the following:
    1/ Manually adjust the font style for the box you want each time you mke a correction
    or
    2/ Set up different, independent boxes (text areas) and style the box the way you want. Obviously changing text will mean changes in the area used by that box...
    Maybe someone else here can help out with a better suggestion...

  • Help: apply different para styles to several consecutive paragraphs via script

    Hi all,
    I need to apply different para styles to several consecutive paragraphs via script, something like this (found somewhere on the net):
    var myDoc = app.documents[0];
    var mySel = app.selection[0];
    var myPStyle1 = "A";
    var myPStyle2 = "B";
    //need to add 6 more styles here:
    //var myPStyle3 = "C";
    //var myPStyle4 = "D";
    //var myPStyle5 = "E";
    //var myPStyle6 = "F";
    //var myPStyle7 = "G";
    //var myPStyle8 = "H";
    //the last style not needed in script?
    // apply 1st style to 1st paragraph
    mySel.appliedParagraphStyle = myDoc.paragraphStyles.item (myPStyle1);
    // apply styles to paragraphs after selected
    //2nd style
    mySel.paragraphs[-1].insertionPoints[-1].appliedParagraphStyle = myDoc.paragraphStyles.item (myPStyle2);
    //next style
    mySel.paragraphs[-1].insertionPoints[-1].paragraphs[0].insertionPoints[-1].appliedParagrap hStyle = myDoc.paragraphStyles.item (myPStyle2).nextStyle;
    I've tried badly, but can't find the way to extend the sequence
    Sorry, no skills in scripting yet...
    all styles have 'Next Style' option activated, but I can't use 'Apply style, then Next style' or Object styles, because I need four different sequences of those para styles:
    A-B-C-D-E-F-G-H
    A-B-D-E-G-H
    A-C-D-F-G-H
    A-D-G-H
    and I really don't want to create special clones of the same style for each sequence (Keep It Simple, they say ).
    I believe it can be done via four slightly adjusted scripts...
    any suggestions would be greatly appreciated...

    Sorry about being late to the party, I usually pick up stuff like this right away.
    How about this one?
    1. No separate scripts needed, it uses a tiny dialog where you can choose what style set to use. If I'm correct, you can press a number key on Windows to immediately select one of the items.
    2. It works down from the paragraph your cursor is in. It has nothing to do with text frames, though -- consecutive paragraphs inside a story always ignore any text frames.
    3. Extensible: you can easily change the names of the styles in the top array, and the number of style groups in the list.
    var styleLists = [
              [ "A", "B", "C", "D", "E", "F", "G", "H" ],
              [ "A", "B", "D", "E", "G", "H" ],
              [ "A", "C", "D", "F", "G", "H" ],
              [ "A", "D", "G", "H" ]
    var radiobutts = [];
    styleDialog = app.dialogs.add ({name:"Set Multiple Styles",canCancel:true});
    with (styleDialog)
              with (dialogColumns.add())
                        with (radiobuttonGroups.add())
                                  for (i=0; i<styleLists.length; i++)
                                            // Build radio button string
                                            str = "&"+String (i+1)+". ";
                                            for (j=0; j<styleLists[i].length; j++)
                                                      if (j) str += "-";
                                                      str += styleLists[i][j];
                                            radiobutts.push (radiobuttonControls.add({staticLabel:str, checkedState:false}) );
    radiobutts[0].checkedState = true;
    if (styleDialog.show())
              for (i=0; i<radiobutts.length; i++)
                        if (radiobutts[i].checkedState == true)
                                  break;
              if (i < radiobutts.length)
                        par = app.selection[0].paragraphs[0];
                        for (j=0; j<styleLists[i].length; j++)
                                  par.appliedParagraphStyle = styleLists[i][j];
                                  par = par.parentStory.paragraphs.nextItem(par);

  • Data merging: how to get multiple records in single text frame?

    Hi
    I'm experimenting with data merging in InDesign CS3. The biggest stumbling block I've come across is trying to get my records to flow as continuous text in a single text frame (which would, ideally, autoflow onto new pages in the document). The records vary considerably in length, and so I can't just create a standard text frame to repeat on the page.
    Perhaps data merging isn't the best way of doing this and I should be learning to script instead. I feel like I'm just one step away, though.
    Any suggestions would be appreciated.

    OK, new scenario now:
    Is it possible to set a text box to auto-resize to fit the content that comes in during the data merge?
    I have placed one of my data fields in a text box with a stroke and fill, and placed this as an anchored object in the main text box with the other fields. The problem is that the length of text in this field varies considerably, and I'd like the text to fit snugly within its box. Ideally this text box would not appear at all if the field is blank for a particular record.
    I hope I've explained all of that clearly enough. Any ideas?

  • Multiple columns within a single text frame

    Is it at all possible to make a single text frame containing first a single column followed by two columns?
    Why: I need to have my heading expanding across my two column body text. What's important is that I need the two column body text to automatically drop whenever I type (or paste) in more text in my heading. Like it would if the heading and body text was in a single column.
    My text frame options (I work in CS3) do not give me this option, I can only work in one "frame set". I have tried fixing this problem with combinations of tables, multiple text frames and text wrap, but nothing really works.

    Thank you Peter.
    Yes I did try it.
    InDesign CS3 just gives me this alert:
    I also tryed copying the files (HeadStraddler.jsx and HeadStraddler.indl) into a folder like you suggested.
    C:\Program Files\Adobe\Adobe InDesign CS3\Scripts\Scripts Panel\Version 4.0 Scripts\HeadStraddlerForCS2.
    But I just get the same alert.

  • Create a  continuous flow of records in a single text frame

    I've searched past posts and cannot find the answer (though I'm sure the questions been asked aplenty).
    I have an Excel file with Company names, addresses, telephone numbers, emails and websites, etc. which are to be placed in a directory. I can't extract each company's details and get get them to flow in a single text frame (instead each seems to extract into it's own frame).
    Can anyone tell me what to do, please. I've spent more than an hour looking at the forums and various tutorials, etc.
    Bongani

    It might help if you post what versions of InDesign and Excel that you use, what OS you are in, and what format the Excel file is (.xls, .xlsx, .txt, .rtf, etc.). Also, you said your data needs to be placed, but some people paste instead of place, so I thought I'd ask you to specify how you are getting your data into ID.
    EDIT: Are you getting a table, when you want a text frame? I only ask because a table can look like a bunch of separate text frames.

  • How to use different font styles in the same boolean text?

    Hi all,
    As reported here http://digital.ni.com/public.nsf/allkb/6BD344ACA4DEE20A8625692700737E16, it is possible to change font color, size or other font properties of a subtext in a string indicator. This can be applied to a caption too.
    I'd like to apply this properties to a boolean text but it does not work. The boolean control has the Text.selectionStart and End property node but it does not appear to function.
    Can you help me?
    Thanks all

    This is a bug in the development environment (I think it showed up around LV8).
    There's a workaround, but it seems to work intermittently: Place some floating text on your front panel, then edit it's font styles.  Select and copy the floating text.  Select the boolean text (double click on it).  Paste.

  • How do I apply style within a text frame linked object

    I'm selecting the text frame in the object I want to apply an object style
    A script can be written
    within a text frame the linked object (selected text frame)
    how object style is applied

    Hi
    All you need is
    app.selection[0].appliedObjectStyle = app.activeDocument.objectStyles.itemByName ("Trevors Object Style");
    The below snippet will apply the style to all the anchored objects in the selection or document
    var doc = app.properties.activeDocument,
        myOnjectStyle = doc.objectStyles.itemByName ("Trevors Object Style"),
        myObjects, l;
    if (!myOnjectStyle.isValid) {
        alert ("Either add an Object Style Called:\nTrevors Object Style\nOr Make Significant Changes to The Script");
        quit ();
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "^a";
    myObjects = (app.selection && app.selection[0]).findText () || doc.findText ();
    l = myObjects.length;
    while(l--) myObjects[l].textFrames[0].appliedObjectStyle = myOnjectStyle;
    HTH
    Trevor

  • Is it possible to create different font styles within the same text field?

    The form I am creating is getting really complex because when different fields require different font treatments (bold, italic, different font size, different font) I have to create a seperate text box and get it to align with the others. This wouldn't be an issue in most cases but this form is really detailed and has many text boxes. Before I stuggle too much longer on it, I thought I would check and see if there is a way to make them all in the same text field. If not, perhaps I am trying to use Acrobat for something it is not meant for. Any recommendations on other programs I could use? Thanks

    Thank you try76. I'm not sure if I did it correctly. As soon as I tick the Rich Text Formatting box it automatically changes the appearance of the text in the field (Helvetica Light to something like Helvetica Heavy) I can't seem to get the font back to Helvetica light or change the font size while the Rich Text Formatting box is ticked.

  • How to? change to different paragraph style only after column/frame break

    I'm all over paragraph styles and next styles option, all good, sweet. Love em but...
    But when I'm flowing in a long document with multiple text frames on different pages I would like the first paragraph in each of those text frames to be paragraphy style A, then using next styles let it follow on through B, C, etc, till then next time it see's a column/page/frame break character then go back to heading style A.
    I can't find a way to do this for love nor money.
    I've used objecy styles with paragraphy styles and next style turned on but this only seams to work on the first text box not the remaining text boxes that have flowed on text.
    HELP!!!!

    Eugene Tyson wrote:
    For Paragraph Style A go to the Keep Options in the style, and select to Start on Next Page or Next Column or Next Frame - whichever suits.
    Then it automagically does it
    If the content being flowed-in is correctly tagged with style names, then this would work.
    However, I believe the OP wants any paragraph that follows a flow break to be tagged with a specific style. If this is correct, either a script or a plug-in is probably necessary. in-tools.com has some terrific commercial composition tool products; perhaps one can do at least the first step - assigning a style to a paragraph that follows a break.
    In InDesign, assigning specific styles to the subsequent paragraphs based on the Next Style property, requires selecting the paragraphs to be assigned. I'm not sure if there's a plug-in or script that can use the break to trigger the Apply Next Style feature.
    Then, of course, is the question of how should this automation work if editing causes text to reflow across breaks. It's possible this could become the "yo-yo" effect that happens when more consecutive paragraphs than can fit in a text container are tagged with the keep options next and previous.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices
    Message was edited by: peter at knowhowpro

Maybe you are looking for