Flash Printing - Chrome Omits Sprites When Printin

2019-07-03 04:55发布

Quick Summary
We have a Flash application (AS3) that gives users the ability to read, interact and print content embedded within it. We've recently noticed that when printing from Chrome, content is omitted and empty pages are printed (note, blank pages appear in Chrome's print preview as well). We're seeing this issue with Chrome's version "21.0.1180.83" (using Flash Version "11.3.31.230"). This is not reproducible in any other browser.

Technical Details
Each page of content is represented as a Sprite. In order to render content properly, we do some scaling/resizing. We accomplish this with Bitmaps. We create a new BitmapData object (bMapData) and draw the page's sprite. We take (bMapData) and create a new Bitmap object (bMap) with it. Lastly, we create a new Sprite object (sObj) and add (bMap) as its child. Printing (sObj) renders blank pages.

I've included some sample code that can be used to reproduce this:

    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;

        }

    }

Does anyone have suggestions on a "workaround"?

Any and all help is appreciated!

1条回答
我命由我不由天
2楼-- · 2019-07-03 05:29

thanks for the file,

I've grabbed it and it is like I've said - print content MUST be on stage - following is modified print method of yours:

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

    }

when I've modified it I was able to have printout on google,

best regards

查看更多
登录 后发表回答