快速摘要
我们有一个Flash应用程序(AS3),使用户能够读取,交互和打印嵌入其中的内容。我们最近注意到,从Chrome打印时,内容被省略并打印空白页(注意,空白页也出现在Chrome的打印预览中)。我们在Chrome的版本“21.0.1180.83”(使用Flash版“ 11.3.31.230 ”)中看到了这个问题。这在任何其他浏览器中都不可重现。
技术细节
每页内容都表示为Sprite。为了正确呈现内容,我们进行了一些缩放/调整大小。我们使用Bitmaps实现这一目标。我们创建一个新的BitmapData对象(bMapData)并绘制页面的精灵。我们使用(bMapData)并使用它创建一个新的Bitmap对象(bMap)。最后,我们创建一个新的Sprite对象(sObj),并添加(bMap)作为其子对象。打印(sObj)会显示空白页面。
我已经包含了一些可用于重现此代码的示例代码:
private function printAsBitmap(sprite:Sprite):void{
var bitmapData:BitmapData = new BitmapData(sprite.width, sprite.height, false, 0xffffff);
bitmapData.draw(sprite);
var bitmap:Bitmap = new Bitmap(bitmapData);
var newSprite:Sprite = new Sprite();
newSprite.addChild(bitmap);
printSprite(newSprite);
}
private function printSprite(clip:Sprite) {
var printJob:PrintJob = new PrintJob();
var jobOptions:PrintJobOptions = new PrintJobOptions();
jobOptions.printAsBitmap=false;
var numPages:int = 0;
var printArea:Rectangle;
var printHeight:Number;
var printY:int = 0;
if ( printJob.start() ) {
/* Resize movie clip to fit within page width */
if (clip.width > printJob.pageWidth) {
clip.width = printJob.pageWidth;
clip.scaleY = clip.scaleX;
}
/* Store reference to print area in a new variable! Will save on scaling calculations later... */
printArea = new Rectangle(0, 0, printJob.pageWidth/clip.scaleX, printJob.pageHeight/clip.scaleY);
numPages = Math.ceil(clip.height / printJob.pageHeight);
/* Add pages to print job */
for (var i:int = 0; i < numPages; i++) {
//printJob.addPage(clip, printArea);
printJob.addPage(clip,null,jobOptions);
printArea.y += printArea.height;
}
/* Send print job to printer */
printJob.send();
/* Delete job from memory */
printJob = null;
}
}
有没有人对“解决方法”有什么建议?
感谢任何和所有帮助!
答案 0 :(得分:2)
感谢文件,
我抓住了它,就像我说的那样 - 打印内容必须在舞台上 - 以下是您修改后的打印方法:
private function print(clip:Sprite) {
if (!clip) return;//safety
var printJob:PrintJob = new PrintJob();
var jobOptions:PrintJobOptions = new PrintJobOptions();
jobOptions.printAsBitmap=false;
var numPages:int = 0;
var printArea:Rectangle;
var printHeight:Number;
var printY:int = 0;
if (stage)
stage.addChild(clip);//add to stage for print
if ( printJob.start() ) {
/* Resize movie clip to fit within page width */
if (clip.width > printJob.pageWidth) {
clip.width = printJob.pageWidth;
clip.scaleY = clip.scaleX;
}
/* Store reference to print area in a new variable! Will save on scaling calculations later... */
printArea = new Rectangle(0, 0, printJob.pageWidth/clip.scaleX, printJob.pageHeight/clip.scaleY);
numPages = Math.ceil(clip.height / printJob.pageHeight);
/* Add pages to print job */
for (var i:int = 0; i < numPages; i++) {
//printJob.addPage(clip, printArea);
printJob.addPage(clip,null,jobOptions);
printArea.y += printArea.height;
}
/* Send print job to printer */
printJob.send();
/* Delete job from memory */
printJob = null;
}
if (stage && stage.contains(clip))
stage.removeChild(clip);//once done remove from stage
}
当我修改它时,我能够在谷歌打印输出,
最好的问候