Apparently I don't quite get how to use a matrix yet. I thought I did.
So I have on stage of my Flex project a custom object that is 10,000 px wide by 
6,000 px tall. I need to be able to print this so what I have done or tried to 
do is cut up the custom object into chunks of bitmapdata 1000px by 1000px, via 
a matrix object, that I then send to a pdf generator (alivepdf). All is fine, 
but one minor issue that I had to hack my way around.  

So as you will see in the code, I pass an displayobject and get its 
measurements, which then I find out how many snapshots it will take to capture 
the entire displayobject. I couldn't get this to work so what I had to do is 
put in this little hack. Specifically the "+ 2.5" and the "+ 15.5" to add on 
additional 2.5 pages to the height and 15.5 extra pages to width to be sure I 
capture the entire displayObject passed in. If I don't then I don't end up 
getting all of it, usually the lower right corner of the displayobject gets 
cutoff in my bitmapdata/matrix capture function below.

Anyone will to teach a man to fish (aka where am I going wrong with the 
matrix?)  

numberOfPDFPanelsHigh = Math.max( 1, Math.round(( (_bounds.height * 
_percentageToScalePrintOut) / imageHeight) + 2.5) );
                                numberOfPDFPanelsWide = Math.max( 1, 
Math.round(( (_bounds.width * _percentageToScalePrintOut) / imageWidth) + 15.5) 
);





CODE ============================

        private function willPrepareToPrint(event:Event=null):void{
                                willSetPrintInContextMenuToDisabled();
                                CursorManager.setBusyCursor();
                                if(event){ event.stopImmediatePropagation() };
 
                                callLater(willEstablishPDFPanels, [event]);
                        }
private function willEstablishPDFPanels( event:Event=null ):void {
                                
                                _bounds = 
this.vis.visualization.getBounds(DisplayObject(this.vis.visualization));
                                trace("this.vis.visualizations bounds are " + 
_bounds);
                                
                                numberOfPDFPanelsHigh = Math.max( 1, 
Math.round(( (_bounds.height * _percentageToScalePrintOut) / imageHeight) + 
2.5) );
                                numberOfPDFPanelsWide = Math.max( 1, 
Math.round(( (_bounds.width * _percentageToScalePrintOut) / imageWidth) + 15.5) 
);
                                callLater( willMakeABitmap, [ event, 
numberOfPDFPanelsWide, numberOfPDFPanelsHigh] );
                        }
                        
                        public function willMakeABitmap( event:Event, 
numOfXPanels:int, numOfYPanels:int ):void {       
                                
                                generator = new PdfGenerator("Map.pdf", null);  
                                
generator.addEventListener(PdfGeneratorEvent.PDF_GENERATOR_COMPLETE, 
this.onPdfComplete);
                            
generator.addEventListener(PdfGeneratorEvent.PDF_GENERATOR_PAGE_COMPLETE, 
this.onPdfPageComplete);  
                            
generator.addEventListener(PdfGeneratorEvent.PDF_GENERATOR_STOPPED, 
this.onPdfGenStopped);
                            generator.generate();               
                            createProgressBox();
                            
                                recForPrinting = 
this.vis.visualization.getBounds( DisplayObject(this.vis.visualization) );
                                allWhiteBMPD = new BitmapData(imageWidth, 
imageHeight, false, 0xFFFFFFFF);
                                _columnsCompleted = 0;
                                _rowsCompleted = 0;
                                _images = [];
                                nextPageCapture();
                        }
                        
                        private function nextPageCapture() : void
                        {
                                if(_columnsCompleted >= numberOfPDFPanelsWide){ 
                                        onPdfComplete();
                                        return 
                                }
                                
                                if(bitmapProgress){ 
                                        
progress.progBar.setProgress(_columnsCompleted, numberOfPDFPanelsWide);
                                        progress.progBar.label = 
_columnsCompleted + " of " + numberOfPDFPanelsWide + " images captured";
                                }
                                
                                trace('         ');
                                trace('STARTING NEW PAGE  ||   
||||||||||||||||||||||||||||||||||||||||||||||||');
                                
                                // this always sets us back to 0,0 point
                                initRecX = -(recForPrinting.x + -50);
                                initRecY = -(recForPrinting.y + -50);
                                
                                xMatrixPos = -imageWidth * _columnsCompleted; 
// this puts xMatrixPos at the next row to the right.
                                
                                /* The following sets us back 100 pixels on X 
so we can compensate for any cutoff by printer margins. 
                                        It also makes it easier for the user to 
put the map together after printing (aka leaves overlap)*/
                                if(_columnsCompleted > 0){ xMatrixPos += 100 }; 
                                
                                
                                trace('At page ' + _columnsCompleted + ' ' + 
_rowsCompleted + ' =   ===================');
                                var matrx:Matrix = new Matrix();
                                
                                yMatrixPos = -imageHeight * _rowsCompleted;
                                
                                /* The following sets us back 100 pixels on Y 
so we can compensate for any cutoff by printer margins. 
                                It also makes it easier for the user to put the 
map together after printing (aka leaves overlap)*/
                                if(_rowsCompleted > 0){ yMatrixPos += 100 };
                                trace('image for matrix moved to the right ' + 
(initRecX + xMatrixPos) + ' pixels');
                                trace('image for matrix moved down ' + 
(initRecY + yMatrixPos) + ' pixels');
                                matrx.scale( _percentageToScalePrintOut, 
_percentageToScalePrintOut );
                                matrx.translate( (initRecX + xMatrixPos), 
(initRecY + yMatrixPos) );
                                
                                // create a bytearray so we can get the screen 
to 300dpi.
                                // 
---------------------------------------------------------------
                                
                                var bdu:BitmapDataUnlimited = new 
BitmapDataUnlimited;
                                bdu.addEventListener( 
BitmapDataUnlimitedEvent.COMPLETE, function onBmpReady(event : 
BitmapDataUnlimitedEvent) : void
                                {
                                        hugeBmp = bdu.bitmapData;
                                        trace("BitmapData: w=" + hugeBmp.width 
+ " h=" + hugeBmp.height);
                                } );
                                bdu.create( imageWidth, imageHeight, false, 
0xFFFFFF );
                                
                                // capture and draw to bitmapdata object
                                hugeBmp.draw(this.vis.visualization, matrx, 
null, null, recForPrinting, false );
                                
                                var isABlankWhitePage:* = allWhiteBMPD.compare( 
hugeBmp );
                                
                                matrx.translate( -initRecX, -initRecY );
                                
                                if( isABlankWhitePage != 0){ 
                                        //_images.push( hugeBmp );
                                        generator.feedSinglePage( hugeBmp );
                                        doRowAndColumnCount();
                                }else{
                                        hugeBmp.dispose();
                                        doRowAndColumnCount();
                                        nextPageCapture();
                                }
                                
                        }

Reply via email to