all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

printing multiple pages from a dynamically loaded text field


printing multiple pages from a dynamically loaded text field targetplanet
2/14/2006 11:24:55 PM
flash actionscript: I recently had to impliment printing of the content of a textArea that was
dynamically populated. The first problem I ran into was how to access the
textArea for printing. I quickly avoided that problem by populating an off
stage text field with the same data. I placed that text field in a movie clip
so I could print that clip.
The next problem I ran into was, depending on the data, the text feild may
contain more then one page worth of printing. I search the forums for an
answer, but only found the question. So I had to come up with a way to add
multiple pages to my PrintJob based on a text field that could be any size.
Here is the script I came up with:
It is pretty simple, it check sthe hieght of the text holder clip against the
PrintJob.pageHeight. If the movieclip height is larger, It devides it by the
pageHeight to get the number of pages needed to print the whole thing, then
runs a loop to add the pages. I then used the pageHeight and mc height to get
the min and max y boundries for printing.
pageHeight*i got me the ymin, then adding the mc height to that got me the
ymax.
If the mc height wasn't larger then the pageHeight, it only adds one page.
hope this helps some of you, and I welcome any comments, changes, additions or
criticism of this script.
Russ



var mh:Number = textHolder_mc._height;
var pageCount:Number = 0;
var my_pj:PrintJob = new PrintJob();
if (my_pj.start()) {
if (mh>my_pj.pageHeight) {
var pnum:Number = Math.ceil(mh/my_pj.pageHeight);
trace(pnum);
for (var i:Number = 0; i<pnum; i++) {
var ymn:Number = my_pj.pageHeight*i;
var ymx:Number = ymn+my_pj.pageHeight;
my_pj.addPage("textHolder_mc", {xMin:0, xMax:my_pj.pageWidth, yMin:ymn,
yMax:ymx}, null, 1);
pageCount++;
}
} else {
my_pj.addPage("textHolder_mc", {xMin:0, xMax:my_pj.pageWidth, yMin:0,
yMax:my_pj.pageHeight}, null, 1);
pageCount++;
}
if (pageCount>0) {
my_pj.send();
}
delete my_pj;
Re: printing multiple pages from a dynamically loaded text field JuliaO
2/26/2006 4:45:23 PM
Awesome! This is exactly what I was looking for, and it works perfectly! Can't thank you enough for posting.....


Re: printing multiple pages from a dynamically loaded text field targetplanet
2/27/2006 2:37:34 PM
Re: printing multiple pages from a dynamically loaded text field boyBacon
3/10/2006 12:46:53 PM
This is the same technique I've used to print large textfields -- it works
pretty well, but occasionally a line of text gets split across two pages (i.e.
the top half of the line prints at the bottom of a page and the bottom half
prints at the top of the next page).
Any ideas how to get around that problem? Anyone?
AddThis Social Bookmark Button