# Printing with PrintJob

**URL:** <https://forum.kirupa.com/t/printing-with-printjob/183998>\
**Category:** flash\
**Created:** [March 31, 2006, 8:51pm UTC](https://forum.kirupa.com/t/printing-with-printjob/183998 "2006-03-31T20:51:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ORNj](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@ORNj](https://forum.kirupa.com/u/ORNj)\
**Post date:** [March 31, 2006, 8:51pm UTC](https://forum.kirupa.com/t/printing-with-printjob/183998/1 "2006-03-31T20:51:14Z")

</div>

I am trying to have a movie clip load alternate content, move it out of the user’s view, and send it to the printer. The script seems to work except what it sends to the printer only contains the background. Just looking at the code does anyone see anything wrong?

The function which attaches the print\_mc and initiates the print command:

```auto

prep_print = function(loc:String) {
	_parent.attachMovie(loc, "print_mc", 99);
	_parent.print_mc._x = Stage.width;
	_parent.print_mc._y = Stage.height;
	_parent.print_mc.field.htmlText = "<b>"+_global.secTitle+"</b><br><br>";
	_parent.print_mc.field.htmlText += _global.bodyTxt;
	
	//	Usage:
	//	print_item(movie_to_print, allow_scale);
	//	print_item(MovieClip , Boolean );
	_global.print_item(_parent.print_mc, false);
	_parent.print_mc.removeMovieClip();
};

```

Print function:

```auto

//	------------------------------------------------------------------------------------
//	target_mc ->	The movieclip you want to be printed. |
//	allowScale ->	Allow the movieclip to scale down to fit on a single page. Page |
// size is determined at runtime by the PrintJob object. If scalling	|
//	------------------------------------------------------------------------------------
_global.print_item = function(target_mc:MovieClip, allowScale:Boolean) {
	var pgCount:Number = 0;
	var myPj:PrintJob = new PrintJob();
	if(myPj.start()) {
		//	Fix orientation to force portrait
		var iniH:Number = target_mc._height;
		var iniW:Number = target_mc._width;
		if(myPj.orientation == "landscape") {
			target_mc._rotation = -90;
			var height_:Number = target_mc._width;
			var width_:Number = target_mc._height;
			if(allowScale) {
				var hRatio:Number = 1;
				//	---
				while((height_ < myPj.pageHeight)||(width_ < myPj.pageWidth)) {
					if(height_ < myPj.pageHeight) {
						hRatio = myPj.pageHeight/height_;
						height_ = myPj.pageHeight;
						width_ = width_*hRatio;
					}
					if(width_ < myPj.pageWidth) {
						hRatio = myPj.pageWidth/width_;
						width_ = myPj.pageWidth;
						height_ = height_*hRatio;
					}
				}
				//	---
				while((height_ > myPj.pageHeight)||(width_ > myPj.pageWidth)) {
					if(height_ > myPj.pageHeight) {
						hRatio = myPj.pageHeight/height_;
						height_ = myPj.pageHeight;
						width_ = width_*hRatio;
					}
					if(width_ > myPj.pageWidth) {
						hRatio = myPj.pageWidth/width_;
						width_ = myPj.pageWidth;
						height_ = height_*hRatio;
					}
				}
				//	---
				target_mc._width = height_;
				target_mc._height = width_;
			}
		} else {
			//	---
			var height_:Number = target_mc._height;
			var width_:Number = target_mc._width;
			if(allowScale) {
				var hRatio:Number = 1;
				//	---
				while((height_ < myPj.pageHeight)||(width_ < myPj.pageWidth)) {
					if(height_ < myPj.pageHeight) {
						hRatio = myPj.pageHeight/height_;
						height_ = myPj.pageHeight;
						width_ = width_*hRatio;
					}
					if(width_ < myPj.pageWidth) {
						hRatio = myPj.pageWidth/width_;
						width_ = myPj.pageWidth;
						height_ = height_*hRatio;
					}
				}
				//	---
				while((height_ > myPj.pageHeight)||(width_ > myPj.pageWidth)) {
					if(height_ > myPj.pageHeight) {
						hRatio = myPj.pageHeight/height_;
						height_ = myPj.pageHeight;
						width_ = width_*hRatio;
					}
					if(width_ > myPj.pageWidth) {
						hRatio = myPj.pageWidth/width_;
						width_ = myPj.pageWidth;
						height_ = height_*hRatio;
					}
				}
				//	---
				target_mc._height = height_;
				target_mc._width = width_;
			}
		}
		//	---
		//	Set print region
		var iniX:Number = target_mc._x;
		var iniY:Number = target_mc._y;
		//	---
		var xmin_:Number = Stage.width;
		var xmax_:Number = Stage.width + myPj.pageWidth;
		var ymin_:Number = Stage.height;
		var ymax_:Number = Stage.height + myPj.pageHeight;
		//	---
		if(myPj.orientation == "landscape") {
			target_mc._x = xmin_ + ((myPj.pageWidth - height_) / 2);
			target_mc._y = ymin_ + ((myPj.pageHeight + width_) / 2);
		} else {
			target_mc._x = xmin_ + ((myPj.pageWidth - width_) / 2);
			target_mc._y = ymin_ + ((myPj.pageHeight - height_) / 2);
		}
		//	---
		var printMC:String = String(target_mc);
		trace("+++printMC: " + printMC);
		if(myPj.addPage(printMC, {xMin:xmin_, xMax:xmax_, yMin:ymin_, yMax:ymax_}, null, 1)) {
			pgCount++;
		}
	}
	if(pgCount > 0) {
		myPj.send();
	}
	trace("+++location: " + target_mc._x + ", " + target_mc._y);
	trace("+++printing: " + xmin_ + ", " + ymin_);
	
	target_mc._rotation = 0;
	target_mc._height = iniH;
	target_mc._width = iniW;
	target_mc._x = iniX;
	target_mc._y = iniY;
	delete myPj;
};

```

---

<div class="post-metadata">

**Author:** ![ORNj](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@ORNj](https://forum.kirupa.com/u/ORNj)\
**Post date:** [March 31, 2006, 9:33pm UTC](https://forum.kirupa.com/t/printing-with-printjob/183998/2 "2006-03-31T21:33:16Z")

</div>

Nevermind.
