从FlowDocument的创建XPS文档并将其安装在飞行 [英] creating an XPS Document from a FlowDocument and attach it on the fly
本文介绍了从FlowDocument的创建XPS文档并将其安装在飞行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我想转换为XPS文档并将其连接到一个电子邮件,这一切一起发送一个的FlowDocument。我使用这个code
I have a FlowDocument that I want to convert to an XPS Document and attach it to an e-mail and send it all together. I'm using this code
public static MemoryStream FlowDocumentToXPS(FlowDocument flowDocument, int width, int height)
{
MemoryStream stream = new MemoryStream();
using (Package package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
{
using (XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Maximum))
{
XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false);
DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
paginator.PageSize = new System.Windows.Size(width, height);
rsm.SaveAsXaml(paginator);
rsm.Commit();
}
}
stream.Position = 0;
Console.WriteLine(stream.Length);
Console.WriteLine(stream.Position);
return stream;
}
然后,我附上使用这个code的:
Then I attach it using this code:
Attachment xps = new Attachment(FlowDocumentToXPS(FD, 768, 676), "FileName.xps", "application/vnd.ms-xpsdocument");
,其中FD是的FlowDocument我想转换,我收到0.0KB大小XPS文件连接,它不能与XPS查看器打开时,我在这里缺少什么?
where FD is the FlowDocument I want to convert , I'm receiving 0.0KB size XPS file attached and it can't be open with the XPS Viewer , what I'm missing here ?
编辑:这工作的最后code,见注释
The final code that worked , see the comments
在此先感谢
推荐答案
解决了,看到在问题文章的评论和对职位本身已经做了修改
Solved , see the comments under the question post and the edit already done on the post itself
这篇关于从FlowDocument的创建XPS文档并将其安装在飞行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文