title: c#: exporting swf object as image to Word
body: <p>in my Asp.net web page (C# on backend) I use a Repeater, whose items consist of a title and a Flex chart (embedded .swf file).  I am trying to export the contents of the Repeater to a Word document.  My problem is to convert the SWF files into images and pass it on to the Word document.</p>
  
  <p>The swf object has a public function which returns a byteArray representation of itself (public function grabScreen():ByteArray), but I do not know how to call it directly from c#.
  I have access to the mxml files, so I can make modifications to the swf files, if needed.</p>
  
  <p>The code is shown below, and your help is appreciated  :)</p>
  
  <h2>.aspx</h2>
  
  <pre><code>&lt;asp:Button ID="Button1" runat="server" text="export to Word" onclick="print2"/&gt;
  
  &lt;asp:Repeater ID="rptrQuestions" runat="server"   OnItemDataBound="rptrQuestions_ItemDataBound" &gt;
  ...
  &lt;ItemTemplate&gt;
  &lt;tr&gt;  
  &lt;td&gt;  
  &lt;div align="center"&gt;
    &lt;asp:Label class="text" Text='&lt;%#DataBinder.Eval(Container.DataItem, "Question_title")%&gt;' runat="server" ID="lbl_title" NAME="lbl_title"/&gt;
  &lt;br&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;
  
  
    &lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="result_survey"  width="100%" height="100%" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"&gt;
         &lt;param name="movie" value="result_survey.swf" /&gt;
         &lt;param name="quality" value="high" /&gt;
         &lt;param name="bgcolor" value="#ffffff" /&gt;
         &lt;param name="allowScriptAccess" value="sameDomain" /&gt;
         &lt;param name="flashvars" value='&lt;%#DataBinder.Eval(Container.DataItem, "rank_order")%&gt;' /&gt;  
         &lt;embed src="result_survey.swf?rankOrder='&lt;%#DataBinder.Eval(Container.DataItem, "rank_order")%&gt;' quality="high" bgcolor="#ffffff" width="100%" height="100%"
           name="result_survey" align="middle" play="true" loop="false"  allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"&gt;
          &lt;/embed&gt;
       &lt;/object&gt;
  
  
  &lt;/td&gt;&lt;/tr&gt;
  &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt; 
  </code></pre>
  
  <h2>c#</h2>
  
  <pre><code>protected void print2(object sender, EventArgs e)
  {
      HttpContext.Current.Response.Clear();
      HttpContext.Current.Response.Charset = "";
      HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7;
      HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
      HttpContext.Current.Response.ContentType = "application/msword";
      HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + "Report.doc");
      EnableViewState = false;
      System.IO.StringWriter sw = new System.IO.StringWriter();
      HtmlTextWriter htw = new HtmlTextWriter(sw);
      // Here I render the Repeater
      foreach (RepeaterItem row in rptrQuestions.Items)
      {
          row.RenderControl(htw);
      }
      StringBuilder sb1 = new StringBuilder();
      sb1 = sb1.Append("&lt;table&gt;" + sw.ToString() + "&lt;/table&gt;");
      HttpContext.Current.Response.Write(sb1.ToString());
      HttpContext.Current.Response.Flush();
      HttpContext.Current.Response.End();
  }
  </code></pre>
  
  <h2>.mxml</h2>
  
  <pre><code>//##################################################
  // grabScreen  (return image representation of the SWF movie (snapshot)
  //######################################################
  public function grabScreen() : ByteArray
  {
  return ImageSnapshot.captureImage( boxMain, 0, new   PNGEncoder()  ).data();
  }
  </code></pre>