Printing in Flex 2

This morning I decided I needed to tackle printing for the project I’m working on. I more or less expected to spend a good part of the day figuring it out. Boy was I wrong! I had my project printing output

While it’s entirely possible to get fancy (which I plan to do tomorrow) to start it’s as simple as

import the class for flex printing:

import mx.printing.FlexPrintJob;

Create a new PrintJob, then start the print job.

var printJob:FlexPrintJob = new FlexPrintJob();
printJob.start();

One thing to keep in mind. Once you’ve started the print job, don’t do too much (really don’t do any) non printing work. Don’t interact with the client, anything. Group all your printing.

then simply add items to the print job.

printJob.addObject(object);

Each addObject is a new page in the printjob (so doing the above 10 times gets you 10 pieces of paper in the printer).

When you’re all done, send your printjob to the printer (really you’re sending it to the OS. From here the print dialogue will open in your OS

printJob.send();

The object you pass the addObject() method can be a layout container (HBox, VBox, etc) or a single text object. My first run at printing, I wrapped my bits in a VBox, then passed the VBox to the addObject() method.

Once I got this solution soundly working I delved a bit deeper and found that a perhaps better solution is to create a printview component. Since often times (including my current project) your application looks a little different than what you’d like the printed output to look like. In my case I have some background colors and such that I don’t want on the print out. So my printview will simply be a component devoid of any colors.

All in all printing in Flex 2 is incredibly easy, in fact IMO much easier than printing in CF/HTML

112 thoughts on “Printing in Flex 2

  1. Paul Post author

    Great post thanks! However I cannot work out how to print a large string over multiple pages. It seems to only print one page.

    This is my print function

    private function doPrint():void {

    var printJob:FlexPrintJob = new FlexPrintJob();

    var formPrintView:SubmissionReport = new SubmissionReport();
    addChild(formPrintView);

    var todayDate:Date = new Date();

    formPrintView.detailUsername.text = _session.getSessionUsername();
    formPrintView.detailDate.text = String(todayDate);
    formPrintView.detailcontent.text = _session.returnSubmissionReportText()

    printJob.start();

    printJob.addObject(formPrintView);

    printJob.send();

    removeChild(formPrintView);

    }

  2. Alexander Post author

    THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 :D
    i was trying to do that whole day
    :D :D

  3. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  4. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  5. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  6. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  7. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  8. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  9. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  10. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  11. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  12. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  13. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  14. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  15. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  16. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  17. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  18. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  19. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  20. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  21. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  22. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  23. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  24. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  25. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  26. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  27. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  28. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  29. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  30. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  31. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  32. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  33. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  34. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  35. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  36. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  37. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  38. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  39. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  40. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  41. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  42. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  43. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  44. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  45. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  46. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  47. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  48. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  49. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  50. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  51. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  52. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  53. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  54. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  55. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  56. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  57. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  58. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  59. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  60. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  61. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  62. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  63. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  64. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  65. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  66. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  67. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  68. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  69. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  70. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  71. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  72. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  73. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  74. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  75. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  76. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  77. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  78. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  79. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  80. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  81. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  82. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  83. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  84. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  85. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  86. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  87. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  88. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  89. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  90. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  91. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  92. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  93. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  94. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  95. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  96. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  97. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  98. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  99. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  100. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  101. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  102. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  103. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  104. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  105. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  106. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  107. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  108. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  109. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

  110. Mike

    I too had trouble printing a large string over multiple pages. This solution works pretty well for me. It prints a header string, a large block text for the body, and a footer with the page number/total pages. I had to print as a bitmap because the calculation for number of lines per page would differ from what actually printed on the pages in vector mode. Also, I found that for some reason in bitmap mode I had to add the print sprite to a UIComponent, then actually add that to my application (hidden of course), or else it would print gray on any printer.

    private function printText(header:String,body:String):void
    {
    var pj:PrintJob = new PrintJob();
    var sheet:Sprite = new Sprite();
    var ui:UIComponent = new UIComponent();
    ui.visible=false;
    if(pj.start())
    {
    //Fill in background with white
    sheet.graphics.beginFill(0xFFFFFF);
    sheet.graphics.drawRect(0, 0, pj.pageWidth, pj.pageHeight);
    sheet.graphics.endFill();

    //Create text field for header
    var hdrFormat:TextFormat = new TextFormat("Arial",16,0×000000,true);
    var headerTxt:TextField = new TextField();
    headerTxt.defaultTextFormat=hdrFormat;
    headerTxt.background = false;
    headerTxt.border = false;
    headerTxt.wordWrap = false;
    headerTxt.width=pj.pageWidth;
    headerTxt.y=25;
    headerTxt.autoSize = TextFieldAutoSize.CENTER;
    headerTxt.text = header;
    sheet.addChild(headerTxt);

    //Create text field for body
    var bodyFormat:TextFormat = new TextFormat("Courier New",10,0×000000);
    var bodyTxt:TextField = new TextField();
    bodyTxt.defaultTextFormat=bodyFormat;
    bodyTxt.background = false;
    bodyTxt.border = false;
    bodyTxt.wordWrap = true;
    bodyTxt.x = 25;
    bodyTxt.y = 50;
    bodyTxt.multiline=true;
    bodyTxt.width=pj.pageWidth-50;
    bodyTxt.height=pj.pageHeight-100;
    bodyTxt.text = body;
    sheet.addChild(bodyTxt);
    bodyTxt.scrollV = 1;

    //Create text field for footer
    var footerFormat:TextFormat = new TextFormat("Arial",10,0×000000);
    var footerTxt1:TextField = new TextField();
    footerTxt1.defaultTextFormat=footerFormat;
    footerTxt1.background = false;
    footerTxt1.border = false;
    footerTxt1.wordWrap = false;
    footerTxt1.width=pj.pageWidth;
    footerTxt1.y=pj.pageHeight-40;
    footerTxt1.autoSize = TextFieldAutoSize.CENTER;
    sheet.addChild(footerTxt1);

    var totalLines:int = bodyTxt.numLines; //Total lines in document
    var linesPerPage:int = bodyTxt.bottomScrollV; //Number of lines per page
    var curPage:int = 1; //Current page
    var numPages:int = Math.ceil(totalLines / linesPerPage); //Total number of pages

    //Append new lines to end of text
    //This allows scrolling to work all the way to the end of the document
    for(var i:int=0;i < linesPerPage;i )
    bodyTxt.appendText("n");

    //Add page to printJob, then scroll to next page
    //Continue until last page
    while(bodyTxt.bottomScrollV < totalLines)
    {
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup
    bodyTxt.scrollV = linesPerPage; //Scroll text field to next page
    curPage ;
    if(curPage == 2)
    sheet.removeChild(headerTxt); //Remove header after first page
    }

    //Add last page
    footerTxt1.text = "Page " curPage " of " numPages;
    ui.addChild(sheet);
    Application.application.addChild(ui);
    pj.addPage(ui,null,new PrintJobOptions(true));
    ui.removeChild(sheet); //Cleanup
    Application.application.removeChild(ui); //Cleanup

    pj.send(); //Send the print job
    }
    }

Comments are closed.