Printing problems w/ as2

Publishing Print2Flash Documents embedding them in Flash movies
Post Reply
justin
Posts:2
Joined:Wed Nov 12, 2008 5:59 pm
Printing problems w/ as2

Post by justin » Wed Nov 12, 2008 6:05 pm

I have run into a problem w/ printing. The printed page image is smaller then it should be and it's being pushed to the TL corner of the sheet of paper. Im using as2. Here is my code that I have so far:

Code: Select all

class com.zf.util.PrintUtil {
	private static var pageCount;
	
	public static function PrintScaledMC(pArr:Array) {
		
		var my_pj:PrintJob = new PrintJob();
		var pageSpooled:Boolean;
		
		// Open Print dialog using .start - if my_pj.start returns false, user
		//canceled print dialog...
		if (my_pj.start()) {
			for(var i:Number=0; i<pArr.length; i++)
			{
				pageSpooled = false;
				
				var mc_PrintSource = pArr[i];
				var PrintWidth:Number, PrintHeight:Number;
				var MCWidth:Number, MCHeight:Number;
				var MCOrigXScale:Number, MCOrigYScale:Number;
				var MCRotated:Boolean = false;
				var ScaleFactor:Number;
				
				// Get the printer's width and height dimensions...
				PrintWidth = my_pj.pageWidth+ 180;
				PrintHeight = my_pj.pageHeight + 180;
				
				// Get the dimensions of the movieclip we're printing
				MCWidth = mc_PrintSource._width;
				MCHeight = mc_PrintSource._height;
				
				// Handle Scaling...
				// Capture current MovieClip X and Y Scale to restore later
				MCOrigXScale = mc_PrintSource._xscale;
				MCOrigYScale = mc_PrintSource._yscale;
				
				// Match orientation of Movie Clip to orientation of Printer...
				if (my_pj.orientation == "landscape")
				{
				// If orientation is landscape, then make movieclip portrait.
					if(MCWidth < MCHeight)
					{
						mc_PrintSource._rotation = 90;
						MCRotated = true;
					}
				} else {
				// If orientation is portrait, then make sure movieclip matches.
					if (MCWidth > MCHeight)
					{
						mc_PrintSource._rotation = 90;
						MCRotated = true;
					}
				}
				
				// Determine if width or height is to be used to scale image...
				if (MCWidth > MCHeight)
				{
					if (MCRotated) 
					{
						ScaleFactor = PrintWidth/MCHeight;
					} else {
						ScaleFactor = PrintWidth/MCWidth;
					}
				} else {
					if (MCRotated) 
					{
						ScaleFactor = PrintWidth/MCWidth;
					} else {
						ScaleFactor = PrintWidth/MCHeight;
					}
				}
				
				// Execute scaling process
				mc_PrintSource._xscale = ScaleFactor*100;
				mc_PrintSource._yscale = ScaleFactor*100;
				
				
				// Now that movieclip is scaled to printer size, spool page.
				pageSpooled = my_pj.addPage(mc_PrintSource, {xMin:0,xMax:MCWidth,yMin:0,yMax:MCHeight}, {printAsBitmap:true})
				
				// Now re-scale movieclip being printed to original scale...
				mc_PrintSource._xscale = MCOrigXScale;
				mc_PrintSource._yscale = MCOrigYScale;
				
				if (MCRotated) {
					mc_PrintSource._rotation = 0;
				}
			}
		}
		
		
		// If addPage() was successful, print the spooled page.
		if (pageSpooled){
			
		}
		
		my_pj.send();
		
		delete my_pj;
	} 	
}
Any help would be AWESOME :)
Thanks,
justin

justin
Posts:2
Joined:Wed Nov 12, 2008 5:59 pm

Re: Printing problems w/ as2

Post by justin » Thu Nov 13, 2008 3:08 pm

Ok I started all over and used the new print as2 api. Works great:) Now I need to add my logo to the printed pages.

Post Reply