Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Failed to convert page to image #55

Open
VassilisPallas opened this issue Jan 9, 2020 · 6 comments
Open

Failed to convert page to image #55

VassilisPallas opened this issue Jan 9, 2020 · 6 comments

Comments

@VassilisPallas
Copy link

VassilisPallas commented Jan 9, 2020

Environment:
Node: 10
Os: ubuntu:18.04 (docker)

const path = './tmp';

const saveTempFile = (file, buffer) => { ... }

const readTempFile = file => { ... }

const deleteTempFile = file => { ... }

module.exports = async ({ originalname, buffer }) => {
  try {
    const extension = getExtension(originalname);
    const file = `${path}/${randonString()}${extension}`;
    await saveTempFile(file, buffer);

    const pdfImage = new PDFImage(file);
    const image = await pdfImage.convertPage(0);

    await deleteTempFile(file);
    return readTempFile(image);
  } catch (e) {
    throw e;
  }
};
{ message: 'Failed to convert page to image',
  error:
   { Error: Command failed: convert "./tmp/o22s9w2cqmjhlf0jawr1iq.pdf[0]" "tmp/o22s9w2cqmjhlf0jawr1iq-0.png"
   convert-im6.q16: not authorized `./tmp/o22s9w2cqmjhlf0jawr1iq.pdf' @ error/constitute.c/ReadImage/412.
   convert-im6.q16: no images defined `tmp/o22s9w2cqmjhlf0jawr1iq-0.png' @ error/convert.c/ConvertImageCommand/3258.
   
       at ChildProcess.exithandler (child_process.js:294:12)
       at ChildProcess.emit (events.js:198:13)
       at maybeClose (internal/child_process.js:982:16)
       at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
     killed: false,
     code: 1,
     signal: null,
     cmd:
      'convert "./tmp/o22s9w2cqmjhlf0jawr1iq.pdf[0]" "tmp/o22s9w2cqmjhlf0jawr1iq-0.png"' },
  stdout: '',
  stderr:
   'convert-im6.q16: not authorized `./tmp/o22s9w2cqmjhlf0jawr1iq.pdf\' @ error/constitute.c/ReadImage/412.\nconvert-im6.q16: no images defined `tmp/o22s9w2cqmjhlf0jawr1iq-0.png\' @ error/convert.c/ConvertImageCommand/3258.\n' }
@VassilisPallas
Copy link
Author

VassilisPallas commented Jan 9, 2020

I removed the restriction with the command

sudo sed -i 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/g' /etc/ImageMagick-6/policy.xml

but know the image is blank [43]. Also the convert doesn't work if the density is not given.

    const pdfImage = new PDFImage(file, {
      combinedImage: true,
      convertOptions: {
        '-resize': '200x200',
        '-quality': '75',
        '-density': '800',
      },
    });

@jamiegalbreath
Copy link

I am also having this issue. Any luck?

@toddself
Copy link
Collaborator

toddself commented Apr 3, 2020

This isn't an issue with this tool, rather an issue with the environment where it's being run.

As far as the image being blank, i would need a replicable test case to investigate.

@VassilisPallas
Copy link
Author

VassilisPallas commented Apr 4, 2020

It runs inside a docker image which is using ubuntu as base image. The pdf file is just a file inside /tmp. I have already provided to you the code I'm using. In saveTemp you can use fs to store the file.

@toddself
Copy link
Collaborator

toddself commented Apr 6, 2020

Sorry, the code above does not run, nor is there a Dockerfile to build it. If you'd like help with this, I'd be happy to help, but I need a fully replicable test case first.

@VolckaertAchiel
Copy link

sudo sed -i 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/g' /etc/ImageMagick-6/policy.xml

This fixed my problem, thanks alot

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants