AS3 使用 PrintJob 打印 MovieClip
我目前正在尝试创建一个函数,该函数允许我传入 MovieClip
并打印它。
以下是该函数的简化版本:
function printMovieClip(clip:MovieClip) {
var printJob:PrintJob = new PrintJob();
var numPages:int = 0;
var printY:int = 0;
var printHeight:Number;
if ( printJob.start() ) {
/* Resize movie clip to fit within page width */
if (clip.width > printJob.pageWidth) {
clip.width = printJob.pageWidth;
clip.scaleY = clip.scaleX;
}
numPages = Math.ceil(clip.height / printJob.pageHeight);
/* Add pages to print job */
for (var i:int = 0; i < numPages; i++) {
printJob.addPage(clip, new Rectangle(0, printY, printJob.pageWidth, printJob.pageHeight));
printY += printJob.pageHeight;
}
/* Send print job to printer */
printJob.send();
/* Delete job from memory */
printJob = null;
}
}
printMovieClip( testMC );
不幸的是,这并没有按预期工作,即打印MovieClip 的整个宽度并在长度上进行分页。
I am currently trying to create a function which will allow me to pass in a MovieClip
and print it.
Here is the simplified version of the function:
function printMovieClip(clip:MovieClip) {
var printJob:PrintJob = new PrintJob();
var numPages:int = 0;
var printY:int = 0;
var printHeight:Number;
if ( printJob.start() ) {
/* Resize movie clip to fit within page width */
if (clip.width > printJob.pageWidth) {
clip.width = printJob.pageWidth;
clip.scaleY = clip.scaleX;
}
numPages = Math.ceil(clip.height / printJob.pageHeight);
/* Add pages to print job */
for (var i:int = 0; i < numPages; i++) {
printJob.addPage(clip, new Rectangle(0, printY, printJob.pageWidth, printJob.pageHeight));
printY += printJob.pageHeight;
}
/* Send print job to printer */
printJob.send();
/* Delete job from memory */
printJob = null;
}
}
printMovieClip( testMC );
Unfortunately this is not working as expected i.e. printing the full width of the MovieClip
and doing page breaks on the length.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我忘记缩放打印区域以匹配正在调整大小的影片剪辑。请参阅下面的工作解决方案:
I forgot to scale the print area to match the movie clip being resized. See below for working solution:
感谢您的开源精神!基于您的出色工作,我实现了它并做了一些改进来解决我实际的 MovieClip 打印问题。我取得的主要进展是找到一种仅通过一次打印作业发送来打印多帧MovieClip的方法。当然,我解决了“打印Movieclip的全宽度”的问题。由于SWF以矢量图的形式存储内容,因此您需要做的是确保clip.height = printArea.height;剪辑.宽度=打印区域.宽度;。这是一个简单的方法:
如果你想了解更多信息,你可以看一下我的剪辑图像(假设你懂一点中文):都是在我的博客。还有MovieClip缩略图(仍然是中文)。
Thank you for your Open-source spirit! Based on your great work, I implement it and make a little improvement to solve my practical MovieClip-printing problem. The major progress I have made is to work out a way of printing a MovieClip with multi-frames only by one printjob sending. Of course, I resolved the question of "printing the full width of the Movieclip". Because SWF stores content in the form of vectorgraph, what you need to do is make sure
clip.height = printArea.height; clip.width = printArea.width;
. It is a easy way:If you want more information, you can take a look at my clip image (and given you understand a little Chinese): it's all in my blog. There are also MovieClip thumbnails (still Chinese).
我添加了一个小修复,可以在打印作业完成后重置影片剪辑的尺寸。问题是,当您打印比页面大的内容时,代码也会缩放舞台上的影片剪辑。所以我修复了这个问题...没什么特别的,但可能对其他人有用:)
此代码还修复了一个事实,即您的透明 PNG 在您的打印上也将是透明的
I added a small fix that resets the MovieClip's dimensions after the printjob is done. The problem was that when you print something that is larger then your page, the code would also scale the movieclip on stage. So i Fixed that... nothing special but might be useful for other people :)
this code also fixes the fact that your transparent PNG's will ALSO be transparent on your print