By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

Printing partially working

P: 18
Hi there!

I implemented a printing function which is working nice even for multiple pages.

Problem is as follows...
Say we have a text 100 lines long.
Each page can hold 80 lines.
We should have:
Page 1 = from line 1 to line 80
Page 2 = from line 81 to line 100

Instead, I get:
Page 1 = from line 1 to line 80
Page 2 = from line 20 to line 100 !!!
i.e. lines 20 to 80 are printed twice!

I think problem is in maxScroll but can't find the mistake...
Could you help me find it?

Many thanks in advance.

Best regards,
Gerry



Expand|Select|Wrap|Line Numbers
  1. // import the textarea control
  2. import mx.controls.TextArea;
  3. // define styles... one for the screen and one for the print
  4. var printStyles = new TextField.StyleSheet();
  5. printStyles.setStyle("html", {fontFamily:"verdana,sans-serif", fontSize:"12", color:"#336699"});
  6. printing = function () {
  7.     myPrintStr = _root.printFld.htmlText;
  8.     // Define printable textarea
  9.     this.createEmptyMovieClip("mc2", this.getNextHighestDepth());
  10.     mc2.createClassObject(TextArea, "text2", mc2.getNextHighestDepth());
  11.     // uncomment the following to move the printable textarea off the stage
  12.     mc2._x = 910;
  13.     mc2.text2.move(1000, 0);
  14.     // a good size for printing out on American, standard letter-sized paper
  15.     mc2.text2.setSize(525, 700);
  16.     mc2.text2.html = true;
  17.     mc2.text2.wordWrap = true;
  18.     mc2.text2.styleSheet = printStyles;
  19.     mc2.text2.antiAliasType = "advanced";
  20.     mc2.text2.text = myPrintStr;
  21.     // give the function the name of the textarea to print
  22.     PrintText(mc2.text2);
  23. };
  24. function PrintText(theTextarea:Object) {
  25.     //theTextarea.border_mc._visible = false;
  26.     theTextarea.depthChild0._alpha = 0;
  27.     // determine number of rows 
  28.     var visibleRows:Number = theTextarea.viewableRows;
  29.     trace("visibleRows " + visibleRows);
  30.     // to get the maxScroll, add the number of visible rows to the maxVPosition
  31.     // this gives us a number sufficiently high enough to enable the while statement to get to the bottom of the textarea
  32.     var maxScroll:Number = theTextarea.maxVPosition + visibleRows;
  33.     trace("maxScroll " + maxScroll);
  34.     trace("is maxScroll Not a number? " + isNaN(maxScroll));
  35.     // hide scrollbar for printout
  36.     theTextarea.vSB.visible = false;
  37.     // instantiate the PrintJob
  38.     var the_pj:PrintJob = new PrintJob();
  39.     // test the print job
  40.     if (the_pj.start()) {
  41.         var counter:Number = 0;
  42.         // if maxScroll is a number, meaning that the textarea is in fact scrollable, proceed
  43.         // otherwise,just add the single page to the print job and send it to the printer
  44.         if (!isNaN(maxScroll)) {
  45.             // while the counter is less than the maxScroll, keep adding pages to the print job
  46.             while (counter < maxScroll) {
  47.                 // scroll based on the counter position
  48.                 theTextarea.vPosition = counter;
  49.                 // increment the counter by the value of visibleRows (so page down)
  50.                 counter += visibleRows;
  51.                 // add the page to the print job
  52.                 the_pj.addPage(theTextarea, {xMin:-25, xMax:600, yMin:-30, yMax:800}, {printAsBitmap:false});
  53.             }
  54.         }
  55.         else {
  56.             // if there is only one page... that is, maxScroll is NaN, just add the current page and move on
  57.             the_pj.addPage(theTextarea, {xMin:-25, xMax:600, yMin:-30, yMax:800}, {printAsBitmap:false});
  58.         }
  59.         // send and delete the print job
  60.         the_pj.send();
  61.         delete the_pj;
  62.     }
  63.     // make scrollbar visible again   
  64.     thetextarea.vSB.visible = true;
  65. }
Mar 29 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.