简体   繁体   English

NodeJS 创建 docx 文件的图像预览

[英]NodeJS creating an image preview of a docx file

I want to generate an image preview of a word docx file similar to Google Drive (see image).我想生成类似于 Google Drive 的 word docx 文件的图像预览(见图)。 Essentially, the client uploads a docx that is sent to the backend.本质上,客户端上传一个发送到后端的 docx。 The backend takes a snapshot of the first page of the file and sends that image back to the client.后端拍摄文件第一页的快照并将该图像发送回客户端。

谷歌云端硬盘文件预览

Is there a way to take a snapshot of a word file in the backend--or even in the client-side?有没有办法在后端或什至在客户端拍摄 word 文件的快照? Any tools to do this?有什么工具可以做到这一点?

you can use node canvas https://www.npmjs.com/package/canvas or you can use IMG4Me - Text to Image Service API to generate an image from text https://rapidapi.com/seikan/api/img4me-text-to-image-service you can use node canvas https://www.npmjs.com/package/canvas or you can use IMG4Me - Text to Image Service API to generate an image from text https://rapidapi.com/seikan/api/img4me-text -to-image-service

There does seem to be a library for you to start with: https://www.npmjs.com/package/docx-preview似乎确实有一个库可供您开始使用: https://www.npmjs.com/package/docx-preview

The preview works for simple documents.预览适用于简单文档。 For server-side usage, one would still need to render the canvas output to a picture and send that to the requesting client.对于服务器端使用,仍然需要将 canvas output 渲染为图片并将其发送给请求的客户端。

EDIT: For server-side usage only, it seems versatile solutions are already;编辑:仅用于服务器端,似乎已经有了通用的解决方案; see https://www.npmjs.com/package/filepreview-es6 or https://www.npmjs.com/package/filepreview respectively.分别参见https://www.npmjs.com/package/filepreview-es6https://www.npmjs.com/package/filepreview (note that for more common media types like pictures/videos, there may be better preview generators available). (请注意,对于更常见的媒体类型,如图片/视频,可能有更好的预览生成器可用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM