8 Replies Latest reply on Jan 31, 2008 9:21 PM by kglad

    Printing dynamic text exceeding one page

    GerryIsHere Level 1
      Hi there!

      I am building a Flash site in which users can perform searches (via PHP and MySQL).
      Results (html text) are displayed in html scrollable dynamic text fields and simultaneously to an off stage movie clip (see below).
      Results often exceed the size of the field.

      Users may want to print the results (even on more than one page if they are long texts).
      For this purpose, results are also sent to a movie clip (PRINTMC) which contains:
      a) a dynamic text field (printFld) in the first frame (#p) with a stop();
      b) another dynamic text field (dateFld) which received the date
      c) a portrait bounding box in the second frame (#b) with no stop.
      To print, users click a button which code is attached (see below).
      At the moment, printing results are good but incomplete when they exceed one page length.

      I tried unsuccessfully to use TextField.maxScroll in several ways.

      Does anybody can help ?
      I thank you in advance for any advice.

      Best regards,

      Gerry

      I f you want to test the site choose Diffusion --> Quebec in the Navigation Bar, then on the left "Toutes les librairies".
      Beware of the very slow database today! Be patient...


        • 1. Re: Printing dynamic text exceeding one page
          kglad Adobe Community Professional & MVP
          create a movieclip that contains a textfield that you populate and that does not exceed the printable pageHeight of your printjob.

          attach as many movieclips as you need for the entire text, parse the text to your movieclips' textfield and use addPage() to add each to your printjob.
          • 2. Re: Printing dynamic text exceeding one page
            GerryIsHere Level 1
            Excuse me to be so late but today is a hectic one...

            I unserstand the principle in your reply but the related coding will be like hebrew for me !

            Do I attach the movieclips by enumerating them as params between brackets and separated by "comma space"?
            Like:
            ... if (printJob.addPage(PRINTMC.printFld, PRINTMCTWO.printFld, PRINTMCTHREE.printFld, PRINTMCFOUR.printFld)) {... etc
            I feel ridiculously ignorant!!!

            How can I know by advance how many movieclips will be necessary?
            Also, I have no idea how to parse the variable content send to the movieclips...

            I really am the hell of a newbie, am I?

            Anyway, thank you for the reply!

            Regards,

            Gerry
            • 3. Re: Printing dynamic text exceeding one page
              kglad Adobe Community Professional & MVP
              no, apply the addPage() method to one movieclip at a time. using the addPage() method is like using the push() method of arrays.

              you won't know in advance how many movieclips to use. you create your printjob and using its pageWidth and pageHeight properties you create the first movieclip with a multiline textfield. you can assign the width of your textfield to match the pageWidth and use autoSize to increase the height of your textfield as you add more and more text.

              if, as your're adding text, the height of the textfield exceeds the pageHeight, you know you need a line break to continue the text in another movieclip that contains a textfield. etc until there's no more text to allocate to your textfields. add each page to your printjob and when there are no more pages to be added you can apply the send() method.

              you'll want to pay attention to breaking the text at a reasonable place. ie, not in the middle of a word.
              • 4. Printing dynamic text exceeding one page
                GerryIsHere Level 1
                Hi!

                I spent a lot of time in building something I wanted slim and simple which could cover any printing requirement from the basic user.

                I declared a global LoadVariable named myPrintStr and included a the end of each search function a statement which says:

                myPrintStr = “blah blah blah” + myVars.content; // blah blah blah is an html formatted text which presents the content and myVars.content is the result of the search which is displayed in the visible html scrollable dynamic text field located in the page the user is looking at.

                Then, I built a function to prepare the data and printing setting

                [code]
                function prepPrint(width, height, myPrintStr):Object {
                this.createTextField("myPrintFld", 10, 1000, 0, 533, 723);
                //this["myPrintFld"].setTextFormat(_root.txtFmtResources); I didn't set any parameters
                this["myPrintFld"].antiAliasType = "advanced";
                this["myPrintFld"].multiline = true;
                this["myPrintFld"].wordWrap = true;
                this["myPrintFld"].html = true;
                //this[ "myPrintFld" ].styleSheet = this.CSS; Maybe in the future...
                this["myPrintFld"].htmlText = myPrintStr;
                var linesVisible = this["myPrintFld"].bottomScroll;
                var totalLines = this["myPrintFld"].maxscroll - 1 + linesVisible;
                var numberOfTextPages = Math.ceil((totalLines / linesVisible));
                var linesToFit = (numberOfTextPages * linesVisible) - totalLines;
                for (var i = 0; i < linesToFit; i++) {
                this["myPrintFld"].htmlText += "<br>";
                }
                totalLines = numberOfTextPages * linesVisible;
                return {linesVisible:linesVisible, numberOfTextPages:numberOfTextPages, myPrintFldRef:this["myPrintFld"]};
                }
                [/code]

                And then a print function

                [code]
                //Calls the above function (I put in the print button : on (press) {doPrint();};
                function doPrint() {
                pJob = new PrintJob();
                if (pJob.start()) {
                var wMargin = pJob.paperWidth;
                var hMargin = pJob.paperHeight;
                var objPrint = prepPrint(pJob.pageWidth, pJob.pageHeight, myPrintStr);
                for (var i = 0; i < objPrint.numberOfTextPages; i++) {
                objPrint.myPrintFldRef.scroll = (i * objPrint.linesVisible) + 1;
                pageAdded = pJob.addPage(this, {xMin:0, xMax:pJob.pageWidth, yMin:0, yMax:pJob.pageHeight});
                }
                }
                }
                [/code]

                This prints on multiple pages.
                BUT IT DOESN’T PRINT THE SPECIFIED myPrintStr AND SIMPLY PRINTS THE WHOLE PAGE !
                All my efforts ruined in a single click...

                Could you please tell me what’s wrong in my code?

                Best,

                Gerry
                • 5. Re: Printing dynamic text exceeding one page
                  kglad Adobe Community Professional & MVP
                  1. you're not creating multiple movieclips/textfields.

                  2. you're not taking steps to allocate the correct amount of text to each textfield.

                  3. you are
                  a. using one movieclip (this) and a textfield and
                  b. you're allocating all your text to that textfield,
                  c. adding this to your printjob and

                  4. you should expect one page worth of text to print.
                  • 6. Re: Printing dynamic text exceeding one page
                    GerryIsHere Level 1
                    quote:

                    Originally posted by: kglad
                    1. you're not creating multiple movieclips/textfields.


                    I tried a completely different and new approach which, obviously, you didn’t consider...

                    quote:

                    2. you're not taking steps to allocate the correct amount of text to each textfield.


                    Of course, as I try to think different, I don’t have to... see above...
                    BUT, if I follow your method, I don’t know how to tell the machine “hold this variable (the result of the search), split it in crunches so each of them fit in a movieclip/textfield and allocate each of them to the movieclip/textfield it belongs”
                    OR, if you prefer, I don’t know how to allocate the correct amount of text to each textfield.


                    quote:

                    3. you are
                    a. using one movieclip (this) and a textfield and
                    b. you're allocating all your text to that textfield,
                    c. adding this to your printjob and


                    In the new method I tried, I wrote statements which compare the total lines and the visible ones.
                    I thought these statements would have been efficient to determine the number of pages and, on each of the printed pages, the amount of printed lines.

                    quote:

                    4. you should expect one page worth of text to print.

                    Sorry, but when I print, I have THREE pages printed as expected. Problem is that the content of each page is always the same and is not the kind of content I expected (the content printed is the whole page instead of the result of the search).

                    To make my answer short: I really trust in your solution but only if you tell me how can I “parse” the content of my variable to movieclip/textfields I create?

                    Best,

                    Gerry

                    • 7. Re: Printing dynamic text exceeding one page
                      GerryIsHere Level 1
                      Hello kglad, what can I do now ?

                      Regards,

                      Gerry
                      • 8. Re: Printing dynamic text exceeding one page
                        kglad Adobe Community Professional & MVP
                        re-read my 01/28/2008 09:18:49 PM message. this is not an elementary task and i don't know any simpler way to explain what needs to be done.

                        i spent many hours perfecting this so the printed page has perfect top, bottom, left and right margins with intelligent page breaks.