It's all about the answers!

Ask a question

How can I change the font size of an artifact in RPE from DNG with javascript?

David Clark (234847) | asked Jun 09 '16, 7:00 p.m.
 I have tried several ways to do this. I am new to Javascript and obviously I am missing some very fundamental thing.
When I test this script on the individual artifact RTF/XHTML in the debugger it does what I want. But when running to completion in RPE, it does not modify the artifact, such that the change is picked up.

Here is what I wrote (elegance was not the point ;-) at this time.

var pos ="font-size");
var font_str = div.slice(pos,pos+20);
var pos2 =">");
var full_font_size_str = font_str.slice(0,pos2-1);
var new_fs = full_font_size_str.slice(0,10);
new_fs = new_fs + "14pt";

Here is the first artifact my script encounters:
<p dir="ltr" id="_972" style="margin-left: 0px; ">
<span style="font-size:10pt">
<span style="font-family:arial,helvetica,sans-serif">The CC application&#160;</span>
<span style="font-family:arial,helvetica,sans-serif">
<b>shall&#160;</b>capture and<b>&#160;</b>
<span style="font-family:arial,helvetica,sans-serif">store up to 14 </span>
<span style="font-family:arial,helvetica,sans-serif">accelerometer channel readings (configured by PDI_TBD) at a rate of 1kHz.</span>

here is the second:
<p dir="ltr" id="_1460486204393">The CC application&#160;<b>shall&#160;</b>scale the <i style="font-family:arial,helvetica,sans-serif; font-size:14.6667px">accelerometer channel readings</i> to units of g&apos;s using the accel_scaling pdi.</p>

Eventually, I need to also strip all hyperlinks out as well. Our systems group is utilizing the term links in DNG but we do not want these in a WORD document.


Accepted answer

permanent link
Subramanya Prasad Pilar (4.6k14) | answered Jun 10 '16, 5:14 a.m.
edited Jun 10 '16, 5:22 a.m.
This should work in RPE 1.2 and later versions. If I understand your requirement correctly, you  want to change the font-size to 14pt, if it is set to any other value in DNG. This can be easily done using javascript replace with regexp.

Please use the following in Script Expression:
div.replace(/(font-size:)\d+(pt)/g, "$1"+14+"$2"); //$1 = (font-size:) and $2 == (pt)

or simply

div.replace(/font-size:\d+pt/g, "font-size:14pt");

Note that both “XHTML Input” and “XHTML Output” are checked. If you want to edit the rich text further, make sure that the Script Expression returns valid XML. Otherwise, the document generation stops with an error.
You may find this link useful -
David Clark selected this answer as the correct answer

David Clark commented Jun 10 '16, 8:36 a.m.

This gets me past my road block, thank you.

My problem was I inserted a JavaScript block as separate from the text block, not embedded the script in the text block.

So that issues is resolved. Thank you.

Now I need to figure out how to make it generic, not all font settings are the same, how to change the font type as needed and how to get ride of hyperlinks for term linkage from DNG...


Subramanya Prasad Pilar commented Sep 23 '17, 8:28 a.m. | edited Sep 23 '17, 8:31 a.m.

Please use

This works for both "font-size: 11pt;" and "font-size:11pt;"

One other answer

permanent link
Fariz Saracevic (904613) | answered Jun 09 '16, 10:55 p.m.
Hi David,

Could you let us know which RPE version are you using?

Thank you.
Fariz Saracevic

PS. I suggest that you bookmark following link as you will find a tons of useful RPE articles. You can subscribe by clicking follow on the right bottom of the web page and you will be notified when new article is posted.

Your answer

Register or to post your answer.