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 :)

10 comments:

Alejandro Moreno said...

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);

Karthik said...

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

Patrick said...

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 !!

Anonymous said...

酒店打工

酒店兼職

台北酒店

打工兼差

酒店工作

酒店經紀

禮服店

酒店兼差

酒店上班

酒店PT

酒店

酒店喝酒

酒店消費

喝花酒

粉味

酒店上班請找艾葳 said...

艾葳酒店經紀公司提供專業的酒店經紀, 酒店上班小姐,八大行業,酒店兼職,傳播妹,或者想要打工兼差打工,兼差,八大行業,酒店兼職,想去酒店上班, 日式酒店,便服店,制服酒店,ktv酒店,禮服店,整天穿得水水漂漂的,還是想去制服店日領上班小姐,水水們如果想要擁有打工工作、晚上兼差工作兼差打工假日兼職兼職工作酒店兼差兼差打工兼差日領工作晚上兼差工作酒店工作酒店上班酒店打工兼職兼差兼差工作酒店上班等,想了解酒店相關工作特種行業內容,想兼職工作日領假日兼職兼差打工、或晚班兼職想擁有鋼琴酒吧又有保障的工作嗎???又可以現領請找專業又有保障的艾葳酒店經紀公司!

艾葳酒店經紀是合法的公司工作環境高雅時尚,無業績壓力,無脫秀無喝酒壓力,高層次會員制客源,工作輕鬆,可日領現領
一般的酒店經紀只會在水水們第一次上班和領薪水時出現而已,對水水們的上班安全一點保障都沒有!艾葳酒店經紀公司的水水們上班時全程媽咪作陪,不需擔心!只提供最優質的酒店上班,酒店上班,酒店打工環境、上班條件給水水們。心動嗎!? 趕快來填寫你的酒店上班履歷表

水水們妳有缺現領、想要兼職、有缺錢的煩腦嗎?想到日本留學缺錢嗎?妳是傳播妹??想要擁有高時薪又輕鬆的賺錢,酒店和,假日打工,假日兼職賺錢的機會嗎??想實現夢想卻又缺錢沒錢嗎!??
艾葳酒店台北酒店經紀招兵買馬!!徵專業的酒店打工,想要去酒店的水水,想要短期日領,酒店日領,禮服酒店,制服店,酒店經紀,ktv酒店,便服店,酒店工作,禮服店,酒店小姐,酒店經紀人,
等相關服務 幫您快速的實現您的夢想~!!

tonihb said...

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???

Anonymous said...

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);

Anonymous said...

酒店打工 酒店兼職
台北酒店 打工兼差 酒店工作 禮服酒店
酒店兼差 酒店上班 酒店應徵 酒店 酒店經紀

a13 said...

I've try to use it, but printing output have almost black background and text is bad visible beacuse it also is black.

Anonymous said...

i am also getting same problem

almost black background and text is bad visible beacuse it also is black.