Hi'ya,
I'm still struggling with printing fields !
I have a card with two fields on it. The user can type HTML text (he/she can 'format' the text with colour, bold, italic... etc...) of various length into each of the fields - he/she could 'format' the line length themselves hitting 'cr' -or- LC will wrap the text at line end automatically.
Each of the two fields contains HTML formatted text of various length, some text 'lines' occur on a single screen/page 'line', whilst other text 'lines' may be auto wrapped and 'spread' over several screen/page 'lines'. Furthermore the amount of text (number of lines of text) in each field is variable.
OK, So, printing... should be a pretty simple affair... hmmm...
By getting the 'formattedlength' of the field that contains the required text I can set the height of the control on the print card and 'spread' (print) the text over multiple pages as required. I can even gang up the two controls so that they 'flow' correctly on my print pages be that one page overall (not much text in either of the two controls) or multiple pages (loads of text in one or more of the controls).
The problem : 'formattedlength' reports the overall height of the control required to display the text without needing to scroll (obviously, no good for printing) the said control. Using this value I can check required height of my control and set its height to suit / decide if I need to spread the text of the control over multiple print pages.
So, after using 'formattedheight' to detect if the required control height for text it contains and noting the required control height is greater than the available page space, I can then use a simple repeat structure to detect how may lines of text will fit the available space/control size, populate the control with only that number of lines and repeat printing pages as required... Seems simple enough (now that I've spent some time on it) but... there's always a but... !!
[1] I don't seem to be able to maintain my HTML formatting (bold, italic, colours etc) once I start to manipulate/copy chunks of the user's text between fields...
[2] using the 'Line' command (e.g. : put line 3 of control sMyText into sMyLine) does not put the line 3 (per se) of the control's text as it is seen in the control on the card but rather the line as it is separated by crlf (basically as the user entered it) into sMyLine
[3] inserting '<br>' or '<p>' into the user's text to manually break up (format to line length) the lines actually results in inserting <Br> (or somesuch) which does not result in a formatting command - just a load of chars - which I can understand but LC renders 'incorrectly'...
The long and the short is I'm very confused (having spent numerous DAYS on this) and having played with 'formattedheight', 'formattedwidth' and chunks in repeat loops I'm no further on to being able to display a piece of html formatted text over multiple pages without chopping some of it off, missing out some of it or losing the original html formatting...
Anyone able to decypher / make any sense out of the above and come to my rescue please ?
Thanks a million.
Trouble formatting for printing
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Trouble formatting for printing
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1
Re: Trouble formatting for printing
I think you're looking for the pageHeights property. That tells you how many pages of text your field will require, and how much to scroll the field before printing each "page". That way you don't have to calculate much of anything and you don't have to change the content of the field.
Note that you can scroll a field by script even if it doesn't have a scrollbar.
Note that you can scroll a field by script even if it doesn't have a scrollbar.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Trouble formatting for printing
Thanks Jacque,
Continuing to struggle with this one... but making progress. I'm having difficulty even trying to explain precisely what I'm trying to achieve. I'll give this some more thought and revert at a later date.
Thanks a mil for the help and support - appreciated.
Continuing to struggle with this one... but making progress. I'm having difficulty even trying to explain precisely what I'm trying to achieve. I'll give this some more thought and revert at a later date.
Thanks a mil for the help and support - appreciated.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1
Re: Trouble formatting for printing
Here's a quick overview:
Set up the field so its borderwidth is 0 and margins are 6. If that doesn't work for your layout, then create an inivisible field with those properties and move your content to that field when you want to print. The field does not have to be visible when printing. The size of the field should match the size you want it to be on paper. LC assumes 72 pixels per inch, so make the width and height of the field the number of inches you want times 72. Turn off showBorders unless you really do want a box around the printed text. Make the field transparent, or use a white background color.
The upper left of the printout will start at 0,0 which is the top left of the paper (on most printers 0,0 is actually about a half inch in from the edges of the paper.) If you want a larger margin, set the printMargins in the printing script (again, 72 pixels per inch.) When printing a card, the whole card prints, not just the field, so I usually put the left and top of the field close to 0,0 on the card.
The general script, off the top of my head, is:
You'll probably want to add some error checking, and maybe an "open printing with dialog" command so that users can cancel the printout. There are lots of other print properties you can set to control the printer, page orientation, all sorts of things, but the above should get you started.
I usually create a substack that contains a template for each type of printout I need, one per card. Then I move the content into the right template field(s), open the printing stack invisibly, print, and close the stack. To the user, nothing is displayed.
And...after all that...check out the revPrintField command in the dictionary, which manages a lot of this for you. It's useful for quick printing at the expense of a little less control.
Set up the field so its borderwidth is 0 and margins are 6. If that doesn't work for your layout, then create an inivisible field with those properties and move your content to that field when you want to print. The field does not have to be visible when printing. The size of the field should match the size you want it to be on paper. LC assumes 72 pixels per inch, so make the width and height of the field the number of inches you want times 72. Turn off showBorders unless you really do want a box around the printed text. Make the field transparent, or use a white background color.
The upper left of the printout will start at 0,0 which is the top left of the paper (on most printers 0,0 is actually about a half inch in from the edges of the paper.) If you want a larger margin, set the printMargins in the printing script (again, 72 pixels per inch.) When printing a card, the whole card prints, not just the field, so I usually put the left and top of the field close to 0,0 on the card.
The general script, off the top of my head, is:
Code: Select all
on doPrint
set the printmargins to "72,72,72,72" -- 1 inch margins
put the pageheights of fld "printFld" into tHeights
set the scroll of fld "printFld" to 0
repeat for each line L in tHeights
print this cd
set the scroll of fld "printFld" to (the scroll of fld "printFld") + L
end repeat
end doPrint
I usually create a substack that contains a template for each type of printout I need, one per card. Then I move the content into the right template field(s), open the printing stack invisibly, print, and close the stack. To the user, nothing is displayed.
And...after all that...check out the revPrintField command in the dictionary, which manages a lot of this for you. It's useful for quick printing at the expense of a little less control.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com