c#: exporting swf object as image to Word

Posted by Lynn on Stack Overflow See other posts from Stack Overflow or by Lynn
Published on 2010-03-28T09:44:03Z Indexed on 2010/03/28 9:53 UTC
Read the original article Hit count: 426

Filed under:
|
|
|
|

Hello

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.

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.

The code is shown below, and your help is appreciated :)

.aspx

<asp:Button ID="Button1" runat="server" text="export to Word" onclick="print2"/>

<asp:Repeater ID="rptrQuestions" runat="server"   OnItemDataBound="rptrQuestions_ItemDataBound" >
...
<ItemTemplate>
<tr>  
<td>  
<div align="center">
  <asp:Label class="text" Text='<%#DataBinder.Eval(Container.DataItem, "Question_title")%>' runat="server" ID="lbl_title" NAME="lbl_title"/>
<br>
</div>
</td>
</tr>
<tr><td>


  <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">
       <param name="movie" value="result_survey.swf" />
       <param name="quality" value="high" />
       <param name="bgcolor" value="#ffffff" />
       <param name="allowScriptAccess" value="sameDomain" />
       <param name="flashvars" value='<%#DataBinder.Eval(Container.DataItem, "rank_order")%>' />  
       <embed src="result_survey.swf?rankOrder='<%#DataBinder.Eval(Container.DataItem, "rank_order")%>' 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">
        </embed>
     </object>


</td></tr>
</ItemTemplate>
</asp:Repeater> 

c#

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("<table>" + sw.ToString() + "</table>");
    HttpContext.Current.Response.Write(sb1.ToString());
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
}

.mxml

//##################################################
// grabScreen  (return image representation of the SWF movie (snapshot)
//######################################################
public function grabScreen() : ByteArray
{
return ImageSnapshot.captureImage( boxMain, 0, new   PNGEncoder()  ).data();
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET