How to create thumbnails of PDF files using node.js and gm

I use meteor (which is built on node) and CollectionCFS (which allows me to use gm [GraphicsMagick] for finger-nails).

I am doing the following to automatically create a thumbnail of uploaded images:

new FS.Store.FileSystem("thumbs", { transformWrite: function(fileObj, readStream, writeStream) { gm(readStream, fileObj.name()).resize('100', '100').stream().pipe(writeStream); }, path: "/Volumes/Public/Thumbs", }) 

The transformWrite function receives a readStream (source image), modifies it, and passes the results to writeStream. How can I create thumbnails of PDF files?

+5
source share
1 answer

If you just want the first pdf page to be a thumbnail. follow these steps:

 new FS.Store.FileSystem("thumbs", { transformWrite: function(fileObj, readStream, writeStream) { gm(readStream, fileObj.name() + '[0]').resize('100', '100').stream('png').pipe(writeStream); }, beforeWrite: function (fileObj) { return { extension: 'png', type: 'image/png' }; }, path: "/Volumes/Public/Thumbs", }) 
+1
source

Source: https://habr.com/ru/post/1203220/


All Articles