*** i moved to my own blog site so to check on my future posts, please go to www.junblogs.com  ***

a question has been raised before whether we can fully justify in an rtf control but i am currently busy with enhancing my classes plus creating new ones i can think of to add beauty to a form’s appearance that i simply tuck this question away at the back of my mind for later retrieval and playing.

so after the 8 classes is posted,
i opened up my rtf control here and much to my dismay, i believe it really is
impossible to do that as even copy-pasting a fully justified document from word
into the rtf control automatically converts fully-justified paragraphs into a
left justified one.  even importing from
a doc or docx (please see my previous posts on how this can be done) have the
same result.  so i gave up finding out
how in an rtf control.


nevertheless, if we cannot do
that in an rtf control on a form, at least we can do that when we export the
rtf control’s contents (textrtf property) into a doc file or simply saves it as
an outside rtf from a memo field.  in
that way, our document is presented better.


the trick to make it proper is to
only apply full justifications on left-justified paragraphs.  we should not touch right and center justified
paragraphs, i will show you later how to do that.  what this trick will do is save content of an
rtf control into a physical file, turns left justified into a right justified
one, then utilizes shellexecute() to open the file via its default program like


we will presume that you have an
rtf control named olertf in a form (if you don’t have one yet, you can download
any of the previous samples i gave last time regarding rtf), then add a command
button and in its click event paste these:

#define wdalignparagraphleft     0
#define wdalignparagraphjustify  3
#define wdparagraph              4
#define wdline                   5

local loword as word.application, lnloop as integer, lctemprtf as character
loword = createobject("word.application")

* crate a filename reference in the local user’s temp folder, to be used for saving.  saving can be done via strtofile() but an rtf activex control has a built-in method for that so we will use that instead

lctemprtf = addbs(getenv("tmp"))+sys(3)+".rtf"

* open it up via automation

* now we will check from top to bottom its justification settings and replace only the left justified ones
for lnloop = 1 to loword.activedocument.paragraphs.count
    if loword.selection.paragraphformat.alignment = wdalignparagraphleft
        loword.selection.paragraphformat.alignment = wdalignparagraphjustify

* save the changes made, close it, and quit word

* open it in its default program to see outright the result
declare integer shellexecute in shell32.dll ;
    integer hndwin, ;
    string caction, ;
    string cfilename, ;
    string cparams, ;
    string cdir, ;
    integer nshowwin


and there you have it, a very simple trick yet an effective one.  to test this properly, you can change justifications of some paragraphs into center or right in an rtf control before performing the above trick.  you will see that those settings will be retained in the final output.

the only problem i can see with the above is it will be applied to the entire document, i.e., all left justified paragraphs will be fully justified.

and here are the other two constants that we don’t need in the above trick but maybe will be useful on your playings as well:

#define wdalignparagraphcenter    1
#define wdalignparagraphright     2

i hope this simple trick will be useful to you. 

in fully justifying of the contents of a memo field containing an rtf format in the native vfp report, i will take the liberty to refer you to mike gagnon’s wonderful article: http://www.atoutfox.org/articles.asp?action=fconsulter&id=0000000131


2 Responses to Fully Justify an RTF

Leave a Reply

Your email address will not be published. Required fields are marked *