Truth be told, the weathered programmer, having gotten all the pages to scroll to their exact locations had thought the battle over. He had celebrated and there had been much merriment. Yet he was unaware that in Flash, What You See Is *Not* What You Print!
That was a lesson he learned later, when, after having refactored the mess that his spikes had become, he actually tried to print the resulting page clips -- those same page clips that looked so fine garbed in countless glimmering pixels on his screen. Aghast he was when he discovered that the conniving trickster who answers to the name Flash had – behind the scenes and far from sight -- changed the layout of the text in his TextArea components when printing them so that the printed layouts did not match what he had on screen.
Ah, a valuable lesson this: Never underestimate Flash's ability to throw you a curve ball!
So, was this the fatal blow? Will the embattled geek rise from the ashes to wrench his ultimate prize of the perfectly printed multi-page TextArea from the wretched claws of the one they call The IDE? Only time and an ever growing pile of pulled out hair will tell!
[Update: After writing this blog post, Flash and I sat down and had a long talk and worked things out. We've decided to give each other some space and start seeing other people. I think it's all for the best. We're still living together though… I think there's hope.]
The Episode V: PrintJob Strikes Back article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.
I wouldn’t be too surprised if you’re running into issues with a text field. If you zoom in when there’s a textfield in the movie it a lot of times it will re-wrap it for reasons unknown.
It recalculates stuff when you print it out, that’s for sure, there’s not much to do about it. I circumvented the problem in a recent project by creating a bunch of textfields with displaced _y based on textHeight. It was for a column view of sorts. It worked out all right, but it was a pain to get working.
PrintJob and textfields get screwey too – unless you use embedded fonts. is that an option for you? not sure it will make any difference, though, but might be worth a shot…
fwiw
g.
Gwygonik is right, if you want to control Textfield for printing, you have to embed fonts, there is no other options. But don’t be so ‘critical’ with this buggy thing: Textfield is the ONLY object that deal with the system!
And when you’ll be able to print several pages (like a multiple page with a text scrolling…) you will be facing a real, big, and horrible bug: to print multiple pages, you have to write a function (of course). But, but, the PrintJob is calling another system object: the print spooler. tadaaaaa: flash is not really ‘pausing’ your function, so after few seconds, you’ll have a wonderfull ‘Flash run slowly blabla blabla’ error message!
Actually, the only way to ‘fix’ that is to use ASV or Flasm to put the scriptlimit tag to 60 or 120 seconds (and enjoy the debugging…).
I’m looking forward, but if you find an other trick, tell us!
PS: I made a StreetMail Application in my system that print letter or fax in flash templates that output perfectly controled printouts.
Patrick, Greg and François — thank you for taking the time to reply and for your suggestions. Also a big thank-you to Peter (Hall) for suggesting I try to embed fonts last night when we talked about this (Greg and François also brought up the same point.) I had completely overlooked it and that was the one remaining thing, meaning…
IT WORKS!!!
The darn thing works!
(I have the FlashPaper to prove it!)
Expect another post after I’m off this train and have had a bite to eat for dinner!
Thank you all again for your help!
I’m glad to hear it works!
Do you experience the ‘timeout’ problem or the material you print is not ‘heavy’ enough? I publish a preview of my App this afternoon:
http://www.nectil.com/Public/News.php?ID=982
Hi François,
Thanks, man! Your application looks very sleek by the way.
The way I designed the print solution, it doesn’t time out: The trick is to use intervals instead of a regular loop. This complicates your implementation, of course, but, since it spans multiple frames, it doesn’t ever timeout.
Hope that helps and best of luck with your app!
Hi again,
I try the intervals, but a printJob have to be in one frame (read: in the same Scope Chain) to work. With this trick, I have to setup the printer at every documents, and if my document have 3 or more pages, at every page!? Have I miss something?
Argh says the troll. I have to go back to the (uglier I agree but persuasive) scriptlimit tag hack.
Hi François,
The trick is to prepare your pages *before* you start the PrintJob.
Also: I’ve held off on a new post because I uncovered at least one test case wherein my TextAreaDecorator fails. In fact, it’s not so much the TextAreaDecorator failing but the TextArea absolutely refusing to initialize correctly regardless of how long you wait before invalidating it!
The search for the perfect solution continues…
Hi,
I was thinking one work around might be to create an autosized Textfield the entire length of the text off stage. Then print the page rects until you have reached the height of that clip…
var printClip = mc.attachMovie(“com.magic.views.PrintClip”, “printClip” pageCount, pageCount);
printClip.init(p_text);
var yOffSet:Number = 0;
//printClip.scrollRect = _scrollMask;
var my_pj:PrintJob = new PrintJob();
if (my_pj.start())
{
while(yOffSet 0){
my_pj.send();
}
delete my_pj;
}
I’m still tweaking with it to make sure text doesn’t get cut off from page to page, but it’s much faster than some of the alternative solutions Mark ;)
Hey Mark, do let us know how you get on. :)
Hi there,
I’m having issues with using printjob using addpages. I’ve tried creating the pages using createEmptyMovieClip and drawing a bitmap onto it using a repeat loop first then using setInterval to start the printjob and addpages afterwards but I keep getting pages printing black.
The funny thing is that on a Mac, if you use print preview, it works but if you print direct, I get these black pages printed.
Any suggestions are greatly welcome.
Thanks / RP
All.
I have stumbled upon this posting of the so called PrintJob and have to say I am kind of worried. what you guys are saying are true workarounds, however, from my perspective they are all HACKS.
One thing is clear. Adobe is using their monopoly power to prevent us from being able to print, and is forcing us to buy flashpaper which I will not do. So, this weekend I am writing a letter to the attorney general on this issue. How many of us flash developers would be interested in a class action lawsuit ? This is fucked up. Email me at thartist026@hotmail.com
Absolutely, you’re right. The PrintJob class is Flash’s skeleton in the closet.
I can’t imagine a more hackneyed way of printing.
Why can’t Adobe implement the InDesign method for printing already? Sheesh.