Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

[JS/CS4+] Best way to add formatted text?

$
0
0

What is the best way to add formatted text to a document?

 

I'm using two different methods:

 

1. Building a string of any length, including hard returns, in memory, and setting the contents of a Story immediately. Pro: pretty fast, even with (moderately) long strings. Con: you cannot specify any local formatting, only 'global' ones.

 

2. Use the last InsertionPoint.contents to insert one text fragment at a time. Pro: each separate fragment can have its own formatting. Con: extremely slow -- as in: you can see the text appear one fragment at a time.

 

I've done a few random experiments with stuff like "a = new Story", but ID doesn't seem to allow this for any type of formatted text at all ...

 

I'm thinking perhaps an XML approach might work -- add tags and then remap these to character styles (or something -- I'd have to try), but only if inserting those XML tags doesn't make ID crawl as well. Another possibility would be to keep a stack in memory, recording where text attributes would need to be changed, then insert everything as plain text, and only then looping over the attribute stack to assig the formatting 'immediately' to the correct ranges. Sounds like a lot of paperwork, but it ought to work pretty fast. At least, theoretically.

 

Other ideas?


Viewing all articles
Browse latest Browse all 15932

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>