2009-08-21 10 views
1

私はAdobe AIRの初心者ですが、私の航空アプリからHTMLを印刷しようとしていますが、このHTMLは決して画面に表示されません。私はこれをHTMLLoaderを使って、Webで見たサンプルごとに使用しています。AIRアプリケーションのオフスクリーンHTMLコンテンツを印刷できません

何が起こるかは、印刷ダイアログが表示されますが、空白のページが印刷されます。

これはウィンドウアプリケーションで、印刷するボタン(印刷するHTMLLoaderのみ)をクリックすると印刷されます。

以下は私のコードです。

のvar mySpriteが:スプライト=新しいmySpriteが()

VARローダー:HTMLLoaderオブジェクト=新しいのHTMLLoader() loader.loadString( "ADDRESS
木8月20日午前21時37分20秒GMT + 0530 2009
")

のvar HTML:HTML =新しいHTML()

html.htmlLoader =ローダー

mySprite.addChild(HTML)。

//このそれはかなり標準

のvar pJob後:のPrintJob =新しいの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();

私に不足していることを教えてください。助けや提案は大歓迎です。

答えて

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

+0

私はそれは私がそれを印刷することができ、画面上のボタンのonclickのですが、私は、バックグラウンドでこれをやってみたかった場合。 IPプリンタで印刷するか、これをいくつかの設定に基づいて行います。それでも、私は今作業するための資料があると思います。どうもありがとう! – Tanmay

関連する問題