1、XPS转字节流
方法一:
byte[] xpsBytes = File.ReadAllBytes(@"E:\\代码测试区\\WPF XPS\\XPSSave练习\\WpfApplication1\\WpfApplication1\\content\\3.xps");
方法二:
string url=@"E:\\代码测试区\\WPF XPS\\XPSSave练习\\WpfApplication1\\WpfApplication1\\content\\3.xps"; var webClient = new System.Net.WebClient(); byte[] data = webClient.DownloadData(url);
2、字节流转XPSDocument
public static XpsDocument OpenXpsDocument(string url) { var webClient = new WebClient(); var data = webClient.DownloadData(url); var package = System.IO.Packaging.Package.Open(new MemoryStream(data)); var xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, url); return xpsDocument; }
3、字节流生成XPS文件
public static void OpenXpsDocument(string url) { var webClient = new System.Net.WebClient(); byte[] data = webClient.DownloadData(url); string fileName = Guid.NewGuid().ToString(); string xpsTempFilePath = string.Format("{0}\\" + fileName + ".xps", Environment.CurrentDirectory); using (BinaryWriter writer = new System.IO.BinaryWriter(File.OpenWrite(xpsTempFilePath))) { writer.Write(data); writer.Flush(); } //XpsDocument xpsDocument = new System.Windows.Xps.Packaging.XpsDocument(xpsTempFilePath, FileAccess.Read); //return xpsDocument; }
浙公网安备 33010602011771号