Printing fields with images included by « set the imageSource of such char » (some insights)

André.Bisseret Andre.Bisseret at inria.fr
Sun Mar 26 14:10:59 EST 2006


Hi !
As far as printing is concerned, I am a newbie. I used to develop a 
number of stacks in HyperCard, but without having to ever print any.
So I don't know how it was with HyperCard ! But I am discovering that 
printing in RR is not easy at all (at least for me!).

Well, I did not receive any answer to the questions below (neither to 
another previous one).
Printing seems not to be a very exciting theme ;-))

Anyway, in case of at least one other newbie in printing be interested, 
I am reporting on how I managed to figure out my problems.


> De: André.Bisseret <Andre.Bisseret at inria.fr>
> Date: Thu 16 Mar 2006  13:33:11 Europe/Paris
> À: use-revolution at lists.runrev.com
> Objet: Printing fields with images included by « set the imageSource 
> of such char »
>
> Hi !
> On each card of an App. I have differents texts ; some are including 
> images that are put there by means of one char on a line (ex. : 
> £,§,€…) whose imageSource is set to an image number (the images are in 
> a special substack).
> I want the user be able to print the text of this fld.
>
> My first method is the following :
> I created a hidden field (in the main stack), say field « toPrint » in 
> which I am composing (from several fields in a card) and formating the 
> text to print.
> The core of it is :
> put fld « theText » into fld « toPrint »
> set the HTMLText of fld « toPrint » to the HTMLText of fld «theText ».
>
> Then I print with
> revShowPrintDialog false,true
> put tab & "Page " & "<%pageNumber%>"  into footer
>   revPrintText (the htmlText of fld "toPrint"),,footer
>
> That works very well on Mac, The field « toPrint » is printed exactly 
> as I want, including printing the images nicely.
>
> But testers got problems with Windows
mainly: repetitions of parts of the text on new pages, large white 
areas between lines; lines being cut (while there is no cr) etc.

After a lot of trials and errors I discovered that it was a problem of 
Font and FontSize.
First, I had several lines whose TextFont was set to "Geneva" ; A 
friend who knows Windows quite well suggested to me to replace Geneva 
(does not exist on Windows) by "Verdana"; this only change eliminated 
nearly all problems.
>
But some were remaining and I tried
> another method using a special PrintingStack with two fields, one, 
> say, the « bufferField » the other the fldToPrint : filling in the 
> second while emptying the first, line after line (thanks to the 
> explanations I founded in the SmartEBook on Printing by Dan Schafer).
>
> .Mainly :
> repeat until the formattedHeight of fld "fldToPrint" of cd cardNum >= 
> gPrintHeight
>     set the htmlText of line lineToAdd of fld "fldToPrint"\
>     to the htmlText of line 1 of fld "bufferField" of cd 1
>     delete line 1 of fld "bufferField" of cd 1
Now, after that, I had to format again (due to the fact that sometimes, 
the last line of fldToPrint is not entirely visible, so it is necessary 
to delete it and put it on the top of next cd).
Then, I had to suppress (as far as they are detectable) the "isolated 
lines" (? "ligne orpheline" in French) at the end of fld "fldToPrint" : 
for example and mainly when last line is a title; then I have to delete 
it and paste it at the top of next card.
>
> All works well if there is no image.
>
> When there is an image, the image appears normally.
> BUT  it is followed by an incredible mess (a lot of chars such as 
> squares, apples, and so on) which could take several pages if it was 
> not  remaining on the same card where the image appears.
> Then the normal text is following, normally on another created card.
The solution I found and adopted is to script:
copy line 1 of fld "bufferField" of cd 1 -- instead of "set the 
htmlText of line 1… etc.
and then (in fld "fldToPrint")  paste
In case of an image line, as well as for a normal line, all is OK (with 
Windows and Mac as well); not any more  "incredible mess" :-))).

COPY AND PASTE is the best way I have found : very simple, it works 
with images and it keeps html formating of the text.

One problem was remaining : one line was set in Verdana 9:  when 
printed it was often cut under the right edge of the field.  I set the 
fontSize to 10 instead of 9  and it  worked normally !!!! (well, I 
would have prefer to keep a smaller fontSize, but in this case it is 
acceptable).

And, eventually, I print ;-))
Here again I got troubles ! not any with Mac with which several 
different scripts work well.
but with Windows a lot of disappointments :-(((. (in particular, I 
tried to play with the "formatForPrinting" property (save, close, set 
formatForPrinting to true, re-open stack, print, set formatForPrinting 
to false, and so on.....

At last, the script I adopted, because it works on Windows as well as 
on Mac is :

on PrintTheReport
   FormatTheReport
   go to stack "PrintingStack"
   set the printmargins to 72,50,50,72
   put the cardNames of stack "PrintingStack" into cardsToPrint
   answer printer
   open printing with dialog
     if the result is "Cancel" then exit PrintTheReport
        repeat for each line tCd in cardsToPrint
       print tCd
     end repeat
     close printing
end PrintTheReport

I hope that will help some people to save time and annoyance

Best regards from Grenoble
André






More information about the Use-livecode mailing list