node-pdf-image icon indicating copy to clipboard operation
node-pdf-image copied to clipboard

default image background color

Open kopipejst opened this issue 10 years ago • 4 comments

it would be great it we could set default background color through options

kopipejst avatar Jul 17 '15 23:07 kopipejst

Since this module uses ImageMagick for pdf to image conversion, you can check ImageMagick's available options for such custom behavior http://www.imagemagick.org/script/command-line-options.php

You can set ImageMagick's options as follows:

var pdfImage = new PDFImage("/tmp/slide.pdf");
pdfImage.setConvertOptions({
  "-density": 300,
  "-trim": null
});

P.S.

I tried some options to set background color, but failed to get preferred result. Maybe, it's not effective to PDF's.

mooz avatar Jul 20 '15 02:07 mooz

It seems that pdfImage doesn't have setConvertOptions.

I found workaround for bg color:

gm(imagePath).resize(width).extent(width, height + 0.1).

kopipejst avatar Jul 21 '15 01:07 kopipejst

I'm also having difficulties with the setConvertOptions.

I tried adding an options array to the constructor:

    var image = new PDFImage(path, options);

and adding some options using the setConvertOptions:

pdfImage.setConvertOptions({
    '-density': '300',
    '-depth': '8'
});

Both options don't work. Is it possible that you have to update the npm package?

gijbelst avatar Aug 15 '15 17:08 gijbelst

It works fine when I do:

var pdfImage = new PDFImage(path, {
    convertOptions: {
        '-density': '300',
        '-depth': '8',
        '-background': 'white',
        '-flatten': ''
    }
});

a-legrand avatar Dec 17 '15 14:12 a-legrand