yakovmeister / pdf2image

A utility for converting pdf to image and base64 format.
MIT License
434 stars 141 forks source link

Get image the same dimension as pdf #188

Closed pkboom closed 1 year ago

pkboom commented 1 year ago

Been searching the doc but couldn't find any solution for this. Is there any way to get an image the same size as a pdf file? I want to get an image that has the same width and height as those of a pdf file.

Thanks.

mskec commented 1 year ago

Hi @pkboom

The library doesn't have this feature, but it sounds like something that can be useful. Do you want to try and submit a PR with this?

You can get each page size like this:

import gm from "gm";

gm('./test/data/pdf1.pdf')
  .identify((error, data) => {
    console.log(data.Geometry) // ['842x595', '1684x595', '1684x595', '1684x595', '1684x595', '1684x595', '1684x595', '1684x595', '842x595']
  })
pkboom commented 1 year ago

Thanks for the tip. Looked at the code for hours. It's a bit complicated to simply write code for this. Sorry for not being helpful this time.