Windows Printing

depstein at att.net depstein at att.net
Sun Aug 29 09:18:26 EDT 2004


Jacqueline Landman Gay wrote of Windows printing problems:

> The printing stack has its 
> formatForPrinting set to true.
> 
> My script fills both fields, prints the card, prints a break, then 
> repeats until the data is gone.

The documentation for "formatForPrinting" warns us never to edit a field with its formatForPrinting set to true.  A script that "fills both fields" is editing a field with formatForPrinting set to true.

I experienced the symptoms you described, plus the program frequently simply quitting, while trying to print in Windows using Metacard 2.5.  I believe I have now remedied the problem by having my script repeatedly call this command:

on ffp whether
  set the formatForPrinting of stack <myPrintLayoutStack> to whether
end ffp

FormatForPrinting needs to be FALSE before the script changes a field's content (including filling it in the first place), and it needs to be TRUE before you try to determine what changes are needed based on how the text fits in the space available (and before you print).  For example, here's handler I use to determine what text doesn't fit in a field and needs to be moved to the next column or page:

function extraText f -- returns the htmlText that overflows size of fld f
  ffp true -- SO THAT FORMATTEDHEIGHT WILL BE PROPERLY CALCULATED
  repeat with c = 1 to length(fld f)
    if the formattedHeight of char 1 to c of fld f > the height of fld f then
      put the htmlText of char c to -1 of fld f into myHtml
      ffp false -- BECAUSE I'M ABOUT THE CHANGE THE CONTENT OF FLD F
      delete char c to -1 of fld f
      return myHtml
    end if
  end repeat
  ffp false -- READY FOR FURTHER EDITS OF FLD F
  return empty
end extraText

Just before you print, set ffp true again.  Somewhere (but not in Rev docs, I think) I read advice suggesting a further precaution:  close and open the stack and then set formatForPrinting to true.  So I added this just before printing:

    set the destroyStack of stack <myPrintLayoutStack> to true
    save stack <myPrintLayoutStack>
    close stack <myPrintLayoutStack>
    open stack <myPrintLayoutStack>
    ffp true

This last bit seems a littler superstitious, but since I made these fixes a couple of weeks ago my Windows printing has worked properly.

I hope this will help with your difficulties.

David Epstein


More information about the use-livecode mailing list