Flex-printing-support

提供:Dev Guides
移動先:案内検索

フレックス-印刷サポート

Flexは、flexオブジェクトを印刷するための特別なクラス FlexPrintJob を提供します。

  • FlexPrintJobを使用して、FormまたはVBoxコンテナなどの1つ以上のFlexオブジェクトを印刷できます。
  • FlexPrintJobは、オブジェクトとそれに含まれるすべてのオブジェクトを印刷します。
  • オブジェクトは、表示されたインターフェイスのすべてまたは一部にすることができます。
  • オブジェクトは、特に印刷用にデータをフォーマットするコンポーネントにすることができます。
  • FlexPrintJobクラスを使用すると、ページに合わせて出力をスケーリングできます。
  • FlexPrintJobクラスは、複数のページを自動的に使用して、1ページに収まらないオブジェクトを印刷します。
  • FlexPrintJobクラスにより、オペレーティングシステムに[印刷]ダイアログボックスが表示されます。 ユーザーの操作なしでは印刷できません。

印刷ジョブを準備して送信する

出力を印刷するには、印刷ジョブを準備して送信します。 FlexPrintJobクラスのインスタンスを作成しましょう

var printJob:FlexPrintJob = new FlexPrintJob();

印刷ジョブを開始する

printJob.start();

Flexは、オペレーティングシステムに[印刷]ダイアログボックスを表示させます。 1つ以上のオブジェクトを印刷ジョブに追加し、それらのスケーリング方法を指定します

printJob.addObject(myObject, FlexPrintJobScaleType.MATCH_WIDTH);

各オブジェクトは新しいページから始まります。 印刷ジョブをプリンターに送信します

printJob.send();

印刷例

Step Description
1 Create a project with a name HelloWorld under a package com.finddevguides.client as explained in the Flex - Create Application chapter.
2 Modify HelloWorld.mxml as explained below. Keep rest of the files unchanged.
3 Compile and run the application to make sure business logic is working as per the requirements.

以下は、変更されたmxmlファイル src/com.finddevguides/HelloWorld.mxml の内容です。

<?xml version = "1.0" encoding = "utf-8"?>
<s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"
   xmlns:s = "library://ns.adobe.com/flex/spark"
   xmlns:mx = "library://ns.adobe.com/flex/mx"
   width = "100%" height = "100%"
   minWidth = "500" minHeight = "500"
   initialize = "application_initializeHandler(event)">

   <fx:Style source = "/com/finddevguides/client/Style.css"/>
   <fx:Script>
     <![CDATA[
         import mx.controls.Alert;
         import mx.events.FlexEvent;
         import mx.printing.FlexPrintJob;
         import mx.printing.FlexPrintJobScaleType;

         protected function btnClickMe_clickHandler(event:MouseEvent):void {

           //Create an instance of the FlexPrintJob class.
            var printJob:FlexPrintJob = new FlexPrintJob();

           //Start the print job.
            if (printJob.start() != true) return;

           //Add the object to print. Do not scale it.
            printJob.addObject(myDataGrid, FlexPrintJobScaleType.NONE);

           //Send the job to the printer.
            printJob.send();
        }

        protected function application_initializeHandler(event:FlexEvent):void {
            lblHeader.text = "My Hello World Application";
        }
     ]]>
   </fx:Script>

   <s:BorderContainer width = "500" height = "500" id = "mainContainer"
      styleName = "container">
      <s:VGroup width = "100%" height = "100%" gap = "50"
         horizontalAlign = "center"
         verticalAlign = "middle">
         <s:Label id = "lblHeader" fontSize = "40" color = "0x777777"
            styleName = "heading"/>

         <mx:DataGrid id = "myDataGrid" width = "300">
            <mx:dataProvider>
               <fx:Object Product = "Flex" Code = "1000"/>
               <fx:Object Product = "GWT" Code = "2000"/>
               <fx:Object Product = "JAVA" Code = "3000"/>
               <fx:Object Product = "JUnit" Code = "4000"/>
            </mx:dataProvider>
         </mx:DataGrid>

         <s:Button label = "Print Me!" id = "btnClickMe"
            click = "btnClickMe_clickHandler(event)"
            styleName = "button"/>
      </s:VGroup>
   </s:BorderContainer>
</s:Application>

すべての変更が完了したら、link:/flex/flex_create_application [Flex-アプリケーションの作成]の章で行ったように、アプリケーションを通常モードでコンパイルして実行します。 アプリケーションに問題がなければ、次の結果が得られます。[link:/flex/samples/PrintApplicationl [オンラインで試す]]

フレックスプリント

[印刷]ボタンをクリックすると、以下に示すデータグリッドの印刷が表示されます。

flex Print 1