如何将Canvas保存为PDF和jpg [英] How to save Canvas as PDF and jpg
本文介绍了如何将Canvas保存为PDF和jpg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此代码中,画布上的图形将另存为xml / XAML文件。
我需要将画布导出为PDF和JPG。因为xaml被序列化,我无法让它们受到限制。
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);
}
推荐答案
您可以在打印窗口中以打印格式打开画布数据。你可以把它保存为pdf通过ctrl + p
You can open your canvas data in anoter windows as printed format . where you can save it as pdf through ctrl+p
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());
谢谢
AARIF SHAIKH
Thanks
AARIF SHAIKH
这篇关于如何将Canvas保存为PDF和jpg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文