1. Glenn Scamman
  2. PowerBuilder
  3. Wednesday, 22 September 2021 23:22 PM UTC

I'm using PB2019 R3 Build 2703.

The TX Text Control ActiveX 28.0 control appears to have an issue saving document margin info.  You can set the margins on the control in powerscript, and they will appear properly while the document is open, but when you save the .rtf document, the margins are always just "1" in the resulting file.  Interestingly enough, if you save with a .doc extension (older Word format), the margins are saved fine.  I tried saving as HTML, and it loses the margin information too.  Using the margin arrows in the RTE control ruler-bar also works visually, but doesn't seem to set the margin values for saving. 

I searched around, and many people have also had issues with the RTE controls, but I didn't find any solutions for how to fix the margins issue.

Since the problem only manifests itself in the saved RTF documents, I decided to capture the margin properties right before saving, and then open and write the proper margin values into the just-saved file.  So far, this has worked, so I thought I'd share it for others experiencing this problem.  If there is a true solution to this issue, rather than a workaround, please let me know.

 

Step 1 - BEFORE the call to rte_1.SaveDocument( ls_filename ), get the margin values

Long ll_B, ll_T, ll_L, ll_R
String ls_FileType, ls_Temp

//Get the real margins (in 1/1000ths of an inch)
//Found I must get these BEFORE the save, because the control and the file both switch to '1' during the save.
ll_B = rte_1.BottomMargin
ll_T = rte_1.TopMargin
ll_L = rte_1.LeftMargin
ll_R = rte_1.RightMargin

 

Step 2 - I wrote a function to be called right AFTER the rte_1.SaveDocument( ls_filename ) call. 

I named the function of_FixFileMargins. Pass the file name with path, and the margin values to this function.

/******************************************************************************
Desc: Fix an apparent RTE control bug, which, when saving RTE control contents to a .rtf file, it ignores the
margins that have been set, and saves them as '1' no matter what. I'm opening and fixing the file.
Prog: Glenn Scamman
Date: 21-Sep-21
Arguments: String Value as_filename (The full path of the file just saved by the SaveDocument command)
Long Value al_L (The left margin value, in 1/1000ths of an inch)
Long Value al_T (The top margin value, in 1/1000ths of an inch)
Long Value al_R (The right margin value, in 1/1000ths of an inch)
Long Value al_B (The bottom margin value, in 1/1000ths of an inch)
Mods:
--------- --- -----------------------------------------------------------------
******************************************************************************/
Boolean lb_Changed
Integer li_File
Long ll_Rtn, ll_Pos, ll_twips
String ls_FileString, ls_NewMargin
n_cst_String lnv_String

lb_Changed = FALSE

//Open the just-saved file, and alter the margin entries. Must convert 1/1000ths to twips.
li_File = FileOpen( as_filename, TextMode!)
if li_File >= 0 then
//Fileread never worked until I didn't supply the optional value, but then I can't write to the file.
//Opening a file with Replace! mode, wipes out the file even if you aren't ready to.
//I'll try reading in one pass, then if it needs adjustment, writing in a second pass.
ll_Rtn = FileReadEx( li_File, ls_FileString )
FileClose( li_File )
if ll_Rtn < 0 then
RETURN -1
end if
end if

//Search the string for the margin commands to replace.
ll_Pos = Pos( ls_FileString, "\margl1\" )
if ll_Pos > 0 then
lb_Changed = TRUE
ll_twips = al_L * 1.440
ls_NewMargin = "\margl" + String(ll_twips) + "\"
ls_FileString = lnv_string.of_GlobalReplace( ls_FileString, "\margl1\", ls_NewMargin, TRUE )
end if
ll_Pos = Pos( ls_FileString, "\margt1\" )
if ll_Pos > 0 then
lb_Changed = TRUE
ll_twips = al_T * 1.440
ls_NewMargin = "\margt" + String(ll_twips) + "\"
ls_FileString = lnv_string.of_GlobalReplace( ls_FileString, "\margt1\", ls_NewMargin, TRUE )
end if
ll_Pos = Pos( ls_FileString, "\margr1\" )
if ll_Pos > 0 then
lb_Changed = TRUE
ll_twips = al_R * 1.440
ls_NewMargin = "\margr" + String(ll_twips) + "\"
ls_FileString = lnv_string.of_GlobalReplace( ls_FileString, "\margr1\", ls_NewMargin, TRUE )
end if
ll_Pos = Pos( ls_FileString, "\margb1\" )
if ll_Pos > 0 then
lb_Changed = TRUE
ll_twips = al_B * 1.440
ls_NewMargin = "\margb" + String(ll_twips) + "\"
ls_FileString = lnv_string.of_GlobalReplace( ls_FileString, "\margb1\", ls_NewMargin, TRUE )
end if

//If margins are off (which they always are), then re-write the file with the proper margins.
if lb_Changed then
li_File = FileOpen( as_filename, TextMode!, Write!, LockReadWrite!, Replace!)
if li_File >= 0 then
//Write the amended string back to the file
ll_Rtn = FileWriteEx( li_File, ls_FileString )
ll_Rtn = FileClose( li_File )
end if
else
RETURN 0
end if

RETURN 1

 

I apologize for not knowing how to format very will in this website. All the indenting was lost when pasting the code.

Regards...

Who is viewing this page
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 26 November 2021 08:55 AM UTC
  2. PowerBuilder
  3. # 1

Thanks for sharing!

Here's how to format code in this Q&A: https://community.appeon.com/index.php/qna/q-a/q-a-forum-tip-including-source-code-in-your-question

regards

Comment
There are no comments made yet.
Mark Lee @Appeon Accepted Answer Pending Moderation
  1. Friday, 26 November 2021 05:25 AM UTC
  2. PowerBuilder
  3. # 2

Hi Glenn,

 

Regarding the "but when you save the .rtf document, the margins are always just "1" in the resulting file." issue, I built a small case here using the TX Text Control ActiveX 28.0 with PB 2019 R3 2703 and PB 2021 Build 1311, but can't reproduce the issue.

So can you provide a simple reproducible test case (including the PBT/PBL) for more study? Thanks in advance!

 

Regards,

Comment
  1. Glenn Scamman
  2. Tuesday, 7 December 2021 20:24 PM UTC
Mark, I will try, but it probably won't be until January. Too busy right now. Also, I may be updating to PB 2021 fairly soon and I can see if I still have the issue.
  1. Helpful
  1. Mark Lee @Appeon
  2. Wednesday, 8 December 2021 01:01 AM UTC
Hi Glenn,



OK, we look forward to hearing from you!

  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 23 September 2021 12:09 PM UTC
  2. PowerBuilder
  3. # 3

The rte was fine in the past, but now I hate it more and more every day and we heavily depend on it.

For how to format you pasted code:  https://community.appeon.com/index.php/qna/q-a/tip-for-pasting-code-and-not-loosing-white-space-and-indentation

regards

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.