Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this code drawing on a canvas is saves as a xml/XAML file.
i need to export the canvas as PDF and JPG. I can't get them convered as the xaml is serialized.


private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
       {
           IEnumerable<DesignerItem> designerItems = this.Children.OfType<DesignerItem>();
           IEnumerable<Connection> connections = this.Children.OfType<Connection>();


           XElement designerItemsXML = SerializeDesignerItems(designerItems);
           XElement connectionsXML = SerializeConnections(connections);

           XElement root = new XElement("Root");
           root.Add(designerItemsXML);
           root.Add(connectionsXML);

           SaveFile(root);

       }
Posted

1 solution

You can open your canvas data in anoter windows as printed format . where you can save it as pdf through ctrl+p

C#
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
yourCanvasId.RenderControl(hw);
string canvasHTML = sw.ToString().Replace("\"", "'")
    .Replace(System.Environment.NewLine, "");


StringBuilder sb = new StringBuilder();

sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = new function(){");
sb.Append("var printWin = window.open('', '', 'left=0");
sb.Append(",top=0,width=1200,height=600,status=0');");
sb.Append("printWin.document.write(\"");

sb.Append(canvasHTML);
sb.Append("\");");
sb.Append("printWin.document.close();");
sb.Append("printWin.focus();");
sb.Append("printWin.print();");
sb.Append("printWin.close();};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "CanvasPrint", sb.ToString());


Thanks
AARIF SHAIKH
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900