xpsdocument java,从FlowDocument的创建XPS文档并将其安装在飞行

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;

}

Then I attach it using this code:

Attachment xps = new Attachment(FlowDocumentToXPS(FD, 768, 676), "FileName.xps", "application/vnd.ms-xpsdocument");

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 ?

EDIT: The final code that worked , see the comments

Thanks in advance

解决方案

Solved , see the comments under the question post and the edit already done on the post itself

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值