NodeJS creating an image preview of a docx file

Viewed 2352

I want to generate an image preview of a word docx file similar to Google Drive (see image). Essentially, the client uploads a docx that is sent to the backend. The backend takes a snapshot of the first page of the file and sends that image back to the client.

Google Drive File Preview

Is there a way to take a snapshot of a word file in the backend--or even in the client-side? Any tools to do this?

2 Answers

There does seem to be a library for you to start with: 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.

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. (note that for more common media types like pictures/videos, there may be better preview generators available).

Related