This print job function looks good in theory but is not printing a 2 page document correctly. It print 2 pages of 45 lines. Page 1 is printing lines 1 to 45. PAge 2 is printing line 24 to the end of the document. dont this the vPosition is working. Here is trhe code:
// set scaleMode to noScale so text fields will stay the same size no matter the size of the window
Stage.scaleMode = "noScale";
// import the textarea control
import mx.controls.TextArea;
// define styles... one for the screen and one for the print
var screenStyles = new TextField.StyleSheet();
screenStyles.setStyle("html", {
fontFamily: "verdana,sans-serif",
fontSize: "12px",
color: "#cc0000"}
);
var printStyles = new TextField.StyleSheet();
printStyles.setStyle("html", {
fontFamily: "verdana,sans-serif",
fontSize: "9px",
color: "#000000"}
);
// Define on-screen textarea
this.createEmptyMovieClip("mc1", this.getNextHighestDepth() );
mc1.createClassObject(TextArea, "text1", mc1.getNextHighestDepth());
mc1.text1.move(10, 80);
mc1.text1.setSize(340, 110);
mc1.text1.html = true;
mc1.text1.wordWrap = true;
mc1.text1.styleSheet = screenStyles;
mc1.text1.antiAliasType = "advanced";
mc1.text1.text ="on-screen version<br /> <br />" + textValue;
// 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 = 1000;
mc2.text2.move(400, 80);
// a good size for printing out on American, standard letter-sized paper
mc2.text2.setSize(525, 650);
mc2.text2.html = true;
mc2.text2.wordWrap = true;
mc2.text2.styleSheet = printStyles;
mc2.text2.antiAliasType = "advanced";
mc2.text2.text = "printer version<br /> <br />" + textValue;
print_btn.onRelease = function() {
// give the function the name of the textarea to print
PrintText(mc2.text2);
}
function PrintText(theTextarea:Object) {
// 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_pjrintJob = 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;
}
// set scaleMode to noScale so text fields will stay the same size no matter the size of the window
Stage.scaleMode = "noScale";
// import the textarea control
import mx.controls.TextArea;
// define styles... one for the screen and one for the print
var screenStyles = new TextField.StyleSheet();
screenStyles.setStyle("html", {
fontFamily: "verdana,sans-serif",
fontSize: "12px",
color: "#cc0000"}
);
var printStyles = new TextField.StyleSheet();
printStyles.setStyle("html", {
fontFamily: "verdana,sans-serif",
fontSize: "9px",
color: "#000000"}
);
// Define on-screen textarea
this.createEmptyMovieClip("mc1", this.getNextHighestDepth() );
mc1.createClassObject(TextArea, "text1", mc1.getNextHighestDepth());
mc1.text1.move(10, 80);
mc1.text1.setSize(340, 110);
mc1.text1.html = true;
mc1.text1.wordWrap = true;
mc1.text1.styleSheet = screenStyles;
mc1.text1.antiAliasType = "advanced";
mc1.text1.text ="on-screen version<br /> <br />" + textValue;
// 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 = 1000;
mc2.text2.move(400, 80);
// a good size for printing out on American, standard letter-sized paper
mc2.text2.setSize(525, 650);
mc2.text2.html = true;
mc2.text2.wordWrap = true;
mc2.text2.styleSheet = printStyles;
mc2.text2.antiAliasType = "advanced";
mc2.text2.text = "printer version<br /> <br />" + textValue;
print_btn.onRelease = function() {
// give the function the name of the textarea to print
PrintText(mc2.text2);
}
function PrintText(theTextarea:Object) {
// 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_pjrintJob = 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;
}