生成 Word 文档的缩略图
我有一个网站,用户可以在其中上传 Word 文档,我想显示这些 Word 文档的缩略图。 如果有人知道如何使用 C# 将 Word 文件的第一页显示为图像,请告诉我。
另外,如果您知道一个值得信赖的 .NET 库可以将 Word 文件转换为图像且无需 Office 互操作,那就太好了。
I have a website where users upload Word documents and I want to display thumbnails of these word documents. If anyone of you knows how to display the first page of a Word file as an image using C# please tell me.
Also if you know a trusted .NET library to convert word files to images that requires no office interop that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http ://blogs.msdn.com/windowssdk/archive/2009/06/12/windows-api-code-pack-for-microsoft-net-framework.aspx
这是微软的API代码包
http://blogs.msdn.com/windowssdk/archive/2009/06/12/windows-api-code-pack-for-microsoft-net-framework.aspx
It's Microsoft's API Code Pack
我在寻找类似的解决方案时发现了这个问题(7年后)。 我正在评估 2JPEG,它似乎支持 275 种格式,包括 Word、Excel、Publisher 和 幻灯片文件。 fCoder 建议将 2JPEG 作为计划后台任务运行。 命令行语法非常全面。
以下是生成特定文件缩略图的示例片段:
I found this question (7 yrs later) while searching for a similar solution. I'm evaluating 2JPEG and it appears to support 275 formats including Word, Excel, Publisher & Powerpoint files. fCoder recommends running 2JPEG as a scheduled background task. The command line syntax is pretty comprehensive.
Here's a sample snippet to generate a thumbnail for a specific file:
.doc 或 .docx 文档第一页的预览图像可以使用名为 Free Spire.Doc for .NET 的工具(用于商业和个人用途的完全免费的 Word API)轻松创建。 我发现它既快速又准确。
开发者页面的注释:
“转换功能允许将 Word 文档(Word 97-2003、Word 2007、Word 2010、Word 2013、Word 2016 和 Word 2019)转换为常用的文件格式,例如 XML、 RTF、TXT、PDF、XPS、EPUB、HTML 和图像等
温馨的提示:
免费版本仅限于 500 个段落和 25 个表格..."
此 C# 代码创建 .docx 文件第一页的 System.Drawing.Image 对象:
创建缩略图图片,以下 C# 示例包含第二个 using 块来执行此操作,然后转换为 Base64 字符串:
此外,该库还可以以其他方式进行转换,例如此函数返回 .SVG 文件每页:
A preview image of the 1st page of a .doc or .docx document can easily be created with a tool called Free Spire.Doc for .NET (a totally free word API for commercial and personal use). I found it to be fast and accurate.
Note from the developer's page:
"The featured function, conversion allows converting Word documents (Word 97-2003, Word 2007, Word 2010, Word 2013, Word 2016 and Word 2019) to commonly used file format, such as XML, RTF, TXT, PDF, XPS, EPUB, HTML and Image etc.
Friendly Reminder:
Free version is limited to 500 paragraphs and 25 tables... "
This C# code creates a System.Drawing.Image object of the 1st page of a .docx file:
To create the thumbnail image, the following C# example includes a second using block to do it, and then converts to a base64 string:
In addition, the library can also convert in other ways, for instance this function returns .SVG files with each page: