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),很高兴为您提供查询和咨询。