node-poppler: The 'undefined' option for pdfToCairo's second parameter does not produce valid output for tiff files.
Prerequisites
-
I have written a descriptive issue title
-
I have searched existing issues to ensure it has not already been reported
-
I agree to follow the Code of Conduct that this project adheres to
API/app/plugin version
5.1.6
Node.js version
v16.13.2
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
12.4
Description
I am trying to fetch a single page from a pdf without writing it down in a separate image file. This works beautifully for jpg’s and png’s as documented in https://github.com/Fdawgs/node-poppler/blob/master/README.md#popplerpdftocairo.
For tiff files it’s a different story though: It works only if I give an output file as a second parameter in the pdfToCairo function, but not when I use ‘undefined’. The result ist way to small - like it is only the header of the tiff file or something.
I checked wether my poppler version (22.05.0) is working correctly on the comand line. It does. pdftocairo -tiff -f 1 -l 1 -singlefile example.pdf - > example.tiff works perfectly on the shell.
As far as I can see - node-poppler does send the correct params to the spawned child process. But the result is a very short string - sth like this:

From debugging index.js in node-poppler I can see that
is only called once for the whole childprocess. This could be the problem.
Steps to Reproduce
This code should be enough to see that foo.tif is not a valid tiff file. You can use any or the provided pdf file: example.pdf
import { Poppler } from 'node-poppler';
import fs from 'fs';
import path from 'path';
const file = fs.readFileSync(path.join(__dirname, 'example.pdf'));
(async () => {
const poppler = new Poppler('/usr/bin');
const res: string | Error = await poppler.pdfToCairo(file, undefined, {
firstPageToConvert:1,
lastPageToConvert: 1,
singleFile:true,
tiffCompression: 'jpeg',
tiffFile: true
//pngFile: true
});
if (res instanceof Error) {
console.log('Error: ' + JSON.stringify(res));
return;
}
fs.writeFileSync('foo.tif', res, { encoding: 'binary' })
})();
Additional information: Though I wrote this code on OSX I also tried it on a docker container with alpine linux expecting the behaviour to be an OSX glitch. But I could also reproduce the problem on linux successfully.
Expected Behaviour
The expected behaviour should be equal for all possible output formats - meaning when using an ‘undefined’ outputfile and the -singleFile Option the resulting string should contain valid image data.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (4 by maintainers)
That sounds like the explanation! Thank you for sharing!
@wunderkind2k1 Did you find a solution to this?
I have just added streaming support to poppler.pdfToCairo in a fork. I tried rendering to TIFF and got the same problem. Just wanted to chime in and inform that this does not seem to be a buffer problem, since my stream version behaves the same.
The file size of my TIFF files are 8 bytes. Rendering to JPG files is no problem with file sizes about 3-9 MB
I can confirm that the exact same pdftocario call works fine manually. The resulting TIFF file is 58 MB in my case. I.e. the last argument to my manually called pdftocairo is “-”, which will direct the output to stdout. Piping this into a file works great.
The only difference between my manual call and poppler.pdfToCairo is the spawn command.
stream.endis called from somewhere.This post might relate to this: https://github.com/nodejs/node/issues/12921 But I didn’t find anything useful.
My fork: https://github.com/msageryd/node-poppler
Hi @wunderkind2k1 sorry for using this issue for non-relevant question.
anyway, Thanks for your helps.
Hi Mustafa,
would you please be so kind open and open an other issue for such a question the next time? It does not belong to this issue.
Nevertheless:
“how can I add the path of poppler-utils to Poppler object when the application is running in server ?” -> you put it in the constructor of the Poppler ‘object’. like so:
const poppler = new Poppler(<INSERT YOUR PATH TO POPPLER_UTILS>);“and also can you please provide me the commands of installing poppler data and utils in Alpine os ?” -> this should do the trick:
apk add poppler-utilsHope this helps.
Thanks for reporting this @wunderkind2k1, I’ll take a look!