M
M
maxism2014-08-15 08:43:02
ImageMagick
maxism, 2014-08-15 08:43:02

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();

It didn't work :( The result is a pdf file containing only the first of the original images.
I also tried this:
var imagesArray = [/*Массив Buffer с бинарными данными*/];

var oneBigBuffer = Buffer.concat(imagesArray);

var convert = cp.spawn('gm', ['convert', 'jpg:-', 'test.pdf']);

convert.stdin.end(oneBigBuffer);

The result is the same.
I would be very grateful for tips in the direction of digging places

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question