2008-03-01
Printing TextArea content
Just this past week an issue in one of our applications was pointed out to me. The feature allows a user to print the contents of a TextArea control, however it does not handle multi-page printing, meaning when the contents of the TextArea actually spans several printing pages. So I started working on adding this capability but after a while was wondering why I wasting my time and starting googling for this solution, since someone must have already done it. Didn't take long to find it actually. Someone has created a PrintTextArea control and included it as part of a project called FlexReport, which you can find here. Only one problem, the website contains no SWC file to download, so I just copied the code and compiled it as a library and used it in my project. I recommend you do the same, before this source code is lost, as this is a very useful control. Many thanks to the developer who created it, wherever you are :)
Subscribe to:
Post Comments (Atom)
8 comments:
Hi!
If you don't ming me asking, how did you use the PrintTextArea component? Because I got the source code and I've incorporated the component to my print function, and it still doesn't work as expected.
It tries to send a few thousand pages to the printer, and they are all the first page!
Here's my code. Naturally, rtEditor is a RichTextEditor.
var tArea:PrintTextArea = new PrintTextArea();
var pJob:FlexPrintJob = new FlexPrintJob();
pJob.start();
pJob.printAsBitmap = false;
tArea.height = pJob.pageHeight;
tArea.width = pJob.pageWidth;
tArea.htmlText = rtEditor.htmlText;
addChild(tArea);
tArea.reset();
pJob.addObject(tArea);
while (tArea.validNextPage) {
tArea.nextPage();
pJob.addObject(tArea);
}
pJob.send();
removeChild(tArea);
Hi,
I tried PrintTextArea and it doesn't seem to be working as expected. It is sending more than 300 pages for about 35 lines in text area. Please let me know how you have used it.
Regards,
Karthik
Hi, I got the same problem as you guys, printing resulted in many many pages.
I found a solution in the repository of the printTextArea,
Use the first version which is checked in of the printTextArea :
http://code.google.com/p/flexreport/source/browse/trunk/flexreport/org/print/PrintTextArea.mxml?spec=svn3&r=3
This one works !!
酒店打工
酒店兼職
台北酒店
打工兼差
酒店工作
酒店經紀
禮服店
酒店兼差
酒店上班
酒店PT
酒店
酒店喝酒
酒店消費
喝花酒
粉味
http://code.google.com/p/flexreport/source/browse/trunk/flexreport/org/print/PrintTextArea.mxml?spec=svn3&r=3
That component works to a degree. There is a bug on the last print page where the beginning line does not match up with the previous page ending line. I see there is just no way to cleanly print multiple TextArea pages in Flex, so why doesn't someone just say that OR provide some code that actually works???
http://code.google.com/p/flexreport/source/browse/trunk/flexreport/org/print/PrintTextArea.mxml?spec=svn3&r=3
This does work but you will need to add some code to the component:
In the function nextPage() before the for loop declare this variable:
var lineHeight:Number;
in the for loop replace contents with this:
lineHeight = getLineMetrics(i).height;
nextHeight += lineHeight;
and after the height is set with nextheight add this:
height -= lineHeight * Math.round(numLines / lineHeight);
I've try to use it, but printing output have almost black background and text is bad visible beacuse it also is black.
i am also getting same problem
almost black background and text is bad visible beacuse it also is black.
Post a Comment