troubleshooting Question

Flex Printing

Avatar of Drachs
Drachs asked on
Apache Flex
4 Comments1 Solution4833 ViewsLast Modified:
I'm trying to get printing working in flex for a reporting application I'm working on.  In particular, I have a control which extends "image".   It loads a chart from the webserver.   The control is programed to send the width and height numbers of itself as arguments with the url so that the script on the server can generate a chart the right size.

When I try to print this control I have to resize it using data the data returned from "printJob.pageWidth", but that property is only accessible after a call to printJob.start();.   I then have to come up with some way to wait until the new url is loaded so that I can continue with the printing.   I tried setting up a callback on "complete", but the callback takes over 20 seconds to fire off.   When it does, I get a "Error #2057: The page could not be added to the print job" exception from the call to printJob.addObject.

The image itself always loads in a fraction of a second, so I don't know why the complete call takes so long.   Does anybody have any idea's about how I can go about printing this control?
// The printing snippet
var Printing = false;
var page:VBox = new VBox();
var printJob:FlexPrintJob = new FlexPrintJob();
public function bdLoadComplete(bd:int):void
	if (Printing)
		Printing = false;
		printJob.addObject(page, FlexPrintJobScaleType.SHOW_ALL);
public function onPrint():void
	Printing = true;
// This is the definition of my bd1 object
package CIPA
	import mx.controls.Image;
	import mx.controls.Alert;
	public class BandwidthGraph extends Image
		public var url:String;
		private var urlWidth:Number = -1;
		private var urlHeight:Number = -1;
		public function BandwidthGraph()
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
			if ((unscaledWidth != 0 && unscaledHeight != 0) && (unscaledWidth != urlWidth || unscaledHeight != urlHeight))
				//"Width:"+unscaledWidth+" Height: "+unscaledHeight);				
				super.source = url+"&width="+unscaledWidth+"&height="+unscaledHeight;
				urlWidth = unscaledWidth;
				urlHeight = unscaledHeight;
			super.updateDisplayList(unscaledWidth, unscaledHeight);	

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros