Javascript Adobe IllustratorAlthough it is generally not recommended to open in Illustrator a PDF generated, for example, from InDesign or QuarkXPress, or simply generated from Illustrator but saved as PDF/X, we eventually end doing it at some point when the source file is not available and we simply want to pick up some graphic assets to reuse in a new design work. We can notice then that the paragraphs are always split into several left-aligned point texts, that some characters originally affected by an horizontal scale in the source file appear affected by an inverse vertical scale and a different point size, that some characters, especially dingbats, sometimes turn out converted to outlines, etc. This extension for Illustrator CC+ (html5 panel not compatible with old CS versions), baptized «Text rebuild tools», gathers a few functions, some of them already published here as separate jsx scripts, to help recreate and rebuild editable lines/paragraphs/stories from these items.

TextRebuildTools ai008 fit text to outline enYou will recognize the “Fit text to outline” function that enables to fit exactly a text item to the bounds of a vector item;
TextRebuildTools ai008 hv scale motionless change to 100 enalong with the Invert characters horizontal/vertical scale function enabling to change, for example, a 18pt character with a 111.11111% vertical scale to a visually identical 20pt character with a 90% horizontal scale & vice versa;
TextRebuildTools ai008 justification motionless change ena new function to change the paragraph alignment of a point text without moving it, in order to restore the alignment mode of a text line back to what it was in the original source file, systematically replaced with left-alignment when we open in Illustrator the generated pdf;
TextRebuildTools ai008 merge into one story enyou will also recognize the Rebuild broken text function enabling to rebuild editable text lines/paragraphs/stories from text split in several frames — frequently encountered case some others script were developed for such as John Wundes’s or Justin Putney’s.

Reference:

TextRebuildTools ai008.13 fr param

“Fit text to outline” > You need to select both a text and one or more vector items and the script will fit the text to the items. [cf. 178-fit-a-text-to-an-outline]


Motionless [that is generally quite invisible] changes:

Redefine characters vertical or horizontal scale to 100%: invert characters horizontal/vertical scale while preserving the appearance [cf. 202-invert-characters-hv-scale]:

  • “vertical” > Set vertical scale to 100%, adjust horizontal scale and font size accordingly.
  • “horizontal” > Set horizontal scale to 100%, adjust vertical scale and font size accordingly.

Redefine selected character baselineShift to [value] > Using Text tool, select only one reference character with or w/o a baseline shift and the script will replace this shift value with the desired one, recalculate the baselineShift for every other character in the text, and move the text anchor to restore the characters initial visual position.

Redefine paragraph alignment to

  • “left” > Set paragraph alignment to left, then move the text anchor to restore the characters initial visual position.
  • “center” > Set paragraph alignment to center, then move the text anchor to restore the characters initial visual position.
  • “right” > Set paragraph alignment to right, then move the text anchor to restore the characters initial visual position.

Merge text parts into one single line/single paragraph/single story [cf. 187-rebuild-broken-text-in-illustrator]

  • “single line” > Attempts to merge all selected text frames into one single line, adding some “baseline shift” to the non-aligned texts parts in order to keep the aspect. Suitable for example when you want to merge on a same line several text frames including some offset split parts resulting from superscript or subscript.
  • “single paragraph” > Merges on a same line only actually vertically aligned text frames (with a tolerance defined using the “Same line threshold” parameter), then merges the (single or multi-line) texts items into one single paragraph (the joined texts will be separated by ¬ soft returns) in a single text item. The distribution of the joined texts will be reproduced wherever possible by seeking the paragraph alignment mode (left with optionally 1st line indent, center or right) that best preserves the initial horizontal distribution and the leading preserving the vertical distribution.
  • “single story” > Merges on a same line only actually vertically aligned text frames (with a tolerance defined using the “Same line threshold” parameter), then merges the (single or multi-line) texts items into one single story (the joined texts will be separated by ¶ carriage returns/end-of-paragraph) in a single text item. The distribution of the joined texts will be reproduced wherever possible using paragraph attributes, vertically using “space before/after” parameters, horizontally using “left/right indent” parameters.

↳ Parameters:

  • “Detected text rotation” > To simply inform you that a rotation was detected and the script will have to temporary cancel then restore this transformation to get correct results.
  • “Add space threshold” > If there is an horizontal gap between two consecutive text parts to merge: 1) for a gap width above this threshold (defined in thousandths of an em of the font size of the last character of the first text part), one or more spaces will be appended at the end of the first text part before appending the characters from the second text part; 2) for a gap width below this threshold, the tracking value of the last character from the first text part will be increased before appending the characters from the second text part [you might have to increase this threshold sometimes, for example to merge spaced caps without seeing spaces inserted between them].
  • “Add attribute threshold” > Threshold used to decide whether an existing horizontal/vertical offset between text parts to merge is enough significant to add/modify some character/paragraph attributes such as “baselineShift”, “left/right indent”, “1st line left indent” in order to preserve the characters distribution, or if this offset is insignificant and should better be ignored. For example if there is a vertical offset between two consecutive text parts to merge on a same line (when using the merge into one line button, or when the vertical offset remains below the “Same line threshold”): 1) for an offset above the “Add attribute threshold”, the baselineShift value of the characters from the second text part will be modified before appending these characters to the first text part; 2) an offset below this threshold will be simply ignored.
  • “Same line threshold” > Parameter for merging text parts into one multiline text (ignored when using the merge into one single line button): if the vertical offset between two text parts to merge is below this threshold, the text parts will be merged in a same line (note that consequently a series of an unlimited amount of consecutive text parts separated by vertical gaps below this threshold between them can end merged in a same line even if the offset between the highest and the lowest of the series is above this threshold).

Keep joined paragraphs vertical spacing using

  • “space before” > When joining two consecutive paragraphs, keep the vertical spacing between them by adjusting the “space before” parameter of the lower paragraph.
  • “space after” > When joining two consecutive paragraphs, keep the vertical spacing between them by adjusting the “space after” parameter of the upper paragraph.
  • “leading” > When joining two consecutive paragraphs, keep the vertical spacing between them by adjusting the character leading of the 1st line of the lower paragraph.

Keep joined paragraphs horizontal distribution using indents computed from

  • “leftest text” > When joining several text items whose anchors have different horizontal coordinates (with offsets beyond the “Add attribute threshold”), keep their horizontal distribution by adjusting the “left/right indent” parameters of the paragraphs, computing indents from the leftest joined text item. The anchor horizontal coordinate for the resulting text will then be the same as for the leftest joined text. Appropriate for left-aligned or justified paragraphs.
  • “rightest text” > When joining several text items whose anchors have different horizontal coordinates (with offsets beyond the “Add attribute threshold”), keep their horizontal distribution by adjusting the “left/right indent” parameters of the paragraphs, computing indents from the rightest joined text item. The anchor horizontal coordinate for the resulting text will then be the same as for the rightest joined text. Appropriate for right-aligned paragraphs.

“Set consistent kerning/tracking” > For use when the Character panel shows zero for kerning value and a different tracking value for every character of the selected text: This function tries to apply to the selected characters the different kerning modes (Metrics - Roman only, Auto, Optical, 0/No auto kern) and different consistent tracking and word spacing values, then selects those best matching the characters visual position.

↳ Parameter:

  • “Tolerance” > The attempt to set consistent kerning, tracking and word spacing to the selected text will be considered successful if the characters average horizontal resulting offset from their initial position remains below this tolerance threshold. Otherwise the modification will be cancelled.

“Equalize leading” > Apply an uniform leading to all characters in selection.

Add comment

Follow Scriptopedia to Social Network

Scriptopedia sur facebook

About Scriptopedia.org

An original idea from Loic Aigon, designed by Eddy.VH. It 's a scripts library for Desktop Publishing Adobe products. Find Javascript for Photoshop, Illustrator, inDesign and Acrobat or ATN scripts ( Photoshop actions ) you need.