corymickelson / NoPoDoFo

node pdf native bindings
GNU Affero General Public License v3.0
26 stars 6 forks source link

Scaling an image has no effect #87

Closed lobabob closed 5 years ago

lobabob commented 5 years ago

The following executes fine and does add the image to the pdf in the right location. However, the scaling portion of painter.drawImage() seems to have no effect. As far as I can tell, I'm using it correctly according to the docs.

doc.load('test.pdf', e => {
  const painter = new npdf.Painter(doc)
  const img = new npdf.Image(doc, path.join(__dirname, './sig.png'))

  const page = doc.getPage(0)
  painter.setPage(page)
  painter.drawImage(img, 0, page.height - img.height, { width: 20, height: 10 })
  painter.finishPage()

  doc.write(path.join(__dirname, './test-img.pdf'), err => {
    console.error(err)
  })
})
corymickelson commented 5 years ago

Thank you for submitting an issue. I will look into this as soon as i can.

corymickelson commented 5 years ago

Thank you again for submitting this. This issue has been resolved on master, https://github.com/corymickelson/NoPoDoFo/commit/ca413390ac7bd89f7bf3652d993b40450b5b416e If you are using one of the downloaded binaries (win64 or aws linux) it is going to take me a little longer to get an updated archive ready.

corymickelson commented 5 years ago

@lobabob Just a heads up, the scaling values will follow: {width: 1.0, height: 1.0} will have no effect on scaling {width: 0.5, height: 0.5}will scale the image down by half {width: 0.25, height: 0.25} will scale the image down to a quarter of the original size etc...

lobabob commented 5 years ago

Ahh, I see. Didn't realize it was scaling, thought it was in points (oversight on my part). As for your thoughts on where I'm installing from, I was installing via npm install nopodofo.

Have you had any thoughts about specifying image dimensions instead of just scaling them? E.g. width: 100, height: 20 } where they are in point units instead of a scale factor. I feel like that would be a more common use for this, but that might just be me.

corymickelson commented 5 years ago

@lobabob The api follow's as closely as possible the api to PoDoFo. I agree with you though that this is a bit misleading. I will take another look and see if I can make this more intuitive, and at the very least update the docs to help explain the args for this particular api. As to the installation method, the download archives I created for people that had difficulties building PoDoFo with the required dependencies. If building PoDoFo is not an issue for you, I recommend you build your own binaries.

corymickelson commented 5 years ago

@lobabob I've created a new issue for the Image api. I am going to close this one now unless you have anything else you would like to add to it.

lobabob commented 5 years ago

Closing this is fine, I think you've addressed everything here.