你知道将DOC格式序列化为字节数组最简单方法吗?来看看Aspose.Words API如何处理

情到浓时终转凉″ 提交于 2019-12-11 11:40:41

Aspose.Words for .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。

Aspose.Words API提供了将Microsoft Word文档从DOC或DOCX格式序列化为字节数组的最简单方法。将文档存储到数据库中和/或从数据库中检索时,将Word文档转换为字节数组很有帮助。

另外!.NET版Aspose Words转换升级,支持将PDF转换为PDF 1.7标准!近日,Aspose Words For .NET更新到了v19.12版,在Windows10上使用SystemFontSource时,支持用户安装的字体,OLE对象数据公开给公共API等等9大新功能。(下载地址可在评论区查看)

.NET的Aspose.Words可用于转换Document对象,以获取表示任何.NET应用程序中Document的字节数组。以下代码段演示了DOC文件到字节数组的转换。

// Load the document from disk.Document doc = new Document("Sample.doc");// Create a new memory stream.MemoryStream outStream = new MemoryStream();// Save the document to stream.doc.Save(outStream, SaveFormat.Docx);// Convert the document to byte form.byte[] docBytes = outStream.ToArray();// The bytes are now ready to be stored/transmitted.// Now reverse the steps to load the bytes back into a document object.MemoryStream inStream = new MemoryStream(docBytes);// Load the stream into a new document object.Document loadDoc = new Document(inStream);// Save the document.loadDoc.Save("loadDoc.docx",SaveFormat.Docx);

以下代码段演示了如何使用Aspose.Words for Java API 将DOC文件转换为字节数组。

// Load the document.Document doc = new Document("Sample.doc");// Create a new memory stream.ByteArrayOutputStream outStream = new ByteArrayOutputStream();// Save the document to stream.doc.save(outStream, SaveFormat.DOCX);// Convert the document to byte form.byte[] docBytes = outStream.toByteArray();// The bytes are now ready to be stored/transmitted.// Now reverse the steps to load the bytes back into a document object.ByteArrayInputStream inStream = new ByteArrayInputStream(docBytes);// Load the stream into a new document object.Document loadDoc = new Document(inStream);// Save the document.loadDoc.Save("loadDoc.docx",SaveFormat.Docx);

如果您有任何疑问或需求,请随时加入Aspose技术交流群(642018183),很高兴为您提供查询和咨询。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!