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
- // import the textarea control
- import mx.controls.TextArea;
- // define styles... one for the screen and one for the print
- var printStyles = new TextField.StyleSheet();
- printStyles.setStyle("html", {fontFamily:"verdana,sans-serif", fontSize:"12", color:"#336699"});
- printing = function () {
- myPrintStr = _root.printFld.htmlText;
- // Define printable textarea
- this.createEmptyMovieClip("mc2", this.getNextHighestDepth());
- mc2.createClassObject(TextArea, "text2", mc2.getNextHighestDepth());
- // uncomment the following to move the printable textarea off the stage
- mc2._x = 910;
- mc2.text2.move(1000, 0);
- // a good size for printing out on American, standard letter-sized paper
- mc2.text2.setSize(525, 700);
- mc2.text2.html = true;
- mc2.text2.wordWrap = true;
- mc2.text2.styleSheet = printStyles;
- mc2.text2.antiAliasType = "advanced";
- mc2.text2.text = myPrintStr;
- // give the function the name of the textarea to print
- PrintText(mc2.text2);
- };
- function PrintText(theTextarea:Object) {
- //theTextarea.border_mc._visible = false;
- theTextarea.depthChild0._alpha = 0;
- // determine number of rows
- var visibleRows:Number = theTextarea.viewableRows;
- trace("visibleRows " + visibleRows);
- // to get the maxScroll, add the number of visible rows to the maxVPosition
- // this gives us a number sufficiently high enough to enable the while statement to get to the bottom of the textarea
- var maxScroll:Number = theTextarea.maxVPosition + visibleRows;
- trace("maxScroll " + maxScroll);
- trace("is maxScroll Not a number? " + isNaN(maxScroll));
- // hide scrollbar for printout
- theTextarea.vSB.visible = false;
- // instantiate the PrintJob
- var the_pj:PrintJob = new PrintJob();
- // test the print job
- if (the_pj.start()) {
- var counter:Number = 0;
- // if maxScroll is a number, meaning that the textarea is in fact scrollable, proceed
- // otherwise,just add the single page to the print job and send it to the printer
- if (!isNaN(maxScroll)) {
- // while the counter is less than the maxScroll, keep adding pages to the print job
- while (counter < maxScroll) {
- // scroll based on the counter position
- theTextarea.vPosition = counter;
- // increment the counter by the value of visibleRows (so page down)
- counter += visibleRows;
- // add the page to the print job
- the_pj.addPage(theTextarea, {xMin:-25, xMax:600, yMin:-30, yMax:800}, {printAsBitmap:false});
- }
- }
- else {
- // if there is only one page... that is, maxScroll is NaN, just add the current page and move on
- the_pj.addPage(theTextarea, {xMin:-25, xMax:600, yMin:-30, yMax:800}, {printAsBitmap:false});
- }
- // send and delete the print job
- the_pj.send();
- delete the_pj;
- }
- // make scrollbar visible again
- thetextarea.vSB.visible = true;
- }