Answer the question
In order to leave comments, you need to log in
How to create multipage file from nodejs using graphicsmagick?
The task is to implement the creation of a multi-page pdf or tif file from existing images using graphicsmagick or imagemagick. The easiest way to implement this is to use the gm convert 1.jpg 2.jpg ... result.pdf
But what if at the time of creating the resulting multipage image there are no source graphic files, but there are Buffer objects in nodejs filled with binary data of the source images?
Based on my own assumptions about how to implement this, I tried the following code:
var cp = require('child_process');
var fs = require('fs');
var imagesArray = [/*Массив Buffer с бинарными данными*/];
var convert = cp.spawn('gm', ['convert', 'jpg:-', 'test.pdf']);
res.forEach(function (imgBuffer) {
convert.stdin.write(imgBuffer);
});
convert.stdin.end();
var imagesArray = [/*Массив Buffer с бинарными данными*/];
var oneBigBuffer = Buffer.concat(imagesArray);
var convert = cp.spawn('gm', ['convert', 'jpg:-', 'test.pdf']);
convert.stdin.end(oneBigBuffer);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question