473,394 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Printing partially working

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
0 1615

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

Similar topics

0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
9
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the...
1
by: Dave Quigley[work] | last post by:
Im working on a printing module for a program that my company is writing and I am wondering if im working with printing the right way. From what I understand with the PrintDocument you get a...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
1
by: Matt Culbreth | last post by:
Hello All, I've got a very simple ASP.NET 2.0 application which uses a DLL from a third party. I don't have the source to this DLL. Everything has been working fine on my XP development...
5
by: =?Utf-8?B?TWFydHluIEZld3RyZWxs?= | last post by:
From the amount of articles about this one I’m sure this gets asked a lot, but I haven’t yet found a succinct article which explains what is required in its entirety. I work using Visual...
2
by: deepakfordotnet | last post by:
Hi, First of all let me confess that I could not get the solution to the same problem from an earlier post Printing :by Mr.Richard MSL (dated September 24th 2006) working. (Replied by Mr.Walter...
6
by: Nathan Sokalski | last post by:
I have a DataList which contains several LinkButtons, which are used to select a category in my application. I want the currently selected category to use a different CSS class. Here is an example...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.