Aspose Words 把内容读到stream中时容易出现的问题,以及memorystream to string
来源:互联网 发布:淘宝店铺层级在哪里看 编辑:程序博客网 时间:2024/05/01 09:51
Aspose Words 转换doc为其他格式时,如果你想直接将转换出的内容保存到数据库中,或者其他方式进行传输,而不需要保存到文件时,通常使用流的方式,如果下面这样:
Aspose.Words.Document doc = new Aspose.Words.Document(new MemoryStream(aDocument));
doc.PageColor = Color.White; // doc files are saved with red background on the server, changing to white anyway MemoryStream firstStream = new MemoryStream(); doc.Save(firstStream, saveFormat); return firstStream.GetBuffer();
这时,会发生一个异常:
Image file cannot be written to disk. When saving the document to a stream either ImagesFolder should be specified or custom streams should be provided via ImageSavingCallback. Please see documentation for details.
解决这个异常的代码是这样的:
也可参考这个页面:
http://www.aspose.com/community/forums/thread/405071/exception-when-converting-doc-to-html-when-saving-the-document-to-a-stream-either-imagesfolder-sho.aspx
internal byte[] ConvertRightNowAspose(byte[] aDocument, SaveFormat saveFormat){ Aspose.Words.Document doc = new Aspose.Words.Document(new MemoryStream(aDocument)); doc.PageColor = Color.White; // doc files are saved with red background on the server, changing to white anyway using (MemoryStream firstStream = new MemoryStream()) { if (saveFormat == SaveFormat.Html) { HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html); options.ImageSavingCallback = new HandleImageSaving(); doc.Save(firstStream, options); } else { doc.Save(firstStream, saveFormat); } return firstStream.GetBuffer(); }} public class HandleImageSaving : IImageSavingCallback{ void IImageSavingCallback.ImageSaving(ImageSavingArgs e) { e.ImageStream = new MemoryStream(); e.KeepImageStreamOpen = false; }}
如果你要获取文本:
MemoryStream streamContent = new MemoryStream(); docContent.Save(streamContent, saveOption); string a = System.Text.Encoding.UTF8.GetString(streamContent.ToArray()); streamContent.Close();
0 0
- Aspose Words 把内容读到stream中时容易出现的问题,以及memorystream to string
- C++中cin内容读到string变量要输入两次回车的问题
- 把整个文本文件内容读到一个string里
- fstream一次把整个文本文件内容读到 string 里
- fstream一次把整个文本文件内容读到 string 里
- Aspose.Words把DataTable 中的数据导出到word中
- Aspose.Words使用模板导出数据库中图片内容
- c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换
- java,String.replaceAll中在替换路径(含有/或者/)容易出现的问题
- c++中new容易出现的问题
- 开发中容易出现的问题
- .net Stream MemoryStream 的使用注意事项 及 把流输出到客户端.
- 利用Aspose.Words 把word 生成图片
- 正文内容 Aspose.Words进行Word替换
- MySQL主从同步配置容易出现的问题以及解决方法
- Java中容易出现乱码的地方以及解决方法
- Java中容易出现乱码的地方以及解决方法
- Java中容易出现乱码的地方以及解决方法
- Android中文联系人排序及检索补丁的原理(090819更新)
- 【SQL之查询】MySQL查询今天、昨天、上周、近30天、去年等的数据的方法
- 怎么在vmware上安装虚拟机?
- 正则表达式-Regular Expression
- web前端页面性能优化小结
- Aspose Words 把内容读到stream中时容易出现的问题,以及memorystream to string
- OC基础使用(二)
- 进化大神宝典1.0
- 双向循环链表的创建,增删查改
- Android:HttpWatch+jsoup抓包
- c#代码统计程序
- 关于plsql可以登录,sqlplus不能登录解决办法
- CVSVM 还没看太懂
- 学习实战完全笔记--JavaSE----流与文件(Streams and Files)