无法从AIR应用程序打印屏幕外HTML内容

时间:2009-08-21 10:45:21

标签: actionscript air adobe

我是Adobe AIR的新手,我正在尝试从我的空中应用程序打印HTML,但是,这个HTML永远不会在屏幕上看到。我正在使用HTMLLoader,就像我在网上看到的一些样本一样。

会发生什么,是有一个打印对话框,但它打印出一个空白页。

如果这是一个窗口应用程序,我点击一些按钮进行打印(只是HTMLLoader),它就会被打印出来。

以下是我的代码。

var mySprite:Sprite = new mySprite()

var loader:HTMLLoader = new HTMLLoader() loader.loadString(“地址
星期四8月20日21:37:20 GMT + 0530 2009”)

var html:HTML = new HTML()

html.htmlLoader = loader

mySprite.addChild(HTML);

//之后是非常标准的

var pJob:PrintJob = new PrintJob(); html.width = pJob.pageWidth html.height = pJob.pageHeight loader.height = pJob.pageHeight loader.width = pJob.pageWidth

如果(!pJob.start()) {      抛出新的PrintingCanceled(“用户取消打印”); } pJob.addPage(loader,null); pJob.send();

请让我知道我错过了什么。欢迎任何帮助或建议。

1 个答案:

答案 0 :(得分:0)

你确定正在加载页面吗? 框架不必是可见的但它需要内容。这意味着您必须在画布中加载并“显示”htmlLoader数据。然后,如果您不希望用户看到将要打印的内容,则可以使画布不可见。

你必须将剪辑设置为false。但这意味着打印机对话框进入屏幕需要几秒钟。

   1. // Event Handler - called when the print button is clicked  
   2. private function onPrintClick ():Void  
   3. {  
   4.     // Remove the clipping so all of the content is printed  
   5.     clipForPrinting( true );  
   6.       
   7.     // Start the delay to allow clipping to update before  
   8.     // printing anything.  
   9.     doLater( this, "doActualPrinting" );  
  10. }  
  11.   
  12. // Adjust the clipping to prepare for or recover from print.  
  13. private function clipForPrinting( printing:Boolean ):Void  
  14. {  
  15.     // Assume printing is true if not passed in  
  16.     if ( printing == undefined ) {  
  17.         printing = true;      
  18.     }  
  19.   
  20.     // Modify the root clipContent so the application's width/height  
  21.     // doesn't interfere with bounds of the print content  
  22.     Application.application.clipContent = !printing;  
  23.           
  24.     // Modify the container holding the content to be printed to remove  
  25.     // the scroll masking   
  26.     printArea.clipContent = !printing;  
  27.           
  28. }  
  29.   
  30. // Handles the actual printing of the content in the popup  
  31. private function doActualPrinting():Void  
  32. {  
  33.     var printJob:PrintJob = new PrintJob();  
  34.     // Keep track of # of pages - only print if there are pages to print  
  35.     var pageCount:Number = 0;  
  36.   
  37.     // Show the print dialog  
  38.     if ( printJob.start() ) {  
  39.         // The user has opted to print - add the pages that  
  40.         // need to be printed  
  41.         pageCount += PrintUtil.pagenate( printArea, printJob );  
  42.   
  43.         // Send the content to the printer  
  44.         if ( pageCount > 0 ) {  
  45.             printJob.send();  
  46.         }  
  47.     }  
  48.   
  49.     // Explicitly delete the printJob  
  50.     delete printJob;  
  51.   
  52.     // Fix clipping now that print is done  
  53.     clipForPrinting( false );  
  54. }  

归功于原作:Link to source