Skip to content

The 'undefined' option for pdfToCairo's second parameter does not produce valid output for tiff files. #430

@wunderkind2k1

Description

@wunderkind2k1

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:
image

From debugging index.js in node-poppler I can see that

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions