【问题标题】:Cannot print off-screen HTML content from AIR application无法从 AIR 应用程序打印屏幕外 HTML 内容
【发布时间】:2010-11-21 15:02:17
【问题描述】:

我是 Adob​​e AIR 的新手,我正在尝试从我的 air 应用程序中打印 HTML,但是,此 HTML 永远不会出现在屏幕上。根据我在网上看到的一些示例,我正在为此使用 HTMLLoader。

发生的情况是,有一个打印对话框,但它打印出一个空白页。

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

以下是我的代码。

var mySprite:Sprite = new mySprite()

var loader:HTMLLoader = new HTMLLoader() loader.loadString("地址
格林威治标准时间 8 月 20 日星期四 21:37:20+0530 2009
")

var html:HTML = new HTML()

html.htmlLoader = 加载器

mySprite.addChild(html);

//在这之后是相当标准的

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

if(!pJob.start()) { throw new PrintingCanceled("用户取消打印"); } pJob.addPage(loader, null); pJob.send();

请让我知道我缺少什么。欢迎任何帮助或建议。

【问题讨论】:

    标签: actionscript air adobe


    【解决方案1】:

    您确定页面正在加载吗? 框架不必可见,但它需要内容。这意味着您的 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

    【讨论】:

    • 如果我点击屏幕上的按钮,我可以打印它,但我想在后台执行此操作。根据某些配置,它要么在 IP 打印机上打印,要么在这个打印机上打印。不过,我想我现在有一些材料可以使用。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-06
    相关资源
    最近更新 更多